All files sync.js

93.75% Statements 30/32
100% Branches 8/8
100% Functions 3/3
93.75% Lines 30/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 603x   3x 3x 3x 3x     61x 61x 61x 61x 265x         61x 61x 7x 7x 7x     54x       54x 54x   5x 5x 5x       49x 51x       49x 49x   49x 49x 49x   49x                 3x  
const core = require( '@actions/core' )
 
const { handleGHIssues }   = require( './ghHandling' )
const { handleJIRAData }   = require( './jiraHandling' )
const { handleJIRAUpdate } = require( './jiraUpdate' )
const { handleGHUpdate }   = require( './ghUpdate' )
 
async function syncJiraWithGH() {
    try {
        const useSubtaskMode = core.getInput( 'SUBTASK_MODE' ) === 'true'
        const useEpicMode    = core.getInput( 'EPIC_MODE' ) === 'true'
        const DEBUG          = core.getInput( 'DEBUG_MODE' ) === 'true'
                               ? ( messageToLog ) => ( console.log( `<<<<DEBUG----------------\n${ JSON.stringify(
                messageToLog ) }\n----------------DEBUG>>>>` ) )
                               : () => {}
        
        
        const issueEventTriggered = await handleGHIssues( useSubtaskMode, useEpicMode, DEBUG )
        if( !issueEventTriggered ) {
            console.log( `--! no change to be handled` )
            console.log( 'Ending Action' )
            return
        }
        
        const arrSubtasksOrIssuesToUpdate = await handleJIRAData( issueEventTriggered,
                                                                  useSubtaskMode,
                                                                  useEpicMode,
                                                                  DEBUG )
        DEBUG( arrSubtasksOrIssuesToUpdate )
        if( !arrSubtasksOrIssuesToUpdate
            || arrSubtasksOrIssuesToUpdate.length === 0 ) {
            console.log( `--! no subtask or issue to upgrade found at all` )
            console.log( 'Ending Action' )
            return
        }
        
        //we push all changes to JIRA
        for( const currentSubtaskOrIssue of arrSubtasksOrIssuesToUpdate ) {
            await handleJIRAUpdate( currentSubtaskOrIssue, issueEventTriggered, DEBUG )
        }
        
        //we sync back to GITHUB
        console.log( `Syncing back to GITHUB` )
        await handleGHUpdate( issueEventTriggered, arrSubtasksOrIssuesToUpdate, DEBUG )
        
        console.log( `==> action success` )
        console.log( `Action Finished` )
        core.setOutput( 'time', new Date().toTimeString() )
        
        return 0
    } catch ( error ) {
        core.setFailed( error.message )
        return 1
    }
}
 
 
 
module.exports.syncJiraWithGH = syncJiraWithGH