git.utils

Handle miscellaneous logic and utilities.

Copyright (C) 2018 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(oauth_token)

Collect authentication details.

Args: oauth_token (str): The Github OAuth token.

Returns: dict: An authentication dictionary.

check_github

check_github(profile)

Check whether or not the provided username is present in the payload as active user.

Args: profile (str): The profile username to be validated.

Returns: dict: A dictionary containing status and user data.

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: access_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_user_token

get_github_user_token(code, **kwargs)

Get the Github authorization token.

get_github_user_data

get_github_user_data(oauth_token)

Get the user's github profile information.

Args: oauth_token (str): The Github OAuth2 token to use for authentication.

Returns: requests.Response: The Github user response.

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 email 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

search(query)

Search for a user on github.

Args: query (str): The query text to match.

Returns: request.Response: The github search response.

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 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: 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)

Get the comments from issues on a respository. PLEASE NOTE CURRENT LIMITATION OF 100 COMMENTS.

Args: owner (str): Owner of the repo repo (str): Name of the repo issue (int): Issue number (optional)

Returns: requests.Response: The GitHub comments response.

get_issues

get_issues(owner, repo, page=1, state='open')

Get the open 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. PLEASE NOTE GITHUB API FOR THIS IS SUBJECT TO CHANGE. (See https://developer.github.com/changes/2016-05-23-timeline-preview-api/ for more info.)

Args: owner (str): Owner of the repo repo (str): Name of the repo issue (int): Issue number

Returns: requests.Response: The GitHub timeline response.

get_user

get_user(user, sub_path='')

Get the github user details.

get_notifications

get_notifications()

Get the github notifications.

get_gh_notifications

get_gh_notifications(login=None)

Get the Github notifications for Gitcoin Bot.

post_issue_comment

post_issue_comment(owner, repo, issue_num, comment)

Post a comment on an issue.

patch_issue_comment

patch_issue_comment(comment_id, owner, repo, comment)

Update a comment on an issue via patch.

delete_issue_comment

delete_issue_comment(comment_id, owner, repo)

Remove a comment on an issue via delete.

post_issue_comment_reaction

post_issue_comment_reaction(owner, repo, 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.