async function getActionToDo()

in src/entrypoints/handle-results.ts [87:128]


async function getActionToDo(context: JunieExecutionContext): Promise<ActionType> {
    if (context.inputs.silentMode) {
        console.log('Silent mode enabled - no git operations will be performed');
        return ActionType.NOTHING;
    }
    const isNewBranch = process.env[OUTPUT_VARS.IS_NEW_BRANCH] === 'true';
    const workingBranch = process.env[OUTPUT_VARS.WORKING_BRANCH]!;
    const baseBranch = process.env[OUTPUT_VARS.BASE_BRANCH]!;
    const hasChangedFiles = await checkForChangedFiles();
    const hasUnpushedCommits = await checkForUnpushedCommits(isNewBranch, baseBranch);
    const isExternalIntegration = isJiraWorkflowDispatchEvent(context)
    const initCommentId = process.env[OUTPUT_VARS.INIT_COMMENT_ID];

    console.log(`Has changed files: ${hasChangedFiles}`);
    console.log(`Has unpushed commits: ${hasUnpushedCommits}`);
    console.log(`Init comment ID: ${initCommentId}`);
    console.log(`Is new branch: ${isNewBranch}`);
    console.log(`Is external integration: ${isExternalIntegration}`)
    console.log(`Working branch: ${workingBranch}`);

    let action: ActionType
    if ((hasChangedFiles || hasUnpushedCommits) && isNewBranch) {
        console.log('Changes or unpushed commits found in new branch - will create PR');
        action = ActionType.CREATE_PR;
    } else if (hasChangedFiles && !isNewBranch) {
        console.log('Changes found and working in existing branch - will commit directly');
        action = ActionType.COMMIT_CHANGES;
    } else if (hasUnpushedCommits) {
        console.log('No changes but has unpushed commits in existing branch - will push');
        action = ActionType.PUSH;
    } else if (initCommentId || isExternalIntegration) {
        console.log('No changes and no unpushed commits but has comment ID or it`s an external integration - will write comment');
        action = ActionType.WRITE_COMMENT;
    } else {
        console.log('No specific action matched - do nothing');
        action = ActionType.NOTHING;
    }

    console.log("Action to do:", action);
    core.setOutput(OUTPUT_VARS.ACTION_TO_DO, action);
    return action;
}