From 29a0963ab0b56fe53d758d05b02d3b5d5d286578 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Sun, 13 Oct 2019 22:58:54 +0800 Subject: Ignore Draft PRs in .hackstats --- bot/seasons/halloween/hacktoberstats.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'bot') 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 -- cgit v1.2.3 From bba22f492f94702857526a068900612d85167928 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Wed, 23 Oct 2019 20:46:51 +0800 Subject: Filter draft PRs in query url instead --- bot/seasons/halloween/hacktoberstats.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktoberstats.py b/bot/seasons/halloween/hacktoberstats.py index ef2c880c..40c680db 100644 --- a/bot/seasons/halloween/hacktoberstats.py +++ b/bot/seasons/halloween/hacktoberstats.py @@ -225,6 +225,7 @@ class HacktoberStats(commands.Cog): not_label = "invalid" action_type = "pr" is_query = f"public+author:{github_username}" + not_query = "draft" date_range = f"{CURRENT_YEAR}-10-01T00:00:00%2B14:00..{CURRENT_YEAR}-10-31T23:59:59-11:00" per_page = "300" query_url = ( @@ -232,20 +233,15 @@ class HacktoberStats(commands.Cog): f"-label:{not_label}" f"+type:{action_type}" f"+is:{is_query}" + f"+-is:{not_query}" f"+created:{date_range}" f"&per_page={per_page}" ) - # 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: + async with session.get(query_url) 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"] @@ -260,8 +256,6 @@ 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}", @@ -271,7 +265,6 @@ class HacktoberStats(commands.Cog): ), } outlist.append(itemdict) - logging.info(f"Found {len(outlist)} valid Hacktoberfest PRs for GitHub user: '{github_username}'") return outlist @staticmethod -- cgit v1.2.3 From 11726da2903ae95929d3d8b453a37dc9a0411d9b Mon Sep 17 00:00:00 2001 From: kosayoda Date: Wed, 23 Oct 2019 20:49:13 +0800 Subject: Readd user agent to request header --- bot/seasons/halloween/hacktoberstats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktoberstats.py b/bot/seasons/halloween/hacktoberstats.py index 40c680db..ffcb6eaf 100644 --- a/bot/seasons/halloween/hacktoberstats.py +++ b/bot/seasons/halloween/hacktoberstats.py @@ -238,8 +238,9 @@ class HacktoberStats(commands.Cog): f"&per_page={per_page}" ) + headers = {"user-agent": "Discord Python Hacktoberbot"} async with aiohttp.ClientSession() as session: - async with session.get(query_url) as resp: + async with session.get(query_url, headers=headers) as resp: jsonresp = await resp.json() if "message" in jsonresp.keys(): -- cgit v1.2.3