diff --git a/action.yml b/action.yml index a590703..13dff08 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,10 @@ inputs: required: false description: 'if specified, the statusFieldName will be set to the enum of this value when a PR is merged into main (or any other commit is pushed to main, for that matter). This should be the name of the enum value, as it appears in the Asana UI (as opposed to the GID or some other identifier).' default: '' + dontUpdateStatusFieldWhenReviewIsApprovedIfStatusFieldValueIsCurrentlyOneOf: + required: false + description: 'A comma-separated list of status field values. If the status field is currently set to one of these values, the status field will not be updated when a PR is approved.' + default: '' statusFieldValueWhenPRReadyForReviewIsApproved: required: false description: 'if specified, the statusFieldName will be set to the enum of this value when a PR is approved and ready for review. This should be the name of the enum value, as it appears in the Asana UI (as opposed to the GID or some other identifier).' diff --git a/src/main.ts b/src/main.ts index b5ac3d0..1ae6dff 100644 --- a/src/main.ts +++ b/src/main.ts @@ -41,6 +41,12 @@ const setStatusFieldvalueForAsanaTask = async ({ return { didSetStatus: true }; }; +const dontUpdateStatusFieldWhenReviewIsApprovedIfStatusFieldValueIsCurrentlyOneOf: string[] = core + .getInput('dontUpdateStatusFieldWhenReviewIsApprovedIfStatusFieldValueIsCurrentlyOneOf') + .split(',') + .map((value) => value.trim()) + .filter(Boolean); + export async function run(): Promise { try { core.info(`Triggered by event name: ${github.context.eventName}`); @@ -123,6 +129,7 @@ export async function run(): Promise { } let fieldValue = ''; + let shouldSkipUpdatingStatusField = false; if ( // this is expected to run upon PRs being opened or reopened @@ -187,19 +194,35 @@ export async function run(): Promise { ); if (isApproved && isReadyForReview) { - if ( - skipSettingStatusForPRReadyForReviewIsApprovedIfLabeledWith.length > 0 && - !hasSkipSettingStatusForPRApprovedLabel - ) { + core.info(`🔍 Checking if current status field value allows update`); + + // Fetch the current status field value + const currentStatusFieldValue = statusCustomField.display_value || ''; + + core.info(`🔍 Current status field value: "${currentStatusFieldValue}"`); + + // Check if the current value is in the skip list + shouldSkipUpdatingStatusField = + dontUpdateStatusFieldWhenReviewIsApprovedIfStatusFieldValueIsCurrentlyOneOf.includes( + currentStatusFieldValue + ); + + if (shouldSkipUpdatingStatusField) { + core.info( + `🛑 Current status field value "${currentStatusFieldValue}" is in the skip list. Skipping status update.` + ); + } else { fieldValue = statusFieldValueWhenPRReadyForReviewIsApproved; - } - if (labelToApplyToPRWhenApproved) { - await octokit.issues.addLabels({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, - issue_number: prNumber, - labels: [labelToApplyToPRWhenApproved], - }); + + // Apply label if specified + if (labelToApplyToPRWhenApproved) { + await octokit.issues.addLabels({ + owner: github.context.repo.owner, + repo: github.context.repo.repo, + issue_number: prNumber, + labels: [labelToApplyToPRWhenApproved], + }); + } } } else if (pr?.draft && statusFieldValueWhenDraftPRIsOpen) { fieldValue = statusFieldValueWhenDraftPRIsOpen; @@ -215,7 +238,7 @@ export async function run(): Promise { fieldValue = statusFieldValueForMergedCommitToMain; } - if (fieldValue) { + if (fieldValue && !shouldSkipUpdatingStatusField) { await setStatusFieldvalueForAsanaTask({ fieldValue, taskID,