Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add always pass option #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ inputs:
description: 'List of allowed projects. The action will not add comments to tasks or subtasks of tasks in any of these projects. Only one of allowed-projects or blocked-projects can be specified.'
required: false
default: ''
always-pass:
description: 'If true, the action will always pass, even if it fails to add the pull request as an attachment to any tasks. To be used if failing to add the pull request as an attachment is not a critical failure.'
required: false
default: ''
outputs:
status:
description: 'status'
Expand Down
45 changes: 36 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14808,10 +14808,11 @@ exports.BOTH_PROJECT_LISTS_ARE_NOT_EMPTY = "Forbidden to specify allowed and blo
"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.BLOCKED_PROJECTS = exports.ALLOWED_PROJECTS = exports.ASANA_SECRET = void 0;
exports.ALWAYS_PASS = exports.BLOCKED_PROJECTS = exports.ALLOWED_PROJECTS = exports.ASANA_SECRET = void 0;
exports.ASANA_SECRET = "asana-secret";
exports.ALLOWED_PROJECTS = "allowed-projects";
exports.BLOCKED_PROJECTS = "blocked-projects";
exports.ALWAYS_PASS = "always-pass";


/***/ }),
Expand Down Expand Up @@ -14894,7 +14895,7 @@ const REQUESTS = __importStar(__nccwpck_require__(9339));
const allowedProjects = utils.getProjectsFromInput(INPUTS.ALLOWED_PROJECTS);
const blockedProjects = utils.getProjectsFromInput(INPUTS.BLOCKED_PROJECTS);
const run = () => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d;
try {
utils.validateTrigger(github_1.context.eventName);
utils.validateProjectLists(allowedProjects, blockedProjects);
Expand All @@ -14910,12 +14911,18 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
(0, core_1.setOutput)("status", result.status);
}
catch (error) {
if (utils.isAxiosError(error))
console.log(((_e = error.response) === null || _e === void 0 ? void 0 : _e.data) || "Unknown error");
if (error instanceof Error)
(0, core_1.setFailed)(error.message);
else
(0, core_1.setFailed)("Unknown error");
const errorInfo = utils.getErrorInfo(error);
console.log(`Failed with message: ${errorInfo.message}`);
console.log(`Failed with status: ${errorInfo.status}`);
(0, core_1.setOutput)("status", errorInfo.status);
if (errorInfo.response) {
console.log('Response data:', errorInfo.response.data);
}
if (utils.shouldPass()) {
console.log('Always pass is enabled, skipping failure');
return;
}
(0, core_1.setFailed)(errorInfo.message);
}
});
run();
Expand Down Expand Up @@ -15003,10 +15010,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isAxiosError = exports.validateProjectLists = exports.validateTrigger = exports.getProjectsFromInput = void 0;
exports.getErrorInfo = exports.shouldPass = exports.isAxiosError = exports.validateProjectLists = exports.validateTrigger = exports.getProjectsFromInput = void 0;
const core_1 = __nccwpck_require__(2186);
const ERRORS = __importStar(__nccwpck_require__(1231));
const TRIGGERS = __importStar(__nccwpck_require__(2160));
const inputs_1 = __nccwpck_require__(9579);
const getProjectsFromInput = (inputName) => {
const projects = (0, core_1.getInput)(inputName);
if (!projects)
Expand All @@ -15026,6 +15034,25 @@ const validateProjectLists = (allowedProjects, blockedProjects) => {
exports.validateProjectLists = validateProjectLists;
const isAxiosError = (e) => e.isAxiosError;
exports.isAxiosError = isAxiosError;
const shouldPass = () => {
return (0, core_1.getInput)(inputs_1.ALWAYS_PASS) === "true";
};
exports.shouldPass = shouldPass;
const getErrorInfo = (err) => {
const errorInfo = {
message: "Unknown error",
status: 500,
};
if (err instanceof Error) {
errorInfo.message = err.message;
}
if ((0, exports.isAxiosError)(err) && err.response) {
errorInfo.response = err.response;
errorInfo.status = err.response.status;
}
return errorInfo;
};
exports.getErrorInfo = getErrorInfo;


/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "tsc",
"test": "jest",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix",
"package": "ncc build --source-map --license licenses.txt",
"test:coverage": "jest --collectCoverage=true"
},
Expand Down
1 change: 1 addition & 0 deletions src/constants/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const ASANA_SECRET = "asana-secret";
export const ALLOWED_PROJECTS = "allowed-projects";
export const BLOCKED_PROJECTS = "blocked-projects";
export const ALWAYS_PASS = "always-pass";
17 changes: 14 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ const run = async () => {
console.log(result.data);
setOutput("status", result.status);
} catch (error) {
if (utils.isAxiosError(error)) console.log(error.response?.data || "Unknown error");
if (error instanceof Error) setFailed(error.message);
else setFailed("Unknown error")
const errorInfo = utils.getErrorInfo(error);
console.log(`Failed with message: ${errorInfo.message}`);
console.log(`Failed with status: ${errorInfo.status}`);
setOutput("status", errorInfo.status);
if (errorInfo.response) {
console.log('Response data:', errorInfo.response.data);
}

if (utils.shouldPass()) {
console.log('Always pass is enabled, skipping failure');
return;
}

setFailed(errorInfo.message);
}
};

Expand Down
28 changes: 27 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { AxiosError } from "axios";
import { AxiosError, AxiosResponse } from "axios";
import { getInput } from "@actions/core";
import * as ERRORS from "../constants/errors";
import * as TRIGGERS from "../constants/triggers";
import { ALWAYS_PASS } from "../constants/inputs";

export const getProjectsFromInput = (inputName: string): String[] => {
const projects = getInput(inputName);
Expand All @@ -24,3 +25,28 @@ export const validateProjectLists = (
};

export const isAxiosError = (e: any): e is AxiosError => e.isAxiosError;

export const shouldPass = (): boolean => {
return getInput(ALWAYS_PASS) === "true";
};

interface ErrorInfo {
message: string;
status: number;
response?: AxiosResponse;
}
export const getErrorInfo = (err: any): ErrorInfo => {
const errorInfo: ErrorInfo = {
message: "Unknown error",
status: 500,
};
if (err instanceof Error) {
errorInfo.message = err.message;
}
if (isAxiosError(err) && err.response) {
errorInfo.response = err.response;
errorInfo.status = err.response.status;
}

return errorInfo;
};