Skip to content

Commit

Permalink
Remove string trimmings
Browse files Browse the repository at this point in the history
  • Loading branch information
aldwyn-acn committed Jun 30, 2020
1 parent a997377 commit 94ebe15
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/post/index.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { setFailed, getInput, info } from "@actions/core";
import { formatAndNotify } from "./utils";

try {
const showCardOnStart =
getInput(`show-on-start`).trim().toLowerCase() == "true";
const showCardOnStart = getInput(`show-on-start`).toLowerCase() == "true";
if (showCardOnStart) {
formatAndNotify("start");
} else {
info(`Configured to not show card upon job start.`);
info("Configured to not show card upon job start.");
}
} catch (error) {
setFailed(error.message);
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/compact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function formatCompactLayout(

// Set environment name
const environment = getInput("environment");
if (environment.trim() !== "") {
if (environment !== "") {
labels += ` \`ENV:${environment.toUpperCase()}\``;
}

Expand All @@ -33,5 +33,6 @@ export function formatCompactLayout(
`${labels}   CI [#${process.env.GITHUB_RUN_NUMBER}](${runLink}) ` +
`(commit [${shortSha}](${commit.data.html_url})) on [${process.env.GITHUB_REPOSITORY}](${repoUrl}) ` +
`by [@${author.login}](${author.html_url})`;

return webhookBody;
}
12 changes: 5 additions & 7 deletions src/layouts/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Octokit } from "@octokit/rest";
import { getInput, warning, info } from "@actions/core";
import yaml from "yaml";

import { escapeMarkdownTokens, getDefaultActions } from "../utils";
import { escapeMarkdownTokens, renderActions } from "../utils";
import { Fact, PotentialAction } from "../models";
import { formatCozyLayout } from "./cozy";

Expand Down Expand Up @@ -46,7 +46,7 @@ export function formatCompleteLayout(

// for complete layout, just replace activityText with potentialAction
section.activityText = undefined;
section.potentialAction = getDefaultActions(
section.potentialAction = renderActions(
`${repoUrl}/actions/runs/${process.env.GITHUB_RUN_ID}`,
commit.data.html_url
);
Expand All @@ -73,7 +73,7 @@ export function formatCompleteLayout(

// Set custom facts
const customFacts = getInput("custom-facts");
if (customFacts) {
if (customFacts && customFacts.toLowerCase() !== "null") {
try {
let customFactsCounter = 0;
const customFactsList = yaml.parse(customFacts);
Expand All @@ -93,7 +93,7 @@ export function formatCompleteLayout(

// Set environment name
const environment = getInput("environment");
if (environment.trim() !== "") {
if (environment !== "") {
section.facts.splice(
1,
0,
Expand All @@ -102,9 +102,7 @@ export function formatCompleteLayout(
}

// Set list of files
const includeFiles =
getInput("include-files").trim().toLowerCase() === "true";
if (includeFiles) {
if (getInput("include-files").toLowerCase() === "true") {
const allowedFileLen = getInput("allowed-file-len").toLowerCase();
const allowedFileLenParsed = parseInt(
allowedFileLen === "" ? "7" : allowedFileLen
Expand Down
7 changes: 4 additions & 3 deletions src/layouts/cozy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getInput } from "@actions/core";

import { WebhookBody } from "../models";
import { CONCLUSION_THEMES } from "../constants";
import { getDefaultActions } from "../utils";
import { renderActions } from "../utils";

export const OCTOCAT_LOGO_URL =
"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png";
Expand All @@ -31,15 +31,15 @@ export function formatCozyLayout(

// Set environment name
const environment = getInput("environment");
if (environment.trim() !== "") {
if (environment !== "") {
labels += ` \`ENV:${environment.toUpperCase()}\``;
}

// Set themeColor
webhookBody.themeColor = CONCLUSION_THEMES[conclusion] || "957DAD";

// Get potential actions
const actions = getDefaultActions(
const actions = renderActions(
`${repoUrl}/actions/runs/${process.env.GITHUB_RUN_ID}`,
commit.data.html_url
);
Expand All @@ -59,5 +59,6 @@ export function formatCozyLayout(
activityText: `${labels}${actionsConcat}`,
},
];

return webhookBody;
}
8 changes: 4 additions & 4 deletions src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { setFailed, info, getInput } from "@actions/core";
import { formatAndNotify, getWorkflowRunStatus } from "./utils";

try {
// setTimeout to give time for Github API to show up the final conclusion
setTimeout(async () => {
const showCardOnExit =
getInput(`show-on-exit`).trim().toLowerCase() === "true";
const showCardOnExit = getInput(`show-on-exit`).toLowerCase() === "true";
const showCardOnFailure =
getInput(`show-on-failure`).trim().toLowerCase() === "true";
getInput(`show-on-failure`).toLowerCase() === "true";

const workflowRunStatus = await getWorkflowRunStatus();
if (
Expand All @@ -19,7 +19,7 @@ try {
workflowRunStatus.elapsedSeconds
);
} else {
info(`Configured to not show card upon job exit.`);
info("Configured to not show card upon job exit.");
}
}, 2000);
} catch (error) {
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,22 @@ export async function getWorkflowRunStatus() {
};
}

export function getDefaultActions(statusUrl: string, diffUrl: string) {
export function renderActions(statusUrl: string, diffUrl: string) {
const actions: PotentialAction[] = [];
if (getInput("enable-view-status-action").trim().toLowerCase() === "true") {
if (getInput("enable-view-status-action").toLowerCase() === "true") {
actions.push(
new PotentialAction(getInput("view-status-action-text"), [statusUrl])
);
}
if (getInput("enable-review-diffs-action").trim().toLowerCase() === "true") {
if (getInput("enable-review-diffs-action").toLowerCase() === "true") {
actions.push(
new PotentialAction(getInput("review-diffs-action-text"), [diffUrl])
);
}

// Set custom actions
const customActions = getInput("custom-actions");
if (customActions) {
if (customActions && customActions.toLowerCase() !== "null") {
try {
let customActionsCounter = 0;
const customActionsList = yaml.parse(customActions);
Expand Down

0 comments on commit 94ebe15

Please sign in to comment.