Skip to content

Commit 921a26e

Browse files
committed
fix(ci): support integration tokens in comment upsert
1 parent b9f1fa0 commit 921a26e

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎.github/actions/post-coverage-comment/action.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ runs:
109109
${{ always() }}
110110
shell: 'bash'
111111
env:
112+
BOT_LOGIN: 'github-actions[bot]'
112113
GH_TOKEN: '${{ inputs.github_token }}'
113114
PR_NUMBER: '${{ github.event.pull_request.number }}'
114115
REPOSITORY: '${{ github.repository }}'

‎.github/scripts/upsert-bot-comment.sh‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
# path), never the no-op success reserved for a lookup that genuinely
1818
# found nothing.
1919
#
20+
# Set BOT_LOGIN when the token cannot access the /user endpoint, such as a
21+
# GitHub Actions integration token.
22+
#
2023
# Usage: upsert-bot-comment.sh <owner/repo> <issue-number> <marker> <body-file> [--update-only]
2124
# --update-only: PATCH an existing bot-authored marker comment if present;
2225
# succeed as a no-op when none exists (never POSTs). For
@@ -33,7 +36,8 @@ update_only="${5:-}"
3336
body="$(cat "${body_file}")"
3437

3538
for _attempt in 1 2 3; do
36-
if bot_login="$(gh api user --jq '.login')" \
39+
if bot_login="${BOT_LOGIN:-}" \
40+
&& { [ -n "${bot_login}" ] || bot_login="$(gh api user --jq '.login')"; } \
3741
&& [ -n "${bot_login}" ] \
3842
&& listing="$(gh api "repos/${repo}/issues/${number}/comments" \
3943
--method GET \

‎.github/scripts/upsert-bot-comment.test.mjs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const here = dirname(fileURLToPath(import.meta.url));
3131
const script = join(here, 'upsert-bot-comment.sh');
3232
const MARKER = '<!-- test-marker -->';
3333

34-
function run(scenario, { updateOnly = false } = {}) {
34+
function run(scenario, { updateOnly = false, botLogin = '' } = {}) {
3535
const dir = mkdtempSync(join(tmpdir(), 'upsert-bot-comment-'));
3636
const bin = join(dir, 'bin');
3737
mkdirSync(bin);
@@ -93,6 +93,7 @@ function run(scenario, { updateOnly = false } = {}) {
9393
PATH: `${bin}:${process.env.PATH}`,
9494
SCENARIO: scenario,
9595
CALLS: calls,
96+
BOT_LOGIN: botLogin,
9697
},
9798
},
9899
);
@@ -112,6 +113,13 @@ test('POSTs a fresh comment when no bot-authored marker exists', () => {
112113
assert.doesNotMatch(r.calls, /--method PATCH/);
113114
});
114115

116+
test('uses BOT_LOGIN when the token cannot access /user', () => {
117+
const r = run('user-fails', { botLogin: 'bot' });
118+
assert.equal(r.code, 0);
119+
assert.match(r.stdout, /posted new comment/);
120+
assert.doesNotMatch(r.calls, /api user/);
121+
});
122+
115123
test('PATCHes the existing bot-authored marker comment', () => {
116124
const r = run('existing-bot');
117125
assert.equal(r.code, 0);

0 commit comments

Comments
 (0)