def setUp(self): self.token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) self.comment = GitHubComment(self.token, 'gitmate-test-user/test', CommentType.COMMIT, 25047607) self.issue_comment = GitHubComment(self.token, 'gitmate-test-user/test', CommentType.ISSUE, 309221241)
def _github_open_merge_request(self, commit_msg, body, branch_name) -> GitHubMergeRequest: """Create a GitHub pull request with the given dependency update.""" url = f'{IGitt.GitHub.BASE_URL}/repos/{self.slug}/pulls' response = requests.Session().post( url, headers={ 'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {self.token}' }, json={ 'title': commit_msg, 'body': body, 'head': branch_name, 'base': 'master', 'maintainer_can_modify': True } ) try: response.raise_for_status() except Exception as exc: raise RuntimeError(f"Failed to create a pull request: {response.text}") from exc mr_number = response.json()['number'] _LOGGER.info(f"Newly created pull request #{mr_number} available at {response.json()['html_url']}") return GitHubMergeRequest.from_data( response.json(), token=GitHubToken(self.token), repository=self.slug, number=mr_number )
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 test_github_search_pagination(): # this is to cover the pagination format from github search API token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) _fetch(GITHUB_BASE_URL, 'get', token, '/search/issues', query_params={'q': ' repo:coala/corobo'})
def test_get_installations(self): app_token = GitHubToken(os.environ.get('GITHUB_APP_TEST_TOKEN', '')) app_user = GitHubUser(app_token) jwt = GitHubJsonWebToken(os.environ['GITHUB_PRIVATE_KEY'], int(os.environ['GITHUB_TEST_APP_ID'])) self.assertEqual({i.app_id for i in app_user.get_installations(jwt)}, {5408})
def assign(self, issue: Issue, assignees: typing.List[str]) -> None: """Assign users (by their accounts) to the given issue.""" if self.service_type == ServiceType.GITHUB: users = (GitHubUser(GitHubToken(self.token), username) for username in assignees) elif self.service_type == ServiceType.GITLAB: users = (GitLabUser(GitLabPrivateToken(self.token), username) for username in assignees) else: raise NotImplementedError issue.assign(*users)
def test_raises_runtime_error(self): try: token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) _fetch(GITHUB_BASE_URL, 'get', token, '/repos/gitmate-test-user/wontexist') except RuntimeError as ex: self.assertEqual( ex.args[0], '{"message":"Not Found",' '"documentation_url":"https://developer.github.com/v3"}') self.assertEqual(ex.args[1], 404)
def get_token(self, raw_token, private_token=False): """ Returns appropriate Token object for the Provider. :param raw_token: The token string :return: IGitt Token object """ if self.value in ['github', 'github-app']: return GitHubToken(raw_token) elif self.value == 'gitlab': return (GitLabPrivateToken(raw_token) if private_token else GitLabOAuthToken(raw_token)) else: raise NotImplementedError
def __init__(self, service_type: ServiceType, service_url: str, token: str, slug: str): """Initialize source code management tools abstraction. Note that we are using IGitt for calls. IGitt keeps URL to services in its global context per GitHub/GitLab. This is global context is initialized in the manager with a hope to fix this behavior for our needs. """ self.service_type = service_type self.slug = slug self.service_url = service_url self.token = token if self.service_type == ServiceType.GITHUB: self.repository = GitHubRepository(token=GitHubToken(token), repository=slug) elif self.service_type == ServiceType.GITLAB: self.repository = GitLabRepository(token=GitLabPrivateToken(token), repository=slug) else: raise NotImplementedError
def setUp(self): super().setUpWithPlugin('ack') self.gh_comment_data = { 'repository': {'full_name': self.repo.full_name, 'id': 49558751}, 'issue': {'number': 7, 'pull_request': {}}, 'comment': {'id': 0}, 'action': 'created' } self.gh_pr_data = { 'repository': {'full_name': self.repo.full_name, 'id': 49558751}, 'pull_request': {'number': 7}, 'action': 'opened' } self.gl_comment_data = { 'project': {'path_with_namespace': self.gl_repo.full_name}, 'object_attributes': { 'action': 'open', 'id': 25, 'iid': 0, 'noteable_type': 'MergeRequest' }, 'merge_request': {'iid': 25} } self.gl_pr_data = { 'object_attributes': { 'target': {'path_with_namespace': self.gl_repo.full_name}, 'action': 'update', 'oldrev': 'areallylongrandomshayoudontneedtocareabout', 'iid': 25 } } self.gh_token = GitHubToken(environ['GITHUB_TEST_TOKEN']) self.gl_token = GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']) self.gh_commit = GitHubCommit( self.gh_token, self.repo.full_name, 'f6d2b7c66372236a090a2a74df2e47f42a54456b') self.gh_commit_2 = GitHubCommit( self.gh_token, self.repo.full_name, '3f2a3b37a2943299c589004c2a5be132e9440cba') self.gl_commit = GitLabCommit( self.gl_token, self.gl_repo.full_name, 'f6d2b7c66372236a090a2a74df2e47f42a54456b') self.gl_commit_2 = GitLabCommit( self.gl_token, self.gl_repo.full_name, '3f2a3b37a2943299c589004c2a5be132e9440cba')
def unassigned_issues_activity_json(request): try: GH_TOKEN = get_api_key('GH') except Exception: return HttpResponse('[]') org_name = get_org_name() org_repo_name = org_name # Here 'org_repo_name' is the name of repository of a organization. # (assumed here, that name of repository is same as the organization name.) # But you can change 'org_repo_name' as per your requirement. repo_name = org_name + '/' + org_repo_name # 'repo_name' is a full name of repository e.g. `fossasia/susi_server` # which further used for query (assuming here 'org_name' is different from # 'org_repo_name') repo = GitHubRepository(GitHubToken(GH_TOKEN), repo_name) mr_requests = repo.merge_requests final_list = run(mr_requests) return HttpResponse(json.dumps(final_list))
def test_github_conditional_request(): token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) repo = GitHubRepository( token, os.environ.get('GITHUB_TEST_REPO', 'gitmate-test-user/test')) repo.refresh() prev_data = repo.data._data prev_count = _RESPONSES[repo.url].headers.get('X-RateLimit-Remaining') repo.refresh() new_data = repo.data._data new_count = _RESPONSES[repo.url].headers.get('X-RateLimit-Remaining') # check that no reduction in rate limit is observed assert prev_count == new_count # check that response data hasn't been modified assert prev_data == new_data
def test_pagination(): # this is to cover the branch where it handles the pagination token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) _fetch(GITHUB_BASE_URL, 'get', token, '/repos/coala/corobo/issues')
def setUp(self): self.gh = GitHub(GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')))
def setUp(self): self.token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) self.mr = GitHubMergeRequest(self.token, 'gitmate-test-user/test', 7)
def setUp(self): self.token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) self.sils = GitHubUser(self.token, 'sils') self.user = GitHubUser(self.token)
def setUp(self): self.token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) self.iss = GitHubIssue(self.token, 'gitmate-test-user/test', 39)
def setUp(self): self.token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) fork_token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN_2', '')) self.repo = GitHubRepository(self.token, 'gitmate-test-user/test') self.fork_repo = GitHubRepository(fork_token, 'gitmate-test-user/test')
def setUp(self): super().setUpWithPlugin('pr_stale_reminder') self.gh_token = GitHubToken(environ['GITHUB_TEST_TOKEN']) self.gl_token = GitLabOAuthToken(environ['GITLAB_TEST_TOKEN'])
def setUp(self): self.token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) self.org = GitHubOrganization(self.token, 'gitmate-test-org') self.user = GitHubOrganization(self.token, 'gitmate-test-user')
def test_tokens(self): github_token = GitHubToken('test') self.assertEqual(github_token.parameter, {'access_token': 'test'}) self.assertEqual(github_token.value, 'test')
def setUp(self): self.token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) self.iss = GitHubIssue(self.token, 'gitmate-test-user/test', 12) self.reaction = GitHubReaction(self.token, self.iss, 17051518)