Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comment-key input #82

Merged
merged 7 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ inputs:
default: '{**/*.map,**/node_modules/**}'
cwd:
description: 'A custom working directory to execute the action in relative to repo root (defaults to .)'
comment-key:
description: 'Optional key to include in the bot comment to allow for multiple bundle calculations to be posted in separate comments.'

runs:
using: 'node12'
main: 'index.js'
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,13 @@ async function run(octokit, context, token) {
issue_number: pull_number
};

const commentKey = getInput('comment-key')

const comment = {
...commentInfo,
body:
markdownDiff +
'\n\n<a href="https://github.com/preactjs/compressed-size-action"><sub>compressed-size-action</sub></a>'
`\n\n<a href="https://github.com/preactjs/compressed-size-action"><sub>compressed-size-action${commentKey ? `::${commentKey}` : ''}</sub></a>`
};

if (context.eventName !== 'pull_request' && context.eventName !== 'pull_request_target') {
Expand All @@ -197,9 +199,10 @@ async function run(octokit, context, token) {
let commentId;
try {
const comments = (await octokit.issues.listComments(commentInfo)).data;
const commentRegExp = new RegExp(`<sub>[\s\n]*(compressed|gzip)-size-action${commentKey ? `::${commentKey}` : ''}`)
sarayourfriend marked this conversation as resolved.
Show resolved Hide resolved
for (let i = comments.length; i--; ) {
const c = comments[i];
if (c.user.type === 'Bot' && /<sub>[\s\n]*(compressed|gzip)-size-action/.test(c.body)) {
if (c.user.type === 'Bot' && commentRegExp.test(c.body)) {
commentId = c.id;
break;
}
Expand Down