Skip to content

Commit 2aeeeb5

Browse files
committed
Merge PR ceph#65217 into main
* refs/pull/65217/head: .github: pass GITHUB_TOKEN to redmine-upkeep .github/workflows: remove unnecessary permissions for leaving PR comments script/redmine-upkeep: pass token to auth script/redmine-upkeep: cleanup formatting for github comment Reviewed-by: Ernesto Puerta <[email protected]>
2 parents fb8387a + 8afcf9a commit 2aeeeb5

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

.github/workflows/redmine-upkeep.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ jobs:
3939
runs-on: ubuntu-latest
4040
# This condition ensures the job only runs in the main ceph/ceph repository and only on the specified branches.
4141
if: github.repository == 'ceph/ceph' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feature/redmine-upkeep')
42-
permissions:
43-
# To allow writing comments on PRs:
44-
issues: write
4542
steps:
4643
- name: Checkout main branch for pull_request_target
4744
if: github.event_name == 'pull_request_target'
@@ -87,6 +84,7 @@ jobs:
8784
--git-dir=./ceph/
8885
env:
8986
REDMINE_API_KEY: ${{ secrets.REDMINE_API_KEY_BACKPORT_BOT }}
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9088

9189
- name: Run redmine-upkeep via test push
9290
if: github.event_name == 'push' && github.ref == 'refs/heads/feature/redmine-upkeep'
@@ -96,6 +94,7 @@ jobs:
9694
--git-dir=./ceph/
9795
env:
9896
REDMINE_API_KEY: ${{ secrets.REDMINE_API_KEY_BACKPORT_BOT }}
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9998

10099
- name: Run redmine-upkeep via merge on pull_request_target
101100
if: github.event_name == 'pull_request_target' && github.event.pull_request.merged == true
@@ -107,3 +106,4 @@ jobs:
107106
--merge-commit=${{ github.event.pull_request.merge_commit_sha }}
108107
env:
109108
REDMINE_API_KEY: ${{ secrets.REDMINE_API_KEY_BACKPORT_BOT }}
109+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/script/redmine-upkeep.py

Lines changed: 12 additions & 10 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)
@@ -1244,18 +1245,15 @@ def _execute_pull_request(self):
12441245
12451246
This is an automated message by src/script/redmine-upkeep.py.
12461247
1247-
I found one or more 'Fixes:' tags in the commit messages in
1248+
I found one or more `Fixes:` tags in the commit messages in
12481249
12491250
`git log {revrange}`
12501251
12511252
The referenced tickets are:
12521253
12531254
{tracker_links}
12541255
1255-
Those tickets do not reference this merged Pull Request. If this
1256-
Pull Request merge resolves any of those tickets, please update the
1257-
"Pull Request ID" field on each ticket. A future run of this
1258-
script will appropriately update them.
1256+
Those tickets do not reference this merged Pull Request. If this Pull Request merge resolves any of those tickets, please update the "Pull Request ID" field on each ticket. A future run of this script will appropriately update them.
12591257
12601258
Update Log: {GITHUB_ACTION_LOG}
12611259
@@ -1398,6 +1396,10 @@ def main():
13981396
log.fatal("REDMINE_API_KEY not found! Please set REDMINE_API_KEY environment variable or ~/.redmine_key.")
13991397
sys.exit(1)
14001398

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+
14011403
if IS_GITHUB_ACTION and GITHUB_REPOSITORY != "ceph/ceph":
14021404
log.fatal("refusing to run ceph/ceph.git github action for repository {GITHUB_REPOSITORY}")
14031405
sys.exit(0)

0 commit comments

Comments
 (0)