示例#1
0
def get_prs(
    repo: github.Repository.Repository,
    t_a: datetime.datetime,
    t_b: datetime.datetime,
):
    merged = []  # PRs merged during the month
    for pr in repo.get_pulls("closed", sort="updated",
                             direction="desc"):  # most recently merged first
        if pr.merged:
            if t_a <= pr.merged_at < t_b:  # could check `.month` instead...
                merged.append(pr)
            if pr.merged_at < t_a:
                break

    wip = []  # WIP PRs (not merged, still open at this time)
    for pr in repo.get_pulls("open"):
        if pr.created_at < t_b:  # and pr.updated_at >= t_a:
            wip.append(pr)

    return _Prs(merged, wip)
示例#2
0
def get_prs(
    repo: github.Repository.Repository,
    t_a: datetime.datetime,
    t_b: datetime.datetime,
):
    merged = []  # PRs merged during the month
    pl = repo.get_pulls("closed", sort="updated",
                        direction="desc")  # most recently *updated* first
    for pr in _maybe_prog(pl, desc=repo.name):
        if pr.merged:
            if t_a <= pr.merged_at < t_b:
                merged.append(pr)
            # if pr.merged_at < t_a:
            #     break
            # ^ This causes some to be missed since recently updated not equiv. to recently merged.
    merged.sort(key=lambda pr: pr.merged_at)  # earliest merged first

    wip = []  # WIP PRs (not merged, still open at this time)
    for pr in repo.get_pulls("open"):
        if pr.created_at < t_b:  # and pr.updated_at >= t_a:
            wip.append(pr)

    return _Prs(merged, wip)
    def search_repo(self, repo: github.Repository.Repository):
        if not self._pr and not self._issue:
            self._pr = True

        if self._pr:
            for pr_state in self._pr_state:
                prs = repo.get_pulls(state=pr_state, sort='updated')
                # totalCount does not work
                # https://github.com/PyGithub/PyGithub/issues/870
                total = 0
                for _ in prs:
                    total = total + 1
                for i, pr in enumerate(prs):
                    self.printcl('[PR][%s][%d/%d]\t\t%s' % (self._state_to_utf[pr_state], i, total, repo.name))
                    # It's not me
                    if self._search_username not in pr.user.login:
                        continue

                    # Check for max age
                    if (datetime.now().date() - pr.updated_at.date()).days > self._age:
                        break

                    self.print_pr(pr)

        if self._issue:
            for issue_state in self._issue_state:
                issues = repo.get_issues(state=issue_state, sort='updated')
                total = 0
                for _ in issues:
                    total = total + 1
                for i, issue in enumerate(issues):
                    # GitHub's REST API v3 considers every pull request an issue, but not every issue is a pull request.
                    # You can identify pull requests by the pull_request key.
                    if issue.pull_request:
                        continue
                    self.printcl('[ISSUE][%s][%d/%d]\t%s' % (self._state_to_utf[issue_state], i + 1, total, repo.name))
                    # It's not me
                    check_for_name_in = [issue.user.login]
                    if issue.closed_by:
                        check_for_name_in.append(issue.closed_by.login)
                    if issue.assignee:
                        check_for_name_in.append(issue.assignee.login)
                    if self._search_username not in check_for_name_in:
                        continue

                    # Check for max age
                    if (datetime.now().date() - issue.updated_at.date()).days > self._age:
                        break

                    self.print_issue(issue)
示例#4
0
    def search_repo(self, repo: github.Repository.Repository,
                    repo_out: github.Repository.Repository):
        repo_path = "/tmp/%s" % (repo.name)
        call([
            "git", "clone",
            "https://github.com/%s" % (repo.full_name), repo_path
        ])
        call(("git --git-dir %s/.git remote add output https://github.com/%s" %
              (repo_path, repo_out.full_name)).split(' '))
        call(["ls", "-l", repo_path])

        for pr_state in self._pr_state:
            prs = repo.get_pulls(state=pr_state, sort='updated')
            total = 0
            for _ in prs:
                total = total + 1
            for i, pr in enumerate(prs):
                print('[PR][%s][%d/%d]\t%s %s' %
                      (pr_state, i + 1, total, repo.name, pr.title))
                #print('Moved from: %s#%d' % (repo.full_name, pr.number))
                #print('Original author: @%s' % (pr.user.login))
                #print('Body: %s' % (pr.body))

                call(("git --git-dir %s/.git fetch origin pull/%d/head:%d" %
                      (repo_path, pr.number, pr.number)).split(' '))
                call(("git --git-dir %s/.git push output %d" %
                      (repo_path, pr.number)).split(' '))
                head = "%s:%d" % (repo_out.owner.login, pr.number)
                body = \
'''
%s

Moved from: %s#%d
Original author: @%s
''' % (pr.body, repo.full_name, pr.number, pr.user.login)

                repo_out.create_pull(title=pr.title,
                                     head=head,
                                     base="master",
                                     body=body)
示例#5
0
 def check_if_pull_request_exists(self, repo: github.Repository.Repository,
                                  head: str) -> bool:
     pulls = repo.get_pulls(head=head)
     return pulls.totalCount != 0