Exemple #1
0
def check_prs_for_current_release_are_released(
        repo: github.Repository.Repository) -> None:
    """Checks that all pull requests for current release have a
    'PR: released' label.

    Args:
        repo: github.Repository.Repository. The PyGithub object for the repo.

    Raises:
        Exception. Some pull requests for current release do not have a
            "PR: released" label.
    """
    current_release_label = repo.get_label(
        constants.release_constants.LABEL_FOR_CURRENT_RELEASE_PRS)
    current_release_prs = repo.get_issues(state='all',
                                          labels=[current_release_label])
    for pr in current_release_prs:
        label_names = [label.name for label in pr.labels]
        if constants.release_constants.LABEL_FOR_RELEASED_PRS not in (
                label_names):
            open_new_tab_in_browser_if_possible(
                'https://github.com/oppia/oppia/pulls?utf8=%E2%9C%93&q=is%3Apr'
                '+label%3A%22PR%3A+for+current+release%22+')
            raise Exception(
                'There are PRs for current release which do not have '
                'a \'PR: released\' label. Please ensure that they are '
                'released before release summary generation.')
Exemple #2
0
    def search_repo(self, repo: github.Repository.Repository,
                    repo_out: github.Repository.Repository):
        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):
                upstream_tag = False
                confirm_tag = False

                tag = ''
                for label in issue.labels:
                    if label.name == 'upstream':
                        upstream_tag = True
                    elif label.name == 'confirm':
                        confirm_tag = True
                    else:
                        tag = label.name.title()
                if not (not confirm_tag and upstream_tag):
                    continue

                # 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

                print("--------")
                print('[ISSUE][%s][%d/%d]\t%s %s' %
                      (issue_state, i + 1, total, repo.name, issue.title))
                title = '%s: %s' % (tag, issue.title)
                print(title)
                print('Moved from: %s#%d' % (repo.full_name, issue.number))
                print('Original author: @%s' % (issue.user.login))
                issue_body = issue.body.strip()
                if not issue_body:
                    issue_body = '**No description provided.** :sleeping:'
                body = \
'''
Moved from: %s#%d
Original author: @%s

### Issue description
%s
'''% (repo.full_name, issue.number, issue.user.login, issue_body)
                print(body)

                # close issue and create a new one
                issue.edit(state='closed')
                repo_out.create_issue(title=title, body=body)
    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)