aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kosayoda <[email protected]>2019-10-13 22:58:54 +0800
committerGravatar kosayoda <[email protected]>2019-10-13 22:58:54 +0800
commit29a0963ab0b56fe53d758d05b02d3b5d5d286578 (patch)
tree53f2779312bc4e435e4d6227ef41f29880be45c9
parentMerge pull request #296 from vivax3794/hacktober-issue-finder (diff)
Ignore Draft PRs in .hackstats
-rw-r--r--bot/seasons/halloween/hacktoberstats.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/bot/seasons/halloween/hacktoberstats.py b/bot/seasons/halloween/hacktoberstats.py
index 9ad44e3f..ef2c880c 100644
--- a/bot/seasons/halloween/hacktoberstats.py
+++ b/bot/seasons/halloween/hacktoberstats.py
@@ -236,11 +236,16 @@ class HacktoberStats(commands.Cog):
f"&per_page={per_page}"
)
- headers = {"user-agent": "Discord Python Hacktoberbot"}
+ # Use custom media type in Accept header to get `draft` field in API returns
+ # https://developer.github.com/changes/2019-02-14-draft-pull-requests/
+ headers = {
+ "user-agent": "Discord Python Hacktoberbot",
+ "Accept": "application/vnd.github.shadow-cat-preview+json"
+ }
+
async with aiohttp.ClientSession() as session:
async with session.get(query_url, headers=headers) as resp:
jsonresp = await resp.json()
-
if "message" in jsonresp.keys():
# One of the parameters is invalid, short circuit for now
api_message = jsonresp["errors"][0]["message"]
@@ -255,6 +260,8 @@ class HacktoberStats(commands.Cog):
logging.info(f"Found {len(jsonresp['items'])} Hacktoberfest PRs for GitHub user: '{github_username}'")
outlist = []
for item in jsonresp["items"]:
+ if item["draft"] is True: # Draft PRs don't count
+ continue
shortname = HacktoberStats._get_shortname(item["repository_url"])
itemdict = {
"repo_url": f"https://www.github.com/{shortname}",
@@ -264,6 +271,7 @@ class HacktoberStats(commands.Cog):
),
}
outlist.append(itemdict)
+ logging.info(f"Found {len(outlist)} valid Hacktoberfest PRs for GitHub user: '{github_username}'")
return outlist
@staticmethod