Пример #1
0
    def __init__(self, commit, session=None):
        super(RepoCommit, self).__init__(commit, session)
        #: :class:`User <github3.users.User>` who authored the commit.
        self.author = commit.get('author')
        if self.author:
            self.author = User(self.author, self._session)
        #: :class:`User <github3.users.User>` who committed the commit.
        self.committer = commit.get('committer')
        if self.committer:
            self.committer = User(self.committer, self._session)
        #: :class:`Commit <github3.git.Commit>`.
        self.commit = commit.get('commit')
        if self.commit:
            self.commit = Commit(self.commit, self._session)

        self.sha = commit.get('sha')
        #: The number of additions made in the commit.
        self.additions = 0
        #: The number of deletions made in the commit.
        self.deletions = 0
        #: Total number of changes in the files.
        self.total = 0
        if commit.get('stats'):
            self.additions = commit['stats'].get('additions')
            self.deletions = commit['stats'].get('deletions')
            self.total = commit['stats'].get('total')

        #: The files that were modified by this commit.
        self.files = commit.get('files', [])

        self._uniq = self.sha
Пример #2
0
    def __init__(self, issue, session=None):
        super(Issue, self).__init__(issue, session)
        self._api = issue.get('url', '')
        #: :class:`User <github3.users.User>` representing the user the issue
        #  was assigned to.
        self.assignee = issue.get('assignee')
        if self.assignee:
            self.assignee = User(issue.get('assignee'), self._session)
        #: Body (description) of the issue.
        self.body = issue.get('body', '')
        #: HTML formatted body of the issue.
        self.body_html = issue.get('body_html', '')
        #: Plain text formatted body of the issue.
        self.body_text = issue.get('body_text', '')

        # If an issue is still open, this field will be None
        #: datetime object representing when the issue was closed.
        self.closed_at = None
        if issue.get('closed_at'):
            self.closed_at = self._strptime(issue.get('closed_at'))

        #: Number of comments on this issue.
        self.comments = issue.get('comments')
        #: datetime object representing when the issue was created.
        self.created_at = self._strptime(issue.get('created_at'))
        #: URL to view the issue at GitHub.
        self.html_url = issue.get('html_url')
        #: Unique ID for the issue.
        self.id = issue.get('id')
        #: Returns the list of :class:`Label <Label>`\ s on this issue.
        self.labels = [Label(l, self._session) for l in issue.get('labels')]

        #: :class:`Milestone <Milestone>` this issue was assigned to.
        self.milestone = None
        if issue.get('milestone'):
            self.milestone = Milestone(issue.get('milestone'), self._session)
        #: Issue number (e.g. #15)
        self.number = issue.get('number')
        #: Dictionary URLs for the pull request (if they exist)
        self.pull_request = issue.get('pull_request')
        m = match('https://github\.com/(\S+)/(\S+)/issues/\d+', self.html_url)
        #: Returns ('owner', 'repository') this issue was filed on.
        self.repository = m.groups()
        #: State of the issue, e.g., open, closed
        self.state = issue.get('state')
        #: Title of the issue.
        self.title = issue.get('title')
        #: datetime object representing the last time the issue was updated.
        self.updated_at = self._strptime(issue.get('updated_at'))
        #: :class:`User <github3.users.User>` who opened the issue.
        self.user = User(issue.get('user'), self._session)
Пример #3
0
    def committer_as_User(self):
        """Attempt to return the committer attribute as a
        :class:`User <github3.users.User>` object. No guarantees are made
        about the validity of this object.

        """
        return User(self.committer, self._session)
Пример #4
0
    def __init__(self, deployment, session=None):
        super(Deployment, self).__init__(deployment, session)
        self._api = deployment.get('url')

        #: GitHub's id of this deployment
        self.id = deployment.get('id')

        #: SHA of the branch on GitHub
        self.sha = deployment.get('sha')

        #: User object representing the creator of the deployment
        self.creator = deployment.get('creator')
        if self.creator:
            self.creator = User(self.creator, self)

        #: JSON string payload of the Deployment
        self.payload = deployment.get('payload')

        #: Date the Deployment was created
        self.created_at = self._strptime(deployment.get('created_at'))

        #: Date the Deployment was updated
        self.updated_at = self._strptime(deployment.get('updated_at'))

        #: Description of the deployment
        self.description = deployment.get('description')

        #: URL to get the statuses of this deployment
        self.statuses_url = deployment.get('statuses_url')
Пример #5
0
    def __init__(self, status, session=None):
        super(DeploymentStatus, self).__init__(status, session)
        self._api = status.get('url')

        #: GitHub's id for this deployment status
        self.id = status.get('id')

        #: State of the deployment status
        self.state = status.get('state')

        #: Creater of the deployment status
        self.creator = status.get('creator')
        if self.creator:
            self.creator = User(self.creator, self)

        #: JSON payload as a string
        self.payload = status.get('payload', {})

        #: Target URL of the deployment
        self.target_url = status.get('target_url')

        #: Date the deployment status was created
        self.created_at = self._strptime(status.get('created_at'))

        #: Date the deployment status was updated
        self.updated_at = self._strptime(status.get('updated_at'))

        #: Description of the deployment
        self.description = status.get('description')
Пример #6
0
    def __init__(self, history, session=None):
        super(GistHistory, self).__init__(history, session)
        self._api = history.get('url', '')

        #: SHA of the commit associated with this version
        self.version = history.get('version', '')

        #: user who made these changes
        self.user = User(history.get('user') or {}, session)

        #: dict containing the change status; see also: deletions, additions,
        #: total
        self.change_status = history.get('change_status', {})

        #: number of additions made
        self.additions = self.change_status.get('additions', 0)

        #: number of deletions made
        self.deletions = self.change_status.get('deletions', 0)

        #: total number of changes made
        self.total = self.change_status.get('total', 0)

        #: datetime representation of when the commit was made
        self.committed_at = self._strptime(history.get('committed_at'))
Пример #7
0
 def __init__(self, mile, session=None):
     super(Milestone, self).__init__(mile, session)
     self._api = mile.get('url', '')
     #: Identifying number associated with milestone.
     self.number = mile.get('number')
     #: State of the milestone, e.g., open or closed.
     self.state = mile.get('state')
     #: Title of the milestone, e.g., 0.2.
     self.title = mile.get('title')
     #: Description of this milestone.
     self.description = mile.get('description')
     #: :class:`User <github3.users.User>` object representing the creator
     #  of the milestone.
     self.creator = User(mile.get('creator'), self._session)
     #: Number of issues associated with this milestone which are still
     #  open.
     self.open_issues = mile.get('open_issues')
     #: The number of closed issues associated with this milestone.
     self.closed_issues = mile.get('closed_issues')
     #: datetime object representing when the milestone was created.
     self.created_at = self._strptime(mile.get('created_at'))
     #: datetime representing when this milestone is due.
     self.due_on = None
     if mile.get('due_on'):
         self.due_on = self._strptime(mile.get('due_on'))
Пример #8
0
 def __init__(self, event):
     super(Event, self).__init__(event)
     from github3.users import User
     from github3.orgs import Organization
     #: :class:`User <github3.users.User>` object representing the actor.
     self.actor = User(event.get('actor')) if event.get('actor') else None
     #: datetime object representing when the event was created.
     self.created_at = self._strptime(event.get('created_at'))
     #: Unique id of the event
     self.id = event.get('id')
     #: List all possible types of Events
     self.org = None
     if event.get('org'):
         self.org = Organization(event.get('org'))
     #: Event type http://developer.github.com/v3/activity/events/types/
     self.type = event.get('type')
     handler = _payload_handlers[self.type]
     #: Dictionary with the payload. Payload structure is defined by type_.
     #  _type: http://developer.github.com/v3/events/types
     self.payload = handler(event.get('payload'))
     #: Return ``tuple(owner, repository_name)``
     self.repo = event.get('repo')
     if self.repo is not None:
         self.repo = tuple(self.repo['name'].split('/'))
     #: Indicates whether the Event is public or not.
     self.public = event.get('public')
Пример #9
0
    def __init__(self, comment, session=None):
        super(IssueComment, self).__init__(comment, session)

        #: :class:`User <github3.users.User>` who made the comment
        self.user = None
        if comment.get('user'):
            self.user = User(comment.get('user'), self)
Пример #10
0
    def author_as_User(self):
        """Attempt to return the author attribute as a
        :class:`User <github3.users.User>`. No guarantees are made about the
        validity of this object, i.e., having a login or created_at object.

        """
        return User(self.author, self._session)
Пример #11
0
    def __init__(self, build):
        super(PagesBuild, self).__init__(build)
        self._api = build.get('url')

        #: Status of the pages build, e.g., building
        self.status = build.get('status')

        #: Error dictionary containing the error message
        self.error = build.get('error')

        from github3.users import User
        #: :class:`User <github3.users.User>` representing who pushed the
        #: commit
        self.pusher = User(build.get('pusher'))

        #: SHA of the commit that triggered the build
        self.commit = build.get('commit')

        #: Time the build took to finish
        self.duration = build.get('duration')

        #: Datetime the build was created
        self.created_at = self._strptime(build.get('created_at'))

        #: Datetime the build was updated
        self.updated_at = self._strptime(build.get('updated_at'))
Пример #12
0
    def __init__(self, comment, session=None):
        super(ReviewComment, self).__init__(comment, session)

        #: :class:`User <github3.users.User>` who made the comment
        self.user = None
        if comment.get('user'):
            self.user = User(comment.get('user'), self)

        #: Original position inside the file
        self.original_position = comment.get('original_position')

        #: Path to the file
        self.path = comment.get('path')

        #: Position within the commit
        self.position = comment.get('position') or 0

        #: SHA of the commit the comment is on
        self.commit_id = comment.get('commit_id')

        #: The diff hunk
        self.diff_hunk = comment.get('diff_hunk')

        #: Original commit SHA
        self.original_commit_id = comment.get('original_commit_id')
Пример #13
0
    def __init__(self, comment, session=None):
        super(GistComment, self).__init__(comment, session)

        #: :class:`User <github3.users.User>` who made the comment
        #: Unless it is not associated with an account
        self.user = None
        if comment.get('user'):
            self.user = User(comment.get('user'), self)  # (No coverage)
Пример #14
0
    def __init__(self, data, session=None):
        super(Gist, self).__init__(data, session)
        #: Number of comments on this gist
        self.comments = data.get('comments', 0)

        #: Unique id for this gist.
        self.id = '{0}'.format(data.get('id', ''))

        #: Description of the gist
        self.description = data.get('description', '')

        # e.g. https://api.github.com/gists/1
        self._api = data.get('url', '')

        #: URL of this gist at Github, e.g., https://gist.github.com/1
        self.html_url = data.get('html_url')
        #: Boolean describing if the gist is public or private
        self.public = data.get('public')

        self._forks = data.get('forks', [])
        #: The number of forks of this gist.
        self.forks = len(self._forks)

        #: Git URL to pull this gist, e.g., git://gist.github.com/1.git
        self.git_pull_url = data.get('git_pull_url', '')

        #: Git URL to push to gist, e.g., [email protected]/1.git
        self.git_push_url = data.get('git_push_url', '')

        #: datetime object representing when the gist was created.
        self.created_at = self._strptime(data.get('created_at'))

        #: datetime object representing the last time this gist was updated.
        self.updated_at = self._strptime(data.get('updated_at'))

        owner = data.get('owner')
        #: :class:`User <github3.users.User>` object representing the owner of
        #: the gist.
        self.owner = User(owner, self) if owner else None

        self._files = [GistFile(data['files'][f]) for f in data['files']]
        #: Number of files in this gist.
        self.files = len(self._files)

        #: History of this gist, list of
        #: :class:`GistHistory <github3.gists.history.GistHistory>`
        self.history = [GistHistory(h, self) for h in data.get('history', [])]

        ## New urls

        #: Comments URL (not a template)
        self.comments_url = data.get('comments_url', '')

        #: Commits URL (not a template)
        self.commits_url = data.get('commits_url', '')

        #: Forks URL (not a template)
        self.forks_url = data.get('forks_url', '')
Пример #15
0
    def __init__(self, comment, session=None):
        super(IssueComment, self).__init__(comment, session)

        user = comment.get('user')
        #: :class:`User <github3.users.User>` who made the comment
        self.user = User(user, self) if user else None

        #: Issue url (not a template)
        self.issue_url = comment.get('issue_url')
Пример #16
0
 def __init__(self, data, session=None):
     super(UserSearchResult, self).__init__(data, session)
     result = data.copy()
     #: Score of this search result
     self.score = result.pop('score')
     #: Text matches
     self.text_matches = result.pop('text_matches', [])
     #: User object matching the search
     self.user = User(result, self)
Пример #17
0
def _team(payload):
    from github3.orgs import Team
    from github3.repos import Repository
    from github3.users import User
    if payload.get('team'):
        payload['team'] = Team(payload['team'], None)
    if payload.get('repo'):
        payload['repo'] = Repository(payload['repo'], None)
    if payload.get('user'):
        payload['user'] = User(payload['user'], None)
    return payload
Пример #18
0
 def __init__(self, stats_object, session=None):
     super(ContributorStats, self).__init__(stats_object, session)
     #: Contributor in particular that this relates to
     self.author = User(stats_object.get('author', {}), session)
     #: Total number of commits authored by ``author``.
     self.total = stats_object.get('total')
     #: List of weekly dictionaries.
     self.weeks = stats_object.get('weeks', [])
     #: Alternative collection of weekly dictionaries
     #: This provides a datetime object and easy to remember keys for each
     #: element in the list. 'w' -> 'start of week', 'a' -> 'Number of additions',
     #: 'd' -> 'Number of deletions', 'c' -> 'Number of commits'
     self.alt_weeks = [alternate_week(w) for w in self.weeks]
Пример #19
0
    def __init__(self, event, session=None):
        super(IssueEvent, self).__init__(event, session)
        # The type of event:
        #   ('closed', 'reopened', 'subscribed', 'merged', 'referenced',
        #    'mentioned', 'assigned')
        #: The type of event, e.g., closed
        self.event = event.get('event')
        #: SHA of the commit.
        self.commit_id = event.get('commit_id')
        self._api = event.get('url', '')

        #: :class:`Issue <github3.issues.Issue>` where this comment was made.
        self.issue = event.get('issue')
        if self.issue:
            from github3.issues import Issue
            self.issue = Issue(self.issue, self)

        #: :class:`User <github3.users.User>` who caused this event.
        self.actor = event.get('actor')
        if self.actor:
            self.actor = User(self.actor, self)

        #: :class:`User <github3.users.User>` that generated the event.
        self.actor = event.get('actor')
        if self.actor:
            self.actor = User(self.actor, self._session)

        #: Number of comments
        self.comments = event.get('comments', 0)

        #: datetime object representing when the event was created.
        self.created_at = self._strptime(event.get('created_at'))

        #: Dictionary of links for the pull request
        self.pull_request = event.get('pull_request', {})

        self._uniq = self.commit_id
Пример #20
0
    def user(self, login=None):
        """Returns a User object for the specified login name if
        provided. If no login name is provided, this will return a User
        object for the authenticated user.

        :param str login: (optional)
        :returns: :class:`User <github3.users.User>`
        """
        if login:
            url = self._build_url('users', login)
        else:
            url = self._build_url('user')

        json = self._json(self._get(url), 200)
        return User(json, self._session) if json else None
Пример #21
0
 def __init__(self, status):
     super(Status, self).__init__(status)
     #: datetime object representing the creation of the status object
     self.created_at = self._strptime(status.get('created_at'))
     #: :class:`User <github3.users.User>` who created the object
     self.creator = User(status.get('creator'))
     #: Short description of the Status
     self.description = status.get('description')
     #: GitHub ID for the status object
     self.id = status.get('id')
     #: State of the status, e.g., 'success', 'pending', 'failed', 'error'
     self.state = status.get('state')
     #: URL to view more information about the status
     self.target_url = status.get('target_url')
     #: datetime object representing the last time the status was updated
     self.updated_at = self._strptime(status.get('updated_at'))
Пример #22
0
 def __init__(self, comment, session=None):
     super(RepoComment, self).__init__(comment, session)
     #: Commit id on which the comment was made.
     self.commit_id = comment.get('commit_id')
     #: URL of the comment on GitHub.
     self.html_url = comment.get('html_url')
     #: The line number where the comment is located.
     self.line = comment.get('line')
     #: The path to the file where the comment was made.
     self.path = comment.get('path')
     #: The position in the diff where the comment was made.
     self.position = comment.get('position')
     #: datetime object representing when the comment was updated.
     self.updated_at = self._strptime(comment.get('updated_at'))
     #: Login of the user who left the comment.
     self.user = None
     if comment.get('user'):
         self.user = User(comment.get('user'), self)
Пример #23
0
 def __init__(self, dest, direction):
     super(PullDestination, self).__init__(None)
     #: Direction of the merge with respect to this destination
     self.direction = direction
     #: Full reference string of the object
     self.ref = dest.get('ref')
     #: label of the destination
     self.label = dest.get('label')
     #: :class:`User <github3.users.User>` representing the owner
     self.user = None
     if dest.get('user'):
         self.user = User(dest.get('user'), None)
     #: SHA of the commit at the head
     self.sha = dest.get('sha')
     self._repo_name = ''
     self._repo_owner = ''
     if dest.get('repo'):
         self._repo_name = dest['repo'].get('name')
         self._repo_owner = dest['repo']['owner'].get('login')
     self.repo = (self._repo_owner, self._repo_name)
Пример #24
0
    def __init__(self, deployment, session=None):
        super(Deployment, self).__init__(deployment, session)
        self._api = deployment.get('url')

        #: GitHub's id of this deployment
        self.id = deployment.get('id')

        #: SHA of the branch on GitHub
        self.sha = deployment.get('sha')

        #: The reference used to create the Deployment, e.g.,
        #: `deploy-20140526`
        self.ref = deployment.get('ref')

        #: User object representing the creator of the deployment
        self.creator = deployment.get('creator')
        if self.creator:
            self.creator = User(self.creator, self)

        #: JSON string payload of the Deployment
        self.payload = deployment.get('payload')

        #: Date the Deployment was created
        self.created_at = self._strptime(deployment.get('created_at'))

        #: Date the Deployment was updated
        self.updated_at = self._strptime(deployment.get('updated_at'))

        #: Description of the deployment
        self.description = deployment.get('description')

        #: Target for the deployment, e.g., 'production', 'staging'
        self.environment = deployment.get('environment')

        #: URL to get the statuses of this deployment
        self.statuses_url = deployment.get('statuses_url')
Пример #25
0
def _follow(payload):
    from github3.users import User
    if payload.get('target'):
        payload['target'] = User(payload['target'], None)
    return payload
Пример #26
0
def _member(payload):
    from github3.users import User
    if payload.get('member'):
        payload['member'] = User(payload['member'], None)
    return payload
Пример #27
0
    def __init__(self, pull, session=None):
        super(PullRequest, self).__init__(pull, session)
        self._api = pull.get('url', '')
        #: Base of the merge
        self.base = PullDestination(pull.get('base'), 'Base')
        #: Body of the pull request message
        self.body = pull.get('body', '')
        #: Body of the pull request as HTML
        self.body_html = pull.get('body_html', '')
        #: Body of the pull request as plain text
        self.body_text = pull.get('body_text', '')
        #: Number of additions on this pull request
        self.additions = pull.get('additions')
        #: Number of deletions on this pull request
        self.deletions = pull.get('deletions')

        # If the pull request has been closed
        #: datetime object representing when the pull was closed
        self.closed_at = pull.get('closed_at')
        if self.closed_at:
            self.closed_at = self._strptime(self.closed_at)

        #: datetime object representing when the pull was created
        self.created_at = self._strptime(pull.get('created_at'))
        #: URL to view the diff associated with the pull
        self.diff_url = pull.get('diff_url')
        #: The new head after the pull request
        self.head = PullDestination(pull.get('head'), 'Head')
        #: The URL of the pull request
        self.html_url = pull.get('html_url')
        #: The unique id of the pull request
        self.id = pull.get('id')
        #: The URL of the associated issue
        self.issue_url = pull.get('issue_url')

        # These are the links provided by the dictionary in the json called
        # '_links'. It's structure is horrific, so to make this look a lot
        # cleaner, I reconstructed what the links would be:
        #  - ``self`` is just the api url, e.g.,
        #    https://api.github.com/repos/:user/:repo/pulls/:number
        #  - ``comments`` is just the api url for comments on the issue, e.g.,
        #    https://api.github.com/repos/:user/:repo/issues/:number/comments
        #  - ``issue`` is the api url for the issue, e.g.,
        #    https://api.github.com/repos/:user/:repo/issues/:number
        #  - ``html`` is just the html_url attribute
        #  - ``review_comments`` is just the api url for the pull, e.g.,
        #    https://api.github.com/repos/:user/:repo/pulls/:number/comments
        #: Dictionary of _links
        self.links = {
            'self':
            self._api,
            'comments':
            '/'.join([self._api.replace('pulls', 'issues'), 'comments']),
            'issue':
            self._api.replace('pulls', 'issues'),
            'html':
            self.html_url,
            'review_comments':
            self._api + '/comments'
        }

        #: datetime object representing when the pull was merged
        self.merged_at = pull.get('merged_at')
        # If the pull request has been merged
        if self.merged_at:
            self.merged_at = self._strptime(self.merged_at)
        #: Whether the pull is deemed mergeable by GitHub
        self.mergeable = pull.get('mergeable', False)
        #: Whether it would be a clean merge or not
        self.mergeable_state = pull.get('mergeable_state', '')
        #: SHA of the merge commit
        self.merge_commit_sha = pull.get('merge_commit_sha', '')
        #: :class:`User <github3.users.User>` who merged this pull
        self.merged_by = pull.get('merged_by')
        if self.merged_by:
            self.merged_by = User(self.merged_by, self)
        #: Number of the pull/issue on the repository
        self.number = pull.get('number')
        #: The URL of the patch
        self.patch_url = pull.get('patch_url')

        m = match('https://github\.com/(\S+)/(\S+)/issues/\d+', self.issue_url)
        #: Returns ('owner', 'repository') this issue was filed on.
        self.repository = m.groups()
        #: The state of the pull
        self.state = pull.get('state')
        #: The title of the request
        self.title = pull.get('title')
        #: datetime object representing the last time the object was changed
        self.updated_at = self._strptime(pull.get('updated_at'))
        #: :class:`User <github3.users.User>` object representing the creator
        #  of the pull request
        self.user = pull.get('user')
        if self.user:
            self.user = User(self.user, self)