Exemplo n.º 1
0
    def __init__(self,
                 owner,
                 repo,
                 pr=None,
                 branch=None,
                 token=None,
                 url=None,
                 commit=None,
                 ignore_paths=None):
        """
        GitHubInterface lets us post messages to GitHub.

        owner and repo are the repository owner/organization and repo name respectively.

        pr is the ID number of the pull request. branch is the branch name. either pr OR branch
        must be populated.

        token is your GitHub API token.

        url is the base URL of your GitHub instance, such as https://github.com

        commit is the commit hash we're running against

        ignore_paths are paths to ignore comments from
        """
        self.github = None
        self.ignore_paths = set(ignore_paths or [])
        if not url or url == 'https://github.com':
            self.github = github3.GitHub(token=token)
        else:
            self.github = github3.GitHubEnterprise(url, token=token)
        self.owner = owner
        self.repo = repo
        print('Branch: {0}'.format(branch))
        if branch and not pr:
            github_repo = self.github.repository(self.owner, self.repo)
            for pull_request in github_repo.iter_pulls():
                if pull_request.to_json()['head']['ref'] == branch:
                    pr = pull_request.to_json()['number']
                    break
        # TODO: support non-PR runs
        try:
            pr = int(pr)
        except (ValueError, TypeError):
            print('{0} is not a valid pull request ID'.format(pr))
            self.github = None
            return
        print('PR ID: {0}'.format(pr))
        self.pr = pr
        self.pull_request = self.github.pull_request(owner, repo, pr)
        self.commits = self.pr_commits(self.pull_request)
        self.last_sha = commit or git.current_sha()
        print('Last SHA: {0}'.format(self.last_sha))
        self.first_sha = self.commits[0].sha
        self.parent_sha = git.parent_sha(self.first_sha)
        self.diff = git.diff(self.parent_sha, self.last_sha)
        self.patch = unidiff.PatchSet(self.diff.split('\n'))
        self.review_comments = list(self.pull_request.review_comments())
        self.last_update = time.time()
Exemplo n.º 2
0
 def __init__(self, owner, repo, pr, token, url=None):
     if not url:
         self.gh = github3.GitHub(token=token)
     else:
         self.gh = github3.GitHubEnterprise(url, token=token)
     self.pull_request = self.gh.pull_request(owner, repo, pr)
     self.commits = [c for c in self.pull_request.commits()]
     self.last_sha = self.commits[-1].sha
     self.first_sha = self.commits[0].sha
     self.parent_sha = git.parent_sha(self.first_sha)
     self.diff = git.diff(self.parent_sha, self.last_sha)
Exemplo n.º 3
0
 def __init__(self, owner, repo, pr, token, url=None):
     self.github = None
     # TODO: support non-PR runs
     try:
         pr = int(pr)
     except (ValueError, TypeError):
         return
     if not url or url == 'https://github.com':
         self.github = github3.GitHub(token=token)
     else:
         self.github = github3.GitHubEnterprise(url, token=token)
     self.owner = owner
     self.repo = repo
     self.pr = pr
     self.pull_request = self.github.pull_request(owner, repo, pr)
     self.commits = self.pr_commits(self.pull_request)
     self.last_sha = self.commits[-1].sha
     self.first_sha = self.commits[0].sha
     self.parent_sha = git.parent_sha(self.first_sha)
     self.diff = git.diff(self.parent_sha, self.last_sha)
Exemplo n.º 4
0
 def __init__(self, owner, repo, pr, token, url=None):
     self.github = None
     # TODO: support non-PR runs
     try:
         pr = int(pr)
     except (ValueError, TypeError):
         return
     if not url or url == 'https://github.com':
         self.github = github3.GitHub(token=token)
     else:
         self.github = github3.GitHubEnterprise(url, token=token)
     self.owner = owner
     self.repo = repo
     self.pr = pr
     self.pull_request = self.github.pull_request(owner, repo, pr)
     self.commits = self.pr_commits(self.pull_request)
     self.last_sha = self.commits[-1].sha
     self.first_sha = self.commits[0].sha
     self.parent_sha = git.parent_sha(self.first_sha)
     self.diff = git.diff(self.parent_sha, self.last_sha)
Exemplo n.º 5
0
 def __init__(self, owner, repo, pr, token, url=None):
     self.github = None
     # TODO: support non-PR runs
     try:
         pr = int(pr)
     except ValueError:
         return
     if not url:
         self.github = github3.GitHub(token=token)
     else:
         self.github = github3.GitHubEnterprise(url, token=token)
     self.pull_request = self.github.pull_request(owner, repo, pr)
     # github3 has naming/compatibility issues
     try:
         self.commits = [c for c in self.pull_request.commits()]
     except (AttributeError, TypeError):
         self.commits = [c for c in self.pull_request.iter_commits()]
     self.last_sha = self.commits[-1].sha
     self.first_sha = self.commits[0].sha
     self.parent_sha = git.parent_sha(self.first_sha)
     self.diff = git.diff(self.parent_sha, self.last_sha)