Skip to content

Commit cd8f06e

Browse files
committed
Check Asana task for project assignment
1 parent 3e8f3a4 commit cd8f06e

File tree

3 files changed

+222
-5
lines changed

3 files changed

+222
-5
lines changed

org/allPRs.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {fail, warn, danger} from "danger"
2+
import Asana from "asana"
23

34
export const prSize = async () => {
45
// Warn when there is a big PR
@@ -8,10 +9,31 @@ export const prSize = async () => {
89
}
910

1011
export const internalLink = async () => {
12+
const regex = /https:\/\/app.asana.com\/[0-9]\/[0-9]*\/([0-9]*)/
13+
1114
// Warn when link to internal task is missing
1215
for (let bodyLine of danger.github.pr.body.toLowerCase().split(/\n/)) {
13-
if (bodyLine.includes("task/issue url:") && (!bodyLine.includes("app.asana.com"))) {
14-
fail("Please, don't forget to add a link to the internal task");
16+
if (bodyLine.includes("task/issue url:")) {
17+
18+
let match = bodyLine.match(regex);
19+
if (!match || match.length < 2) {
20+
fail("Please, don't forget to add a link to the internal task");
21+
}
22+
23+
let taskGID = match[1];
24+
25+
if (process.env.ASANA_ACCESS_TOKEN && process.env.ASANA_PROJECT_ID && process.env.ASANA_PROJECT_NAME) {
26+
let client = Asana.ApiClient.instance;
27+
let token = client.authentications['token'];
28+
token.accessToken = process.env.ASANA_ACCESS_TOKEN;
29+
30+
let tasksApiInstance = new Asana.TasksApi();
31+
let result = await tasksApiInstance.getTask(taskGID, { 'opt_fields': 'projects' });
32+
let projects = result.data.projects.map( (p) => p.gid );
33+
if (!projects.includes(process.env.ASANA_PROJECT_ID)) {
34+
fail(`Please ensure that the Asana task is added to ${process.env.ASANA_PROJECT_NAME} project`);
35+
}
36+
}
1537
}
1638
}
1739
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"scripts": {
44
"test": "jest"
55
},
6-
76
"devDependencies": {
87
"@babel/cli": "^7.21.0",
98
"@babel/core": "^7.21.4",
@@ -32,6 +31,7 @@
3231
]
3332
},
3433
"dependencies": {
34+
"asana": "^3.0.1",
3535
"github-webhook-event-types": "^1.2.1"
3636
}
3737
}

0 commit comments

Comments
 (0)