Skip to content

Commit 2800c8d

Browse files
committed
script/redmine-upkeep: pass token to auth
I believe I structured it this way originally because I had copied from ptl-tool.py which used a personal github token. Signed-off-by: Patrick Donnelly <[email protected]>
1 parent 72b3438 commit 2800c8d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/script/redmine-upkeep.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747

4848
GITHUB_ACTION_LOG = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/actions/runs/{GITHUB_RUN_ID}"
4949

50-
GITHUB_USER = os.getenv("GITHUB_USER", os.getenv("GITHUB_USER", getuser()))
5150
GITHUB_API_ENDPOINT = f"https://api.github.com/repos/{GITHUB_REPOSITORY}"
5251

5352
REDMINE_CUSTOM_FIELD_ID_BACKPORT = 2
@@ -112,8 +111,10 @@ def process(self, msg, kwargs):
112111
log.addHandler(log_stream)
113112
log.setLevel(logging.INFO)
114113

115-
def gitauth():
116-
return (GITHUB_USER, GITHUB_TOKEN)
114+
GITHUB_HEADERS = {
115+
"Authorization": f"Bearer {GITHUB_TOKEN}",
116+
"X-GitHub-Api-Version": "2022-11-28",
117+
}
117118

118119
def post_github_comment(session, pr_id, body):
119120
"""Helper to post a comment to a GitHub PR."""
@@ -125,7 +126,7 @@ def post_github_comment(session, pr_id, body):
125126
endpoint = f"{GITHUB_API_ENDPOINT}/issues/{pr_id}/comments"
126127
payload = {'body': body}
127128
try:
128-
response = session.post(endpoint, auth=gitauth(), json=payload)
129+
response = session.post(endpoint, headers=GITHUB_HEADERS, json=payload)
129130
response.raise_for_status()
130131
log.info(f"Successfully posted comment to PR #{pr_id}.")
131132
return True
@@ -341,7 +342,7 @@ def fetch_pr(self):
341342
endpoint = f"{GITHUB_API_ENDPOINT}/pulls/{pr_id}"
342343
params = {}
343344
try:
344-
response = self.github_session.get(endpoint, auth=gitauth(), params=params)
345+
response = self.github_session.get(endpoint, headers=GITHUB_HEADERS, params=params)
345346
response.raise_for_status()
346347
pr_data = response.json()
347348
self.logger.debug("PR #%d json:\n%s", pr_id, pr_data)
@@ -1395,6 +1396,10 @@ def main():
13951396
log.fatal("REDMINE_API_KEY not found! Please set REDMINE_API_KEY environment variable or ~/.redmine_key.")
13961397
sys.exit(1)
13971398

1399+
if GITHUB_TOKEN is None:
1400+
log.fatal("GITHUB_TOKEN not found! Please set GITHUB_TOKEN environment variable or ~/.github_token.")
1401+
sys.exit(1)
1402+
13981403
if IS_GITHUB_ACTION and GITHUB_REPOSITORY != "ceph/ceph":
13991404
log.fatal("refusing to run ceph/ceph.git github action for repository {GITHUB_REPOSITORY}")
14001405
sys.exit(0)

0 commit comments

Comments
 (0)