Git

This part of the documentation covers the module associated with the Git Data section of the GitHub API.

Git Objects

class github3.git.Blob(json, session)

This object provides an interface to the API representation of a blob.

See also: http://developer.github.com/v3/git/blobs/

This object has the following atributes

content

The raw content of the blob. This may be base64 encoded text. Use decode_content() to receive the non-encoded text.

encoding

The encoding that GitHub reports for this blob’s content.

size

The size of this blob’s content in bytes.

sha

The SHA1 of this blob’s content.

as_dict()

Return the attributes for this object as a dictionary.

This is equivalent to calling:

json.loads(obj.as_json())
Returns:this object’s attributes serialized to a dictionary
Return type:dict
as_json()

Return the json data for this object.

This is equivalent to calling:

json.dumps(obj.as_dict())
Returns:this object’s attributes as a JSON string
Return type:str
decode_content()

Return the unencoded content of this blob.

If the content is base64 encoded, this will properly decode it. Otherwise, it will return the content as returned by the API.

Returns:Decoded content as text
Return type:unicode
decoded

Compatibility shim for the deprecated attribute.

from_dict(json_dict, session)

Return an instance of this class formed from json_dict.

from_json(json, session)

Return an instance of this class formed from json.

new_session()

Generate a new session.

Returns:A brand new session
Return type:GitHubSession
ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
refresh(conditional=False)

Re-retrieve the information for this object.

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.repositories_by('kennethreitz')]

Without the return value, that would be an array of None’s and you would otherwise have to do:

repos = [r for i in g.repositories_by('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

Parameters:conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs
Returns:self

class github3.git.ShortCommit(json, session)

This represents a commit as returned by the git API.

This is distinct from RepoCommit. Primarily this object represents the commit data stored by git. This shorter representation of a Commit is most often found on a RepoCommit to represent the git data associated with it.

See also: http://developer.github.com/v3/git/commits/

This object has the following attributes:

author

This is a dictionary with at least the name and email of the author of this commit as well as the date it was authored.

committer

This is a dictionary with at least the name and email of the committer of this commit as well as the date it was committed.

message

The commit message that describes the changes as written by the author and committer.

tree

The git tree object this commit points to.

as_dict()

Return the attributes for this object as a dictionary.

This is equivalent to calling:

json.loads(obj.as_json())
Returns:this object’s attributes serialized to a dictionary
Return type:dict
as_json()

Return the json data for this object.

This is equivalent to calling:

json.dumps(obj.as_dict())
Returns:this object’s attributes as a JSON string
Return type:str
from_dict(json_dict, session)

Return an instance of this class formed from json_dict.

from_json(json, session)

Return an instance of this class formed from json.

new_session()

Generate a new session.

Returns:A brand new session
Return type:GitHubSession
ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
refresh(conditional=False)

Re-retrieve the information for this object.

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.repositories_by('kennethreitz')]

Without the return value, that would be an array of None’s and you would otherwise have to do:

repos = [r for i in g.repositories_by('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

Parameters:conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs
Returns:self

class github3.git.Commit(json, session)

This represents a commit as returned by the git API.

This is distinct from RepoCommit. Primarily this object represents the commit data stored by git and it has no relationship to the repository on GitHub.

See also: http://developer.github.com/v3/git/commits/

This object has all of the attributes of a ShortCommit as well as the following attributes:

parents

The list of commits that are the parents of this commit. This may be empty if this is the initial commit, or it may have several if it is the result of an octopus merge. Each parent is represented as a dictionary with the API URL and SHA1.

sha

The unique SHA1 which identifies this commit.

verification

The GPG verification data about this commit. See https://developer.github.com/v3/git/commits/#commit-signature-verification for more information.

as_dict()

Return the attributes for this object as a dictionary.

This is equivalent to calling:

json.loads(obj.as_json())
Returns:this object’s attributes serialized to a dictionary
Return type:dict
as_json()

Return the json data for this object.

This is equivalent to calling:

json.dumps(obj.as_dict())
Returns:this object’s attributes as a JSON string
Return type:str
from_dict(json_dict, session)

Return an instance of this class formed from json_dict.

from_json(json, session)

Return an instance of this class formed from json.

new_session()

Generate a new session.

Returns:A brand new session
Return type:GitHubSession
ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
refresh(conditional=False)

Re-retrieve the information for this object.

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.repositories_by('kennethreitz')]

Without the return value, that would be an array of None’s and you would otherwise have to do:

repos = [r for i in g.repositories_by('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

Parameters:conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs
Returns:self

class github3.git.GitObject(json, session)

This object represents an arbitrary ‘object’ in git.

This object is intended to be versatile and is usually found on one of the following:

This object has the following attributes:

sha

The SHA1 of the object this is representing.

type

The name of the type of object this is representing.

as_dict()

Return the attributes for this object as a dictionary.

This is equivalent to calling:

json.loads(obj.as_json())
Returns:this object’s attributes serialized to a dictionary
Return type:dict
as_json()

Return the json data for this object.

This is equivalent to calling:

json.dumps(obj.as_dict())
Returns:this object’s attributes as a JSON string
Return type:str
from_dict(json_dict, session)

Return an instance of this class formed from json_dict.

from_json(json, session)

Return an instance of this class formed from json.

new_session()

Generate a new session.

Returns:A brand new session
Return type:GitHubSession
ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
refresh(conditional=False)

Re-retrieve the information for this object.

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.repositories_by('kennethreitz')]

Without the return value, that would be an array of None’s and you would otherwise have to do:

repos = [r for i in g.repositories_by('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

Parameters:conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs
Returns:self

class github3.git.Hash(json, session)

This is used to represent the elements of a tree.

This provides the path to the object and the type of object it is. For a brief explanation of what these types are and represent, this StackOverflow question answers some of that: https://stackoverflow.com/a/18605496/1953283

See also: http://developer.github.com/v3/git/trees/#create-a-tree

This object has the following attributes:

mode

The mode of the file, directory, or link.

path

The path to the file, directory, or link.

sha

The SHA1 for this hash.

size

This attribute is only not None if the type is not a tree.

type

The type of git object this is representing, e.g., tree, blob, etc.

as_dict()

Return the attributes for this object as a dictionary.

This is equivalent to calling:

json.loads(obj.as_json())
Returns:this object’s attributes serialized to a dictionary
Return type:dict
as_json()

Return the json data for this object.

This is equivalent to calling:

json.dumps(obj.as_dict())
Returns:this object’s attributes as a JSON string
Return type:str
from_dict(json_dict, session)

Return an instance of this class formed from json_dict.

from_json(json, session)

Return an instance of this class formed from json.

new_session()

Generate a new session.

Returns:A brand new session
Return type:GitHubSession
ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
refresh(conditional=False)

Re-retrieve the information for this object.

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.repositories_by('kennethreitz')]

Without the return value, that would be an array of None’s and you would otherwise have to do:

repos = [r for i in g.repositories_by('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

Parameters:conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs
Returns:self

class github3.git.Reference(json, session)

Object representing a git reference associated with a repository.

This represents a reference (or ref) created on a repository via git.

See also: http://developer.github.com/v3/git/refs/

This object has the following attributes:

object

A GitObject that this reference points to.

ref

The string path to the reference, e.g., 'refs/heads/sc/feature-a'.

as_dict()

Return the attributes for this object as a dictionary.

This is equivalent to calling:

json.loads(obj.as_json())
Returns:this object’s attributes serialized to a dictionary
Return type:dict
as_json()

Return the json data for this object.

This is equivalent to calling:

json.dumps(obj.as_dict())
Returns:this object’s attributes as a JSON string
Return type:str
delete()

Delete this reference.

Returns:True if successful, False otherwise
Return type:bool
from_dict(json_dict, session)

Return an instance of this class formed from json_dict.

from_json(json, session)

Return an instance of this class formed from json.

new_session()

Generate a new session.

Returns:A brand new session
Return type:GitHubSession
ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
refresh(conditional=False)

Re-retrieve the information for this object.

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.repositories_by('kennethreitz')]

Without the return value, that would be an array of None’s and you would otherwise have to do:

repos = [r for i in g.repositories_by('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

Parameters:conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs
Returns:self
update(sha, force=False)

Update this reference.

Parameters:
  • sha (str) – (required), sha of the reference
  • force (bool) – (optional), force the update or not
Returns:

True if successful, False otherwise

Return type:

bool


class github3.git.Tag(json, session)

This represents an annotated tag.

Tags are a special kind of git reference and annotated tags have more information than lightweight tags.

See also: http://developer.github.com/v3/git/tags/

This object has the following attributes:

message

This is the message that was written to accompany the creation of the annotated tag.

object

A GitObject that represents the underlying git object.

sha

The SHA1 of this tag in the git repository.

tag

The “lightweight” tag (or reference) that backs this annotated tag.

tagger

The person who created this tag.

as_dict()

Return the attributes for this object as a dictionary.

This is equivalent to calling:

json.loads(obj.as_json())
Returns:this object’s attributes serialized to a dictionary
Return type:dict
as_json()

Return the json data for this object.

This is equivalent to calling:

json.dumps(obj.as_dict())
Returns:this object’s attributes as a JSON string
Return type:str
from_dict(json_dict, session)

Return an instance of this class formed from json_dict.

from_json(json, session)

Return an instance of this class formed from json.

new_session()

Generate a new session.

Returns:A brand new session
Return type:GitHubSession
ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
refresh(conditional=False)

Re-retrieve the information for this object.

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.repositories_by('kennethreitz')]

Without the return value, that would be an array of None’s and you would otherwise have to do:

repos = [r for i in g.repositories_by('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

Parameters:conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs
Returns:self

class github3.git.Tree(json, session)

This represents a tree object from a git repository.

Trees tend to represent directories and subdirectories.

See also: http://developer.github.com/v3/git/trees/

This object has the following attributes:

sha

The SHA1 of this tree in the git repository.

tree

A list that represents the nodes in the tree. If this list has members it will have instances of Hash.

as_dict()

Return the attributes for this object as a dictionary.

This is equivalent to calling:

json.loads(obj.as_json())
Returns:this object’s attributes serialized to a dictionary
Return type:dict
as_json()

Return the json data for this object.

This is equivalent to calling:

json.dumps(obj.as_dict())
Returns:this object’s attributes as a JSON string
Return type:str
from_dict(json_dict, session)

Return an instance of this class formed from json_dict.

from_json(json, session)

Return an instance of this class formed from json.

new_session()

Generate a new session.

Returns:A brand new session
Return type:GitHubSession
ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
recurse()

Recurse into this tree.

Returns:A new tree
Return type:Tree
refresh(conditional=False)

Re-retrieve the information for this object.

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.repositories_by('kennethreitz')]

Without the return value, that would be an array of None’s and you would otherwise have to do:

repos = [r for i in g.repositories_by('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

Parameters:conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs
Returns:self

class github3.git.CommitTree(json, session)

This object represents the abbreviated tree data in a commit.

The API returns different representations of different objects. When representing a ShortCommit or Commit, the API returns an abbreviated representation of a git tree.

This object has the following attributes:

sha

The SHA1 of this tree in the git repository.

as_dict()

Return the attributes for this object as a dictionary.

This is equivalent to calling:

json.loads(obj.as_json())
Returns:this object’s attributes serialized to a dictionary
Return type:dict
as_json()

Return the json data for this object.

This is equivalent to calling:

json.dumps(obj.as_dict())
Returns:this object’s attributes as a JSON string
Return type:str
from_dict(json_dict, session)

Return an instance of this class formed from json_dict.

from_json(json, session)

Return an instance of this class formed from json.

new_session()

Generate a new session.

Returns:A brand new session
Return type:GitHubSession
ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
refresh()

Retrieve a full Tree object for this CommitTree.

Returns:The full git data about this tree
Return type:Tree
to_tree()

Retrieve a full Tree object for this CommitTree.

Returns:The full git data about this tree
Return type:Tree