-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8e3f2c
commit 77f100e
Showing
9 changed files
with
734 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import datetime | ||
import logging | ||
|
||
import httpx | ||
import tenacity | ||
from django.conf import settings | ||
from django.utils import timezone | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class GithubApiClient: | ||
def __init__(self): | ||
self.client = httpx.Client( | ||
base_url=f"{settings.API_GITHUB_BASE_URL}/repos/gip-inclusion/", | ||
# Authentication is not required as our repo is public. | ||
headers={ | ||
"Accept": "application/vnd.github+json", | ||
"Content-Type": "application/json", | ||
"X-GitHub-Api-Version": "2022-11-28", | ||
}, | ||
) | ||
|
||
@tenacity.retry(wait=tenacity.wait_fixed(2), stop=tenacity.stop_after_attempt(8)) | ||
def _request(self, endpoint, start): | ||
params = { | ||
"labels": ["bug"], | ||
"state": "closed", | ||
"pulls": True, | ||
"since": start.isoformat(), # The GH API does not allow an end date. | ||
} | ||
|
||
response = self.client.get(endpoint, params=params) | ||
response.raise_for_status() | ||
return response | ||
|
||
def get_metrics(self, date): | ||
response = self._request(endpoint="les-emplois/issues/", start=date) | ||
data_received = response.json() | ||
|
||
today_data = [] | ||
for data in data_received: | ||
data_date = datetime.datetime.fromisoformat(data["updated_at"]) | ||
# TODO; make sure we pass the correct timezone in call. | ||
# https://docs.github.com/en/rest/using-the-rest-api/timezones-and-the-rest-api?apiVersion=2022-11-28#explicitly-providing-an-iso-8601-timestamp-with-timezone-information | ||
if timezone.localdate(data_date) == date.date(): | ||
today_data.append(data) | ||
|
||
return {"total_pr_bugs": len(today_data)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.