Skip to content

Commit 3ea37a4

Browse files
authored
Merge pull request #4217 from github/mario-campos/warn-on-changelog-write
Add `post-comment` Action
2 parents 592d162 + 05870b6 commit 3ea37a4

4 files changed

Lines changed: 576 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: "Post comment"
2+
description: "Create or update a sticky PR comment identified by a caller-provided marker."
3+
inputs:
4+
marker:
5+
description: >
6+
Non-empty plain-text identifier for the comment. Use a unique, stable value
7+
for each distinct comment; it is automatically wrapped in a hidden HTML comment.
8+
required: true
9+
body:
10+
description: "Full comment markdown."
11+
required: true
12+
update-only:
13+
description: Do nothing if no comment with the specified marker exists.
14+
required: false
15+
default: "false"
16+
issue-id:
17+
description: >
18+
The issue or pull request number to post/update the comment on.
19+
Defaults to the current pull request if not provided.
20+
required: false
21+
token:
22+
description: "The GitHub token to authenticate with."
23+
required: true
24+
runs:
25+
using: composite
26+
steps:
27+
- name: Post comment
28+
shell: bash
29+
env:
30+
BODY: ${{ inputs.body }}
31+
MARKER: ${{ inputs.marker }}
32+
UPDATE_ONLY: ${{ case(inputs.update-only == 'true', '--update-only', '') }}
33+
GH_TOKEN: ${{ inputs.token }}
34+
ISSUE_ID: ${{ inputs.issue-id || github.event.pull_request.number }}
35+
run: |
36+
npx tsx ./pr-checks/post-comment.ts \
37+
--body "$BODY" \
38+
--marker "$MARKER" \
39+
$UPDATE_ONLY \
40+
--issue-id "$ISSUE_ID" \
41+
--repository "$GITHUB_REPOSITORY"

‎pr-checks/api-client.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ export function getApiClient(token: string): ApiClient {
88
const opts = githubUtils.getOctokitOptions(token);
99
return new githubUtils.GitHub(opts);
1010
}
11+
12+
/** Resolves the GitHub API token to use, from `GH_TOKEN` or `GITHUB_TOKEN`. */
13+
export function resolveToken(env: NodeJS.ProcessEnv): string {
14+
const token = env.GH_TOKEN?.trim() || env.GITHUB_TOKEN?.trim();
15+
if (!token) {
16+
throw new Error(
17+
"Missing authentication token. Set GH_TOKEN or GITHUB_TOKEN.",
18+
);
19+
}
20+
return token;
21+
}

0 commit comments

Comments
 (0)