Esempio 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()
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio n. 6
0
    def __init__(
        self,
        owner,
        repo,
        pr=None,
        branch=None,
        token=None,
        url=None,
        commit=None,
        ignore_paths=None,
        prefix=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.stopped_early = False
        self.prefix = prefix
        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

        self.github_repo = self.github.repository(self.owner, self.repo)
        all_commits = self.repo_commits(self.github_repo)
        self.master_sha = all_commits[0].sha
        print("Master SHA: {0}".format(self.master_sha))

        print("Branch: {0}".format(branch))
        self.pull_request_number = None
        if branch and not pr:
            for github_repo in [self.github_repo, self.github_repo.parent]:
                if pr:
                    break

                if not github_repo:
                    continue

                try:
                    # github.py == 0.9.6
                    pulls = github_repo.iter_pulls()
                except AttributeError:
                    pulls = github_repo.pull_requests()

                for pull_request in pulls:
                    print("Branch: {} - Pull Request Head Ref: {}".format(
                        branch, pull_request.head.ref))
                    if pull_request.head.ref == branch:
                        pr = pull_request.number
                        self.github_repo = github_repo
                        break

        self.owner = self.github_repo.owner
        self.repo = self.github_repo.name

        # 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.pull_request_number = pr
        self.pull_request = self.github.pull_request(self.owner, self.repo, pr)
        self.target_sha = self.pull_request.base.sha
        self.target_branch = self.pull_request.base.label
        try:
            # github.py == 0.9.6
            try:
                git.fetch(
                    self.pull_request.base.to_json()["repo"]["clone_url"])
            except subprocess.CalledProcessError:
                git.fetch(self.pull_request.base.to_json()["repo"]["ssh_url"])
        except AttributeError:
            # latest github.py
            try:
                git.fetch(
                    self.pull_request.base.repository.as_dict()["clone_url"])
            except subprocess.CalledProcessError:
                git.fetch(
                    self.pull_request.base.repository.as_dict()["ssh_url"])

        print("Target SHA: {0}".format(self.target_sha))
        print("Target Branch: {0}".format(self.target_branch))
        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.diff = git.diff(self.target_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()
        self.messages_in_files = dict()