Skip to content

Commit

Permalink
support multiple asana urls
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-ivanir committed Aug 25, 2024
1 parent ffb7b7e commit 7bf2271
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
26 changes: 15 additions & 11 deletions src/asana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,31 @@ export enum QaStatus {

const asanaPat = core.getInput('asana-pat');

export async function updatePrTaskStatus(
export async function updatePrTaskStatuses(
prDescription: string,
status: QaStatus
) {
const taskGid = extractTaskGid(prDescription);
await updateQaStatus(taskGid, status);
const taskIds = extractTaskIds(prDescription);
await Promise.all(taskIds.map(taskGid => updateQaStatus(taskGid, status)));
}

function extractTaskGid(prDescription: string) {
const asanaUrlRegex = /https:\/\/app\.asana\.com\/0\/.*/;
const taskUrl = prDescription.match(asanaUrlRegex)?.[0];
function extractTaskIds(prDescription: string) {
const asanaUrlRegex = /https:\/\/app\.asana\.com\/0\/.*/g;
const taskUrls = [...prDescription.matchAll(asanaUrlRegex)].map(
match => match[0]
);

if (!taskUrl) {
if (!taskUrls) {
throw new Error('Asana task URL not found in PR description');
}

const [_, __, taskGid] = [...taskUrl.matchAll(/\d+/g)].map(
match => match[0]
);
return taskUrls.map(taskUrl => {
const [_, __, taskGid] = [...taskUrl.matchAll(/\d+/g)].map(
match => match[0]
);

return taskGid;
return taskGid;
});
}

function updateQaStatus(taskGid: string, status: QaStatus) {
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from '@actions/core';
import { QaStatus, updatePrTaskStatus } from './asana';
import { QaStatus, updatePrTaskStatuses } from './asana';
import env from 'env-var';

import {
Expand All @@ -11,7 +11,7 @@ import {
async function handleSinglePr(status: QaStatus) {
try {
const description = getPrDescription();
await updatePrTaskStatus(description, status);
await updatePrTaskStatuses(description, status);
} catch (err: any) {
console.log(`PR number ${getPrNumber()} failed. ${err.message}`);
}
Expand All @@ -22,7 +22,7 @@ async function handleInProd() {
await Promise.all(
descriptions.map(async ({ description, prNumber }) => {
try {
await updatePrTaskStatus(description, QaStatus.Prod);
await updatePrTaskStatuses(description, QaStatus.Prod);
} catch (err: any) {
console.log(
`PR number ${prNumber} failed. ${err.message}. PR description:\n ${description}`
Expand Down

0 comments on commit 7bf2271

Please sign in to comment.