def test_github_installation_token(self): itoken = GitHubInstallationToken(60731, self.token) data = get(itoken, '/installation/repositories') self.assertEqual(data['total_count'], 1) self.assertEqual(data['repositories'][0]['full_name'], 'gitmate-test-org/test') self.assertEqual(itoken.jwt, self.token)
def setUp(self): self.gh = GitHub(GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', ''))) self.repo_name = 'org/test_repo' self.default_data = { 'repository': { 'full_name': self.repo_name }, 'pull_request': { 'number': 0 }, 'issue': { 'number': 0 }, 'action': 'opened', 'comment': { 'id': 1, }, 'commit': { 'sha': 'deadbeef', } } self.jwt = GitHubJsonWebToken(os.environ['GITHUB_PRIVATE_KEY'], int(os.environ['GITHUB_TEST_APP_ID'])) self.itoken = GitHubInstallationToken(60731, self.jwt) self.gh_inst = GitHub(self.itoken)
def token(self) -> IGittToken: """ Returns the installation token for the specified configuration. """ if self.provider == Providers.GITHUB.value: return GitHubInstallationToken(self.identifier, django_settings.GITHUB_JWT) # Other providers aren't implemented yet. raise NotImplementedError
def test_clone_url(self): self.assertEqual( self.repo.clone_url, 'https://{}@github.com/gitmate-test-user/test.git'.format( os.environ.get('GITHUB_TEST_TOKEN', ''))) # testing GitHub installation token jwt = GitHubJsonWebToken(os.environ['GITHUB_PRIVATE_KEY'], int(os.environ['GITHUB_TEST_APP_ID'])) itoken = GitHubInstallationToken(60731, jwt) repo = GitHubRepository(itoken, 'gitmate-test-user/test') self.assertRegex( repo.clone_url, r'https://*****:*****@github.com/gitmate-test-user/test.git' )
def get_installations(self, jwt): """ Gets the installations this user has access to. :param jwt: The GitHubJsonWebToken required to fetch data. """ # Don't move to module code, causes circular dependencies from IGitt.GitHub.GitHubInstallation import GitHubInstallation resp = get( self._token, '/user/installations', headers=PREVIEW_HEADER) return { GitHubInstallation.from_data( i, GitHubInstallationToken(i['id'], jwt), i['id']) for i in resp['installations'] }
def get_installation_token(inst): if inst.provider == Providers.GITHUB.value: return GitHubInstallationToken(inst.identifier, settings.GITHUB_JWT) # Other providers aren't implemented yet. raise NotImplementedError
def setUp(self): self.token = GitHubJsonWebToken(os.environ['GITHUB_PRIVATE_KEY'], int(os.environ['GITHUB_TEST_APP_ID'])) self.itoken = GitHubInstallationToken(60731, self.token) self.installation = GitHubInstallation(self.itoken, 60731)