From b9b1e2c74a10a3f1615c975ff842bfc0113ad97c Mon Sep 17 00:00:00 2001 From: Yethal <26117918+Yethal@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:56:32 +0200 Subject: [PATCH 1/2] Support custom owner and repo --- action.yml | 6 ++++++ src/main.ts | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 29d39034..2b6e7b23 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,12 @@ inputs: create_if_not_exists: description: 'Whether a comment should be created even if comment_tag is not found.' default: 'true' + owner: + description: 'Repository owner if different than one action is running in' + required: false + repo: + description: 'Repository name if different than one action is running in' + required: false runs: using: 'node20' main: 'lib/index.js' diff --git a/src/main.ts b/src/main.ts index 62e1ee81..321c934b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,6 +29,8 @@ async function run() { } const context = github.context; + const owner: string = core.getInput('owner') || github.context.repo.owner; + const repo: string = core.getInput('repo') || github.context.repo.repo; const issue_number = parseInt(pr_number) || context.payload.pull_request?.number || context.payload.issue?.number; const octokit = github.getOctokit(github_token); @@ -47,7 +49,8 @@ async function run() { await Promise.allSettled( validReactions.map(async (content) => { await octokit.rest.reactions.createForIssueComment({ - ...context.repo, + owner, + repo, comment_id, content, }); @@ -130,7 +133,8 @@ async function run() { >; let comment: ListCommentsResponseDataType[0] | undefined; for await (const { data: comments } of octokit.paginate.iterator(octokit.rest.issues.listComments, { - ...context.repo, + owner, + repo, issue_number, })) { comment = comments.find((comment) => comment?.body?.includes(comment_tag_pattern)); @@ -140,19 +144,22 @@ async function run() { if (comment) { if (mode === 'upsert') { await updateComment({ - ...context.repo, + owner, + repo, comment_id: comment.id, body, }); return; } else if (mode === 'recreate') { await deleteComment({ - ...context.repo, + owner, + repo, comment_id: comment.id, }); await createComment({ - ...context.repo, + owner, + repo, issue_number, body, }); @@ -174,7 +181,8 @@ async function run() { } await createComment({ - ...context.repo, + owner, + repo, issue_number, body, }); From 049d770690a0393026312ec37fc2306fa05e3167 Mon Sep 17 00:00:00 2001 From: Yethal <26117918+Yethal@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:59:59 +0200 Subject: [PATCH 2/2] Grab owner/repo from context const --- src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 321c934b..215891ff 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,8 +29,8 @@ async function run() { } const context = github.context; - const owner: string = core.getInput('owner') || github.context.repo.owner; - const repo: string = core.getInput('repo') || github.context.repo.repo; + const owner: string = core.getInput('owner') || context.repo.owner; + const repo: string = core.getInput('repo') || context.repo.repo; const issue_number = parseInt(pr_number) || context.payload.pull_request?.number || context.payload.issue?.number; const octokit = github.getOctokit(github_token);