Skip to content

Commit

Permalink
cleanup checkEventTrigger method
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Bildner committed Sep 6, 2022
1 parent 70a4b97 commit 3c0b9bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const GithubTaskSystem_1 = __nccwpck_require__(1580);
const TaskSystem_1 = __nccwpck_require__(2963);
const core_1 = __nccwpck_require__(2186);
exports["default"] = () => __awaiter(void 0, void 0, void 0, function* () {
checkEventTrigger();
if (!checkEventTrigger())
return;
const taskSystem = getTaskSystem();
if (!taskSystem)
return;
Expand Down Expand Up @@ -58,14 +59,15 @@ function checkEventTrigger() {
if (ArgumentContext_1.argumentContext.importAll) {
if (github_1.context.eventName !== 'workflow_dispatch') {
(0, core_1.setFailed)('importAll can only be used on trigger workflow_dispatch');
return;
return false;
}
(0, core_1.info)('Import all mode. Adding all TODOs from codebase which were not created yet');
}
else if (github_1.context.eventName !== 'push') {
(0, core_1.setFailed)('Action can only be used on trigger push or in manual and importAll mode');
return;
return false;
}
return true;
}
function getTaskSystem() {
switch (ArgumentContext_1.argumentContext.taskSystem) {
Expand Down
16 changes: 10 additions & 6 deletions src/ActionMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {debug, error, info, setFailed, warning} from "@actions/core";

export default async () => {

checkEventTrigger();
if (!checkEventTrigger())
return

const taskSystem = getTaskSystem();

Expand Down Expand Up @@ -54,17 +55,20 @@ export default async () => {
await handleTodos(toAddReference, taskSystem.addReferenceTodo);
}

function checkEventTrigger() {
function checkEventTrigger() : boolean {
if (argumentContext.importAll) {
if (github.eventName !== 'workflow_dispatch') {
if (github.eventName !== 'workflow_dispatch'){
setFailed('importAll can only be used on trigger workflow_dispatch')
return
return false
}

info('Import all mode. Adding all TODOs from codebase which were not created yet')
} else if (github.eventName !== 'push') {
} else if (github.eventName !== 'push'){
setFailed('Action can only be used on trigger push or in manual and importAll mode')
return
return false
}

return true
}

function getTaskSystem(): ITaskSystem | undefined {
Expand Down

0 comments on commit 3c0b9bf

Please sign in to comment.