in src/dispatch/plugins/dispatch_github/plugin.py [0:0]
def get_match_status(self, weblink: str, last_modified: datetime = None, **kwargs) -> dict:
"""Fetches the match and attempts to determine current status."""
# determine what kind of link we have
base_url = "https://api.github.com/repos"
# NOTE I'm not sure about this logic
match_data = None
for matcher in self.get_matchers():
for match in matcher.finditer(f"<{weblink}>"):
match_data = match.groupdict()
if match_data:
break
if match_data["type"] == "pull":
# for some reason the api and the front end differ for PRs
match_data["type"] = match_data["type"].replace("pull", "pulls")
request_url = f"{base_url}/{match_data['organization']}/{match_data['repo']}/{match_data['type']}/{match_data['id']}"
# use conditional requests to avoid rate limits
# https://docs.github.com/en/rest/overview/resources-in-the-rest-api#conditional-requests
headers = {"User-Agent": create_ua_string()}
if last_modified:
headers.update({"If-Modified-Since": str(last_modified)})
resp = requests.get(request_url, headers=headers)
if resp.status_code == 304:
# no updates
return
if resp.status_code == 403:
raise TryAgain
if resp.status_code == 200:
data = resp.json()
monitor_data = {
"title": data["title"],
"state": data["state"],
}
return monitor_data