MCPcopy Create free account
hub / github.com/DataDog/datadog-agent / GithubAPI

Class GithubAPI

tasks/libs/common/github_api.py:20–209  ·  view source on GitHub ↗

Helper class to perform API calls against the Github API, using a Github PAT.

Source from the content-addressed store, hash-verified

18
19
20class GithubAPI:
21 """
22 Helper class to perform API calls against the Github API, using a Github PAT.
23 """
24
25 BASE_URL = "https://api.github.com"
26
27 def __init__(self, repository=""):
28 self._auth = self._chose_auth()
29 self._github = Github(auth=self._auth)
30 self._repository = self._github.get_repo(repository)
31
32 def repo(self):
33 """
34 Gets the repo info.
35 """
36
37 return self._repository
38
39 def get_branch(self, branch_name):
40 """
41 Gets info on a given branch in the given Github repository.
42 """
43 try:
44 return self._repository.get_branch(branch_name)
45 except GithubException as e:
46 if e.status == 404:
47 return None
48 raise e
49
50 def create_pr(self, pr_title, pr_body, base_branch, target_branch):
51 """
52 Creates a PR in the given Github repository.
53 """
54 return self._repository.create_pull(title=pr_title, body=pr_body, base=base_branch, head=target_branch)
55
56 def update_pr(self, pull_number, milestone_number, labels):
57 """
58 Updates a given PR with the provided milestone number and labels.
59 """
60 pr = self._repository.get_pull(pull_number)
61 milestone = self._repository.get_milestone(milestone_number)
62 issue = pr.as_issue()
63 issue.edit(milestone=milestone, labels=labels)
64 return pr
65
66 def get_milestone_by_name(self, milestone_name):
67 """
68 Searches for a milestone in the given repository that matches the provided name,
69 and returns data about it.
70 """
71 milestones = self._repository.get_milestones()
72 for milestone in milestones:
73 if milestone.title == milestone_name:
74 return milestone
75 return None
76
77 def get_pulls(self, milestone=None, labels=None):

Callers 10

verify_workspaceFunction · 0.85
list_major_changeFunction · 0.85
create_rcFunction · 0.85
unfreezeFunction · 0.85
update_last_stableFunction · 0.85
trigger_macos_workflowFunction · 0.85
follow_workflow_runFunction · 0.85
download_artifactsFunction · 0.85
download_logsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…