-
Notifications
You must be signed in to change notification settings - Fork 0
Switch manual GitHub API calls to PyGithub #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
5554c66
cbc57a7
8c80f42
3fcbb54
42effa2
46e1b7e
f181adf
4b2eee0
71ba7c7
448403e
7831332
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,16 @@ | |
|
|
||
|
|
||
| def fetch_api(path, params=None): | ||
| """ | ||
| Deprecated: use PyGithub's github instance instead. | ||
| """ | ||
| return fetch_api_full_url(f"https://api.github.com/{path}", params) | ||
|
|
||
|
|
||
| def fetch_api_full_url(url, params=None): | ||
| """ | ||
| Deprecated: use PyGithub's github instance instead. | ||
| """ | ||
| if GITHUB_TOKEN: | ||
| headers = {"Authorization": f"token {GITHUB_TOKEN}"} | ||
| else: | ||
|
|
@@ -23,34 +29,53 @@ def fetch_api_full_url(url, params=None): | |
|
|
||
|
|
||
| def get_releases(owner, repo, params=None): | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve this function to allow releases to be filtered based on their There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated |
||
| return fetch_api(f"repos/{owner}/{repo}/releases", params) | ||
| repository = pygithub_get_repo(owner, repo) | ||
| releases = repository.get_releases() | ||
| if params and "number" in params: | ||
| return [release.raw_data for release in releases[: params["number"]]] | ||
| return [release.raw_data for release in releases] | ||
|
|
||
|
|
||
| def get_repo(owner, repo, params=None): | ||
| return fetch_api(f"{owner}/{repo}", params) | ||
| """ | ||
| Deprecated: use pygithub_get_repo instead. | ||
| """ | ||
| return pygithub_get_repo(owner, repo).raw_data | ||
|
|
||
|
|
||
| def pygithub_get_repo(owner, repo): | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this function and use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed |
||
| return github.get_repo(f"{owner}/{repo}") | ||
|
|
||
|
|
||
| def compare_shas(owner, repo, base, head): | ||
| repo = pygithub_get_repo(owner, repo) | ||
| comparison = repo.compare(base, head) | ||
| repository = pygithub_get_repo(owner, repo) | ||
| comparison = repository.compare(base, head) | ||
| return [commit for commit in comparison.commits] | ||
|
|
||
|
|
||
| def get_all_commits(owner, repo, params=None): | ||
| return fetch_api(f"repos/{owner}/{repo}/commits", params) | ||
| repository = pygithub_get_repo(owner, repo) | ||
| gh_options = {} | ||
| if params: | ||
| if "since" in params: | ||
| gh_options["since"] = params["since"] | ||
| if "sha" in params: | ||
| gh_options["sha"] = params["sha"] | ||
|
|
||
| commits = repository.get_commits(**gh_options) | ||
| if params and "number" in params: | ||
| return [commit.raw_data for commit in commits[: params["number"]]] | ||
| return [commit.raw_data for commit in commits] | ||
|
|
||
|
|
||
| def get_commit(owner, repo, sha, params=None): | ||
| return fetch_api(f"repos/{owner}/{repo}/commits/{sha}", params) | ||
| repository = pygithub_get_repo(owner, repo) | ||
| return repository.get_commit(sha).raw_data | ||
|
|
||
|
|
||
| def get_pull_request(owner, repo, pr_id): | ||
| repo = pygithub_get_repo(owner, repo) | ||
| return repo.get_pull(pr_id) | ||
| repository = pygithub_get_repo(owner, repo) | ||
| return repository.get_pull(pr_id) | ||
|
|
||
|
|
||
| def get_pull_request_commits(owner, repo, pr_id): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jules Why do we still need to keep
fetch_apiandfetch_api_full_url? These should be removed andtreeherder/etl/management/commands/ingest.pyshould be updated to use to functions that make use of the utility written over the PyGithub library.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the deprecated
fetch_apiandfetch_api_full_urlfunctions fromtreeherder/utils/github.pyand updatedtreeherder/etl/management/commands/ingest.pyto use the PyGithub-based utilities.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jules Add type hints for all function parameters and return types as well as variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added type hints for all function parameters, return types, and variables in
treeherder/utils/github.py.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove usage of .raw_data and update the callers to use the actual objects returned instead of the Dict that was returned by raw_data. Also, update the tests to be inline with these changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed all usage of
.raw_dataintreeherder/utils/github.pyand updated all callers intreeherder/etl/management/commands/ingest.py,treeherder/changelog/collector.py, andtreeherder/etl/push_loader.pyto use the actual PyGithub objects. I have also refactored the tests intests/etl/test_ingest_command.pyandtests/changelog/test_collector.pyto align with these changes. This ensures a cleaner, object-oriented interface throughout the ingestion component.