@@ -4,7 +4,7 @@ const asana = require('asana');
4
4
5
5
async function asanaOperations (
6
6
asanaPAT ,
7
- projectId ,
7
+ projectName ,
8
8
taskId ,
9
9
sectionName ,
10
10
taskComment
@@ -14,20 +14,24 @@ async function asanaOperations(
14
14
defaultHeaders : { 'asana-enable' : 'new-sections,string_ids' } ,
15
15
logAsanaChangeWarnings : false
16
16
} ) . useAccessToken ( asanaPAT ) ;
17
- if ( sectionName ) {
18
- let project = await client . sections . findByProject ( projectId ) ;
19
- if ( project ) {
20
- let requiredSection = project . find ( data => data . name === sectionName ) ;
21
- if ( requiredSection ) {
22
- await client . sections . addTask ( requiredSection . gid , { task : taskId } ) ;
23
- core . info ( 'Moved to: ' + requiredSection . name ) ;
17
+
18
+ if ( sectionName && projectName ) {
19
+ let targetProject = await client . tasks . findById ( taskId )
20
+ . then ( task => task . projects . find ( project => project . name === projectName ) ) ;
21
+ if ( targetProject ) {
22
+ let targetSection = await client . sections . findByProject ( targetProject . gid )
23
+ . then ( sections => sections . find ( section => section . name === sectionName ) ) ;
24
+ if ( targetSection ) {
25
+ await client . sections . addTask ( targetSection . gid , { task : taskId } ) ;
26
+ core . info ( 'Moved to: ' + targetSection . name ) ;
24
27
} else {
25
28
core . error ( 'Asana section ' + sectionName + ' not found.' ) ;
26
29
}
27
30
} else {
28
- core . error ( 'Asana project with id ' + projectId + ' not found.' ) ;
31
+ core . error ( `This task does not exist in " ${ projectName } " project` ) ;
29
32
}
30
33
}
34
+
31
35
if ( taskComment ) {
32
36
await client . tasks . addComment ( taskId , {
33
37
text : taskComment
@@ -41,6 +45,7 @@ async function asanaOperations(
41
45
42
46
try {
43
47
const ASANA_PAT = core . getInput ( 'asana-pat' ) ,
48
+ PROJECT_NAME = core . getInput ( 'target-project' ) ,
44
49
SECTION_NAME = core . getInput ( 'target-section' ) ,
45
50
TRIGGER_PHRASE = core . getInput ( 'trigger-phrase' ) ,
46
51
TASK_COMMENT = core . getInput ( 'task-comment' ) ,
@@ -53,16 +58,15 @@ try {
53
58
parseAsanaURL = null ;
54
59
55
60
if ( ! ASANA_PAT ) {
56
- throw ( { message : " ASANA PAT Not Found!" } ) ;
61
+ throw ( { message : ' ASANA PAT Not Found!' } ) ;
57
62
}
58
63
if ( TASK_COMMENT ) {
59
64
taskComment = `${ TASK_COMMENT } ${ PULL_REQUEST . html_url } ` ;
60
65
}
61
66
while ( ( parseAsanaURL = REGEX . exec ( PULL_REQUEST . body ) ) !== null ) {
62
- let projectId = parseAsanaURL . groups . project ,
63
- taskId = parseAsanaURL . groups . task ;
64
- if ( projectId && taskId ) {
65
- asanaOperations ( ASANA_PAT , projectId , taskId , SECTION_NAME , taskComment ) ;
67
+ let taskId = parseAsanaURL . groups . task ;
68
+ if ( taskId ) {
69
+ asanaOperations ( ASANA_PAT , PROJECT_NAME , taskId , SECTION_NAME , taskComment ) ;
66
70
} else {
67
71
core . info ( 'Invalid Asana task URL after the trigger phrase' + TRIGGER_PHRASE ) ;
68
72
}
0 commit comments