From 614e95c78118a55b761e7d5b9b732ab1e3689d77 Mon Sep 17 00:00:00 2001 From: Mahor Foruzesh Date: Wed, 29 May 2024 14:06:26 +0000 Subject: [PATCH 1/2] Add sendComment input --- README.md | 6 ++++++ action.yml | 4 ++++ src/index.ts | 39 ++++++++++++++++++++++----------------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b1a7f35..b3765bf 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,12 @@ Optional. The name of the label, defaults to lfs-detected! Optional. The color of the label, defaults to ff1493. +### `sendComment` + +Optional. If set to false, disables sending comments. + +Default `true`. + ## Outputs ### `lfsFiles` diff --git a/action.yml b/action.yml index 9a45dcb..7ed8a64 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,10 @@ inputs: required: false default: ff1493 description: The color of the label, defaults to ff1493 + sendComment: + required: false + default: true + description: Disable sending comments outputs: lfsFiles: # output will be available to future steps description: "Array of possible detected large file(s)" diff --git a/src/index.ts b/src/index.ts index a3f7935..4fd2235 100644 --- a/src/index.ts +++ b/src/index.ts @@ -87,23 +87,28 @@ async function run() { if (lsfFiles.length > 0) { core.info('Detected file(s) that should be in LFS: '); core.info(lsfFiles.join('\n')); - - const body = getCommentBody( - largeFiles, - accidentallyCheckedInLsfFiles, - fsl - ); - - await Promise.all([ - octokit.rest.issues.addLabels({ - ...issueBaseProps, - labels: [labelName], - }), - octokit.rest.issues.createComment({ - ...issueBaseProps, - body, - }), - ]); + + const send_comment = core.getInput('sendComment'); + if (send_comment === "" || send_comment === "true") { + const body = getCommentBody( + largeFiles, + accidentallyCheckedInLsfFiles, + fsl + ); + + await Promise.all([ + octokit.rest.issues.addLabels({ + ...issueBaseProps, + labels: [labelName], + }), + octokit.rest.issues.createComment({ + ...issueBaseProps, + body, + }), + ]); + } else if (send_comment !== "false") { + throw new Error("sendComment must be either true or false"); + } core.setOutput('lfsFiles', lsfFiles); core.setFailed( From 50cd1ec142346bd842df65d885dc40f21a931224 Mon Sep 17 00:00:00 2001 From: Mahor Foruzesh Date: Wed, 29 May 2024 14:31:54 +0000 Subject: [PATCH 2/2] Fix addLabel --- src/index.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4fd2235..8b679fe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -87,6 +87,18 @@ async function run() { if (lsfFiles.length > 0) { core.info('Detected file(s) that should be in LFS: '); core.info(lsfFiles.join('\n')); + + core.setOutput('lfsFiles', lsfFiles); + core.setFailed( + 'Large file(s) detected! Setting PR status to failed. Consider using git-lfs to track the LFS file(s)' + ); + + await Promise.all([ + octokit.rest.issues.addLabels({ + ...issueBaseProps, + labels: [labelName], + }), + ]); const send_comment = core.getInput('sendComment'); if (send_comment === "" || send_comment === "true") { @@ -97,10 +109,6 @@ async function run() { ); await Promise.all([ - octokit.rest.issues.addLabels({ - ...issueBaseProps, - labels: [labelName], - }), octokit.rest.issues.createComment({ ...issueBaseProps, body, @@ -109,11 +117,6 @@ async function run() { } else if (send_comment !== "false") { throw new Error("sendComment must be either true or false"); } - - core.setOutput('lfsFiles', lsfFiles); - core.setFailed( - 'Large file(s) detected! Setting PR status to failed. Consider using git-lfs to track the LFS file(s)' - ); } else { core.info('No large file(s) detected...');