@@ -4,9 +4,8 @@ const asana = require('asana');
4
4
5
5
async function asanaOperations (
6
6
asanaPAT ,
7
- projectName ,
7
+ targets ,
8
8
taskId ,
9
- sectionName ,
10
9
taskComment
11
10
) {
12
11
try {
@@ -15,22 +14,23 @@ async function asanaOperations(
15
14
logAsanaChangeWarnings : false
16
15
} ) . useAccessToken ( asanaPAT ) ;
17
16
18
- if ( sectionName && projectName ) {
19
- let targetProject = await client . tasks . findById ( taskId )
20
- . then ( task => task . projects . find ( project => project . name === projectName ) ) ;
17
+ const task = await client . tasks . findById ( taskId ) ;
18
+
19
+ targets . forEach ( async target => {
20
+ let targetProject = task . projects . find ( project => project . name === target . project ) ;
21
21
if ( targetProject ) {
22
22
let targetSection = await client . sections . findByProject ( targetProject . gid )
23
- . then ( sections => sections . find ( section => section . name === sectionName ) ) ;
23
+ . then ( sections => sections . find ( section => section . name === target . section ) ) ;
24
24
if ( targetSection ) {
25
25
await client . sections . addTask ( targetSection . gid , { task : taskId } ) ;
26
- core . info ( ' Moved to: ' + targetSection . name ) ;
26
+ core . info ( ` Moved to: ${ target . project } / ${ target . section } ` ) ;
27
27
} else {
28
- core . error ( ' Asana section ' + sectionName + ' not found.' ) ;
28
+ core . error ( ` Asana section ${ target . section } not found.` ) ;
29
29
}
30
30
} else {
31
- core . error ( `This task does not exist in "${ projectName } " project` ) ;
31
+ core . info ( `This task does not exist in "${ target . project } " project` ) ;
32
32
}
33
- }
33
+ } ) ;
34
34
35
35
if ( taskComment ) {
36
36
await client . tasks . addComment ( taskId , {
@@ -45,8 +45,7 @@ async function asanaOperations(
45
45
46
46
try {
47
47
const ASANA_PAT = core . getInput ( 'asana-pat' ) ,
48
- PROJECT_NAME = core . getInput ( 'target-project' ) ,
49
- SECTION_NAME = core . getInput ( 'target-section' ) ,
48
+ TARGETS = core . getInput ( 'targets' ) ,
50
49
TRIGGER_PHRASE = core . getInput ( 'trigger-phrase' ) ,
51
50
TASK_COMMENT = core . getInput ( 'task-comment' ) ,
52
51
PULL_REQUEST = github . context . payload . pull_request ,
55
54
'g'
56
55
) ;
57
56
let taskComment = null ,
57
+ targets = TARGETS ? JSON . parse ( TARGETS ) : [ ] ,
58
58
parseAsanaURL = null ;
59
59
60
60
if ( ! ASANA_PAT ) {
66
66
while ( ( parseAsanaURL = REGEX . exec ( PULL_REQUEST . body ) ) !== null ) {
67
67
let taskId = parseAsanaURL . groups . task ;
68
68
if ( taskId ) {
69
- asanaOperations ( ASANA_PAT , PROJECT_NAME , taskId , SECTION_NAME , taskComment ) ;
69
+ asanaOperations ( ASANA_PAT , targets , taskId , taskComment ) ;
70
70
} else {
71
- core . info ( ' Invalid Asana task URL after the trigger phrase' + TRIGGER_PHRASE ) ;
71
+ core . info ( ` Invalid Asana task URL after the trigger phrase ${ TRIGGER_PHRASE } ` ) ;
72
72
}
73
73
}
74
74
} catch ( error ) {
0 commit comments