11import { fail , warn , danger } from "danger"
2+ import Asana from "asana"
23
34export const prSize = async ( ) => {
45 // Warn when there is a big PR
@@ -8,10 +9,31 @@ export const prSize = async () => {
89}
910
1011export const internalLink = async ( ) => {
12+ const regex = / h t t p s : \/ \/ a p p .a s a n a .c o m \/ [ 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}
0 commit comments