Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
sibljon committed Sep 16, 2024
1 parent f0b9332 commit 257e007
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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).'
Expand Down
49 changes: 36 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
try {
core.info(`Triggered by event name: ${github.context.eventName}`);
Expand Down Expand Up @@ -123,6 +129,7 @@ export async function run(): Promise<void> {
}

let fieldValue = '';
let shouldSkipUpdatingStatusField = false;

if (
// this is expected to run upon PRs being opened or reopened
Expand Down Expand Up @@ -187,19 +194,35 @@ export async function run(): Promise<void> {
);

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;
Expand All @@ -215,7 +238,7 @@ export async function run(): Promise<void> {
fieldValue = statusFieldValueForMergedCommitToMain;
}

if (fieldValue) {
if (fieldValue && !shouldSkipUpdatingStatusField) {
await setStatusFieldvalueForAsanaTask({
fieldValue,
taskID,
Expand Down

0 comments on commit 257e007

Please sign in to comment.