Github REST

skare3_tools.github.github.init(user=None, password=None, token=None, force=True)[source]

Initialize the API.

Parameters:
  • token – str a Github auth token

  • force – bool override a previously initialized API

Returns:

class skare3_tools.github.github.GithubAPI(user=None, password=None, token=None)[source]

Main class that encapsulates Github’s REST API.

get(path, params=None, **kwargs)[source]

Perform http request using GET method.

init(user=None, password=None, token=None, force=True)[source]

Initialize the Github API.

If not token is provided, it tries the following: - look for GITHUB_API_TOKEN environmental variable - look for GITHUB_TOKEN environmental variable

If that fails, try with user/password (deprecated) If no user name is provided, it tries the following:

  • look for GITHUB_USER environmental variable

  • request in a command line prompt.

If no password is provided, it tries the following:

  • look for GITHUB_PASSWORD environmental variable

  • try getting it from the keyring (Keychain in Mac OS)

If user name or password can not be determined, an AuthException is raised.

Parameters:
  • user – str (deprecated)

  • password – str (deprecated)

  • token – str

  • force – bool

Returns:

GithubAPI

patch(path, params=None, **kwargs)[source]

Perform http request using PATCH method

post(path, params=None, **kwargs)[source]

Perform http request using POST method

put(path, params=None, **kwargs)[source]

Perform http request using PUT method

class skare3_tools.github.github.Repository(repo=None, owner=None, api=None)[source]

Switchboard for all repository-related endpoints.

Attributes:
  • releases

  • tags

  • commits

  • issues

  • branches

  • checks

Repository Endpoints

class skare3_tools.github.github.Releases(parent, **kwargs)[source]

Endpoints that have to do with repository releases.

(releases API docs)

__call__(latest=False, tag_name=None, release_id=None)[source]

Get release.

Parameters:
  • latest

  • tag_name

  • release_id

Returns:

create(**kwargs)[source]

Create a Release.

Parameters:
  • tag_name – str. Required. The name of the tag.

  • target_commitish – str. Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository’s default branch (usually master).

  • name – str. The name of the release.

  • body – str. Text describing the contents of the tag.

  • draft – boolean. True to create a draft (unpublished) release, false to create a published one. Default: false

  • prerelease – boolean. True to identify the release as a prerelease. false to identify the release as a full release. Default: false

edit(release_id, **kwargs)[source]

Edit a Release.

Parameters:
  • release_id – str

  • tag_name – str The name of the tag.

  • target_commitish – str Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository’s default branch (usually master).

  • name – str The name of the release.

  • body – str Text describing the contents of the tag.

  • draft – boolean true makes the release a draft, and false publishes the release.

  • prerelease – boolean true to identify the release as a prerelease, false to identify the release as a full release.

class skare3_tools.github.github.Tags(parent, **kwargs)[source]

Endpoints that have to do with repository tags.

(tags API docs)

__call__(tag_sha=None, name=None)[source]

Call self as a function.

create(**kwargs)[source]

Create tag.

Parameters:
  • tag – str. Required. The tag’s name. This is typically a version (e.g., “v0.0.1”).

  • message – str. Required. The tag message.

  • object – str. Required. The SHA of the git object this is tagging.

  • type – str. Required. The type of the object we’re tagging. Normally this is a commit but it can also be a tree or a blob.

  • tagger – object An object with information about the individual creating the tag.

The tagger object contains the following keys:

  • name: str. The name of the author of the tag

  • email: str. The email of the author of the tag

  • date: str. When this object was tagged. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.

class skare3_tools.github.github.Commits(parent, **kwargs)[source]

Endpoints that have to do with repository commits.

(commit API docs)

__call__(ref=None, **kwargs)[source]

Get commits.

Parameters:
  • ref – str

  • sha – str SHA or branch to start listing commits from. Default: the repository’s default branch (usually master).

  • path – str Only commits containing this file path will be returned.

  • author – str GitHub login or email address by which to filter by commit author.

  • since – str Only commits after this date will be returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.

  • until – str Only commits before this date will be returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.

  • kwargs

Returns:

class skare3_tools.github.github.Issues(parent, **kwargs)[source]

Endpoints that have to do with repository issues.

(issues API docs)

__call__(issue_number=None, **kwargs)[source]

List issues.

Parameters:
  • issue_number – int, Optional

  • filter

    str Indicates which sorts of issues to return. Default: assigned. Can be one of:

    • assigned: Issues assigned to you

    • created: Issues created by you

    • mentioned: Issues mentioning you

    • subscribed: Issues you’re subscribed to updates for

    • all: All issues the authenticated user can see

  • state – str Indicates the state of the issues to return. Can be either open, closed, or all. Default: open

  • labels – str A list of comma separated label names. Example: bug,ui,@high

  • sort – str What to sort results by. Can be either created, updated, comments. Default: created

  • direction – str The direction of the sort. Can be either asc or desc. Default: desc

  • since – str Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.

  • kwargs

Returns:

create(**kwargs)[source]

Create issue.

Parameters:
  • title – str Required. The title of the issue.

  • body – str The contents of the issue.

  • milestone – int The number of the milestone to associate this issue with. NOTE: Only users with push access can set the milestone for new issues. The milestone is silently dropped otherwise.

  • labels – list Labels to associate with this issue. NOTE: Only users with push access can set labels for new issues. Labels are silently dropped otherwise.

  • assignees – list Logins for Users to assign to this issue. NOTE: Only users with push access can set assignees for new issues. Assignees are silently dropped otherwise.

edit(issue_number, **kwargs)[source]

Edit issue.

Parameters:
  • issue_number

  • title – str The title of the issue.

  • body – str The contents of the issue.

  • assignee – str Login for the user that this issue should be assigned to. This field is deprecated.

  • state – str State of the issue. Either open or closed.

  • milestone – int The number of the milestone to associate this issue with or null to remove current. NOTE: Only users with push access can set the milestone for issues. The milestone is silently dropped otherwise.

  • labels – list of strings Labels to associate with this issue. Pass one or more Labels to replace the set of Labels on this Issue. Send an empty array ([]) to clear all Labels from the Issue. NOTE: Only users with push access can set labels for issues. Labels are silently dropped otherwise.

  • assignees – list of strings Logins for Users to assign to this issue. Pass one or more user logins to replace the set of assignees on this Issue. Send an empty array ([]) to clear all assignees from the Issue. NOTE: Only users with push access can set assignees for new issues. Assignees are silently dropped otherwise.

  • kwargs

Returns:

class skare3_tools.github.github.Branches(parent, **kwargs)[source]

Endpoints that have to do with repository branches.

(branches API docs)

__call__(branch=None, **kwargs)[source]

Get branches.

Parameters:
  • branch

  • protected – bool Setting to true returns only protected branches. When set to false, only unprotected branches are returned. Omitting this parameter returns all branches.

  • kwargs

Returns:

class skare3_tools.github.github.PullRequests(parent, **kwargs)[source]

Endpoints that have to do with pull requests.

(pull requests API docs)

__call__(pull_number=None, **kwargs)[source]

Get pull request.

Parameters:
  • pull_number – str (optional) Default: all pulls

  • state – str Either open, closed, or all to filter by state. Default: open

  • head – str Filter pulls by head user or head organization and branch name in the format of user:ref-name or organization:ref-name. For example: github:new-script-format or octocat:test-branch.

  • base – str Filter pulls by base branch name. Example: gh-pages.

  • sort – str What to sort results by. Can be either created, updated, popularity (comment count) or long-running (age, filtering by pulls updated in the last month). Default: created

  • direction – str The direction of the sort. Can be either asc or desc. Default: desc when sort is created or sort is not specified, otherwise asc.

commits(pull_number, **kwargs)[source]

Lists a maximum of 250 commits for a pull request.

Parameters:

pull_number – str

create(**kwargs)[source]

Create pull request.

Parameters:
  • title – str Required. The title of the new pull request.

  • head – str Required. The name of the branch where your changes are implemented. For cross-repository pull requests in the same network, namespace head with a user like this: username:branch.

  • base – str Required. The name of the branch you want the changes pulled into. This should be an existing branch on the current repository. You cannot submit a pull request to one repository that requests a merge to a base of another repository.

  • body – str The contents of the pull request.

  • maintainer_can_modify – bool Indicates whether maintainers can modify the pull request.

  • draft – bool Indicates whether the pull request is a draft. See “Draft Pull Requests” in the GitHub Help documentation to learn more.

  • kwargs

Returns:

edit(pull_number, **kwargs)[source]

Edit pull request.

Parameters:
  • pull_number

  • title – str The title of the pull request.

  • body – str The contents of the pull request.

  • state – str State of this Pull Request. Either open or closed.

  • base – str The name of the branch you want your changes pulled into. This should be an existing branch on the current repository. You cannot update the base branch on a pull request to point to another repository.

  • maintainer_can_modify – bool Indicates whether maintainers can modify the pull request.

files(pull_number, **kwargs)[source]

Lists a maximum of 250 commits for a pull request.

Parameters:

pull_number – str

merge(pull_number, **kwargs)[source]

Merge a pull request.

Parameters:
  • pull_number

  • commit_title – str Title for the automatic commit message.

  • commit_message – str Extra detail to append to automatic commit message.

  • sha – str SHA that pull request head must match to allow merge.

  • merge_method – str Merge method to use. Possible values are merge, squash or rebase. Default is merge.

status(pull_number, **kwargs)[source]

Get if a pull request has been merged.

Parameters:

pull_number – str

class skare3_tools.github.github.Checks(parent, **kwargs)[source]

Endpoints that have to do with repository checks.

(checks API docs)

__call__(ref)[source]

Call self as a function.

class skare3_tools.github.github.DispatchEvent(parent, **kwargs)[source]

Create a repository dispatch event.

__call__(event_type, client_payload=None)[source]

Create a repository dispatch event.

Parameters:
  • event_type – str A custom webhook event name.

  • client_payload – dict JSON payload with extra information about the webhook event.

class skare3_tools.github.github.Contents(parent, **kwargs)[source]

Create and edit repository content.

(contents API docs)

__call__(path='', decode=True, **kwargs)[source]

Gets the contents of a file or directory in a repository.

If path is omitted, it returns all the contents of the repository.

Parameters:
  • path – str

  • decode – bool if True, the contents are base64 decoded.

  • ref – str name of the commit/branch/tag (default: the repository’s default branch (usually master)

edit(path, encode=True, **kwargs)[source]

Create or update file contents.

Parameters:
  • message – str Required. The commit message.

  • content – str Required. The new file content.

  • sha – str if you are updating a file. The blob SHA of the file being replaced.

  • branch – str The branch name. Default: the repository’s default branch (usually master)

  • committer – dict The person that committed the file. Default: the authenticated user.

  • author – dict The author of the file. Default: The committer or the authenticated user. Both the author and committer parameters have the same keys: {‘name’: ‘’, ‘email’: ‘’}

  • encode – bool if True, the content argument is plain text, this function will encode it. default True

Returns:

Github GraphQL

skare3_tools.github.graphql.init(token=None, force=True)[source]

Initialize the API.

Parameters:
  • token – str a Github auth token

  • force – bool override a previously initialized API

Returns:

class skare3_tools.github.graphql.GithubAPI(token=None)[source]

Main class that encapsulates Github’s GraphQL API.

init(token=None, force=True)[source]

Initialize the Github API.

Parameters:
  • token – str

  • force – bool

Returns:

GithubAPI