Пример #1
0
 def get_stargazers(self):
     return PaginatedList(
         user.User,
         self._requester,
         self.url + "/stargazers",
         None
     )
Пример #2
0
def get_github_issue_timeline(issue):
    # This has to be a custom since PyGithub doesn't support the starfox preview
    starfox_header = "application/vnd.github.starfox-preview+json"
    headers_accept = f"{starfox_header}, {Consts.issueTimelineEventsPreview}"
    return list(
        PaginatedList(
            TimelineEvent,
            issue._requester,
            issue.url + "/timeline",
            None,
            headers={"Accept": headers_accept},
        ))
Пример #3
0
    def get_pull_requests(self, repository: Repository) -> List[PullRequest]:
        gh = Github(self._get_installation_token())
        repo = gh.get_repo(repository.full_name, lazy=True)

        def _new_pull_request(_, __, data, *args, **kwargs):
            pr, _ = _update_pull_request(self.installation, repository, data)
            return pr

        result = []
        for pr in PaginatedList(
                _new_pull_request,
                repo._requester,
                repo.url + "/pulls",
                dict(state="open"),
        ):  # type: PullRequest
            result.append(pr)

        logger.info(f"Loaded {len(result)} pull requests")
        return result
Пример #4
0
    def get_pull_request_commits(
        self,
        repository: RepositoryIdentifier,
        pr_id: int,
    ) -> List[Commit]:

        gh = Github(self._get_installation_token())
        repo = gh.get_repo(repository.full_name, lazy=True)

        def _new_commit(_, __, data, *args, **kwargs):
            return commit_data_to_commit(data)

        result = []
        for commit in PaginatedList(_new_commit, repo._requester,
                                    f"{repo.url}/pulls/{pr_id}/commits",
                                    {"per_page": 100}):  # type: Commit
            result.append(commit)

        logger.info(f"Loaded {len(result)} commits")
        return result
Пример #5
0
    def get_statuses(self, repository: RepositoryIdentifier,
                     sha: str) -> List[Tuple[str, CheckStatus]]:
        gh = Github(self._get_installation_token())
        repo = gh.get_repo(repository.full_name, lazy=True)
        result = []

        # hacks necessary to prevent the lib from requesting commits first
        def _new_status(_, __, data, *args, **kwargs):
            return data["context"], CheckStatus(data["state"])

        for status in PaginatedList(
                _new_status,
                repo._requester,
                repo.url + "/commits/" + sha + "/status",
            {"per_page": 100},
                list_item="statuses",
        ):
            logger.info(f"Found {status}")
            result.append(status)

        return result
Пример #6
0
def _get_token_otp(app_name, user):
    otp = click.prompt('2FA code (SMS or Authenticator app)')
    request_header = {'X-GitHub-OTP': otp}
    try:
        auths = PaginatedList(Authorization,
                              user._requester,
                              "/authorizations",
                              None,
                              headers=request_header)
        auth = [auth for auth in auths if auth.note == app_name][0]
        auth._requester.requestJsonAndCheck("DELETE",
                                            auth.url,
                                            headers=request_header)

        return user.create_authorization(note=app_name,
                                         scopes=['repo', 'gist'],
                                         onetime_password=otp)
    except BadCredentialsException:
        raise click.ClickException(
            'Bad credentials, make sure your username, password and 2FA code are correct'
        )