git.utils
Handle miscellaneous logic and utilities.
Copyright (C) 2021 Gitcoin Core
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.
github_connect
github_connect(token=None)
Authenticate the GH wrapper with Github.
Args: token (str): The Github token to authenticate with. Defaults to: None.
build_auth_dict
build_auth_dict()
Collect authentication details.
Returns: dict: An authentication dictionary.
is_github_token_valid
is_github_token_valid(oauth_token=None, last_validated=None)
Check whether or not a Github OAuth token is valid.
Args: access_token (str): The Github OAuth token.
Returns: bool: Whether or not the provided OAuth token is valid.
revoke_token
revoke_token(oauth_token)
Revoke the specified token.
reset_token
reset_token(oauth_token)
Reset the provided token.
Args: oauth_token (str): The Github OAuth token.
Returns: str: The new Github OAuth token.
get_auth_url
get_auth_url(redirect_uri='/')
Build the Github authorization URL.
Args: redirect_uri (str): The redirect URI to be used during authentication.
Attributes: github_callback (str): The local path to the Github callback view. redirect_params (dict): The redirect paramaters to URL encode. params (dict): The URL parameters to encode. auth_url (str): The URL encoded Github authentication parameters.
Returns: str: The Github authentication URL.
get_github_primary_email
get_github_primary_email(oauth_token)
Get the primary email address associated with the github profile.
Args: oauth_token (str): The Github OAuth2 token to use for authentication.
Returns: str: The user's primary github email address.
get_github_event_emails
get_github_event_emails(oauth_token, username)
Get all email addresses associated with the github profile.
Args: oauth_token (str): The Github OAuth2 token to use for authentication.
Returns: list of str: All of the user's associated emails from github.
get_github_emails
get_github_emails(oauth_token)
Get all email addresses associated with the github profile.
Args: oauth_token (str): The Github OAuth2 token to use for authentication.
Returns: list of str: All of the user's associated email from git.
search_user
search_user(query, token=None)
Search for a user on github.
Args: query (str): The query text to match. token (str): The user's Github token to be used to perform the search.
Returns: dict: The first matching github user dictionary.
search_users
search_users(query, token=None)
Search for users on github.
Args: query (str): The query text to match. token (str): The user's Github token to be used to perform the search.
Returns: github.PaginatedList: The pygithub paginator object of all results if many True.
get_issue_comments
get_issue_comments(owner, repo, issue=None, comment_id=None, page=1)
Get the comments from issues on a respository.
Args: owner (str): Owner of the repo repo (str): Name of the repo issue (int): Issue number (optional) comment_id (int): Comment ID (optional) page (int): Page number (optional)
Returns: github.PaginatedList.PaginatedList / github.IssueComment.IssueComment: The GitHub comments response.
get_issues
get_issues(owner, repo, page=1, state='open')
Get the issues on a respository.
get_issue_timeline_events
get_issue_timeline_events(owner, repo, issue, page=1)
Get the timeline events for a given issue.
PLEASE NOTE CURRENT LIMITATION OF 100 EVENTS. Args: owner (str): Owner of the repo repo (str): Name of the repo issue (int): Issue number
Returns: github.PaginatedList of githubTimelineEvent: The GitHub timeline response list.
get_user
get_user(user=None, token=None)
Get the github user details.
get_notifications
get_notifications()
Get the Github notifications for Gitcoin Bot.
post_issue_comment
post_issue_comment(owner, repo, issue_num, comment)
Post a comment on an issue.
Args: owner (str): Owner of the repo repo (str): Name of the repo issue_num (int): Issue number comment (int): Comment Body
Returns: github.IssueComment.IssueComment: The GitHub created comment.
patch_issue_comment
patch_issue_comment(issue_id, comment_id, owner, repo, comment)
Update a comment on an issue via patch.
delete_issue_comment
delete_issue_comment(issue_id, comment_id, owner, repo)
Remove a comment on an issue via delete.
post_issue_comment_reaction
post_issue_comment_reaction(owner, repo, issue_id, comment_id, content)
React to an issue comment.
get_url_dict
get_url_dict(issue_url)
Get the URL dictionary with specific data we care about.
Args: issue_url (str): The Github issue URL.
Raises: IndexError: The exception is raised if accessing a necessary index fails.
Returns: dict: A mapping of details for the specified issue URL.
repo_url
repo_url(issue_url)
Build the repository URL.
Args: issue_url (str): The Github issue URL.
Returns: str: The repository URL.
org_name
org_name(issue_url)
Get the organization name from an issue URL.
Args: issue_url (str): The Github issue URL.
Returns: str: The Github organization name.
repo_name
repo_name(issue_url)
Get the repo name from an issue URL.
Args: issue_url (str): The Github issue URL.
Returns: str: The Github repo name.
issue_number
issue_number(issue_url)
Get the issue_number from an issue URL.
Args: issue_url (str): The Github issue URL.
Returns: str: The Github issue_number
get_current_ratelimit
get_current_ratelimit(token=None)
Get the current Github API ratelimit for the provided token.