Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
style: format by prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Sep 19, 2022
1 parent 99a3925 commit 065074b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/index.js
README.md
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from '@actions/core';
import { run, newInputs, newEnvs } from './run';
import * as core from "@actions/core";
import { run, newInputs, newEnvs } from "./run";

const main = async (): Promise<void> => {
await run(newInputs(), newEnvs());
Expand Down
72 changes: 38 additions & 34 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as github from '@actions/github';
import * as core from '@actions/core';
import * as github from "@actions/github";
import * as core from "@actions/core";

type Envs = {
repoOwner: string;
Expand All @@ -12,26 +12,28 @@ type Envs = {

export function newEnvs(): Envs {
return {
repoOwner: process.env.GHA_REPOSITORY_OWNER || '',
repoName: process.env.GHA_REPOSITORY_NAME || '',
sha: process.env.GHA_COMMIT_STATUS_SHA || '',
githubToken: process.env.GITHUB_TOKEN || '',
repoOwner: process.env.GHA_REPOSITORY_OWNER || "",
repoName: process.env.GHA_REPOSITORY_NAME || "",
sha: process.env.GHA_COMMIT_STATUS_SHA || "",
githubToken: process.env.GITHUB_TOKEN || "",
isWorkflow: process.env.GHA_WORKFLOW_COMMIT_STATUS ? true : false,
targetURL: `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${process.env.GITHUB_REPOSITORY || ''}/actions/runs/${process.env.GITHUB_RUN_ID || ''}`,
targetURL: `${process.env.GITHUB_SERVER_URL || "https://github.com"}/${
process.env.GITHUB_REPOSITORY || ""
}/actions/runs/${process.env.GITHUB_RUN_ID || ""}`,
};
}

export function newInputs(): Inputs {
return {
repoOwner: core.getInput('repo_owner'),
repoName: core.getInput('repo_name'),
sha: core.getInput('sha'),
context: core.getInput('context'),
githubToken: core.getInput('github_token'),
state: getState(core.getInput('state', { required: true })),
needs: core.getInput('needs'),
updateCommitStatus: core.getBooleanInput('update_commit_status'),
targetURL: core.getInput('target_url'),
repoOwner: core.getInput("repo_owner"),
repoName: core.getInput("repo_name"),
sha: core.getInput("sha"),
context: core.getInput("context"),
githubToken: core.getInput("github_token"),
state: getState(core.getInput("state", { required: true })),
needs: core.getInput("needs"),
updateCommitStatus: core.getBooleanInput("update_commit_status"),
targetURL: core.getInput("target_url"),
};
}

Expand All @@ -41,7 +43,7 @@ type Inputs = {
sha: string;
context: string;
githubToken: string;
state: 'error' | 'failure' | 'pending' | 'success';
state: "error" | "failure" | "pending" | "success";
needs: string;
targetURL: string;
updateCommitStatus: boolean;
Expand Down Expand Up @@ -116,25 +118,27 @@ export const run = async (inputs: Inputs, envs: Envs): Promise<void> => {
});
};

function getState(state: string): 'error' | 'failure' | 'pending' | 'success' {
function getState(state: string): "error" | "failure" | "pending" | "success" {
switch (state) {
case 'error':
case 'failure':
case 'pending':
case 'success':
case "error":
case "failure":
case "pending":
case "success":
return state;
case 'cancelled':
return 'failure';
case "cancelled":
return "failure";
default:
throw `state ${state} is invalid`;
}
}

type Need = {
result: string
}
result: string;
};

function getStatusFromNeedsContext(needsStr: string): 'error' | 'failure' | 'pending' | 'success' {
function getStatusFromNeedsContext(
needsStr: string
): "error" | "failure" | "pending" | "success" {
// https://docs.github.com/en/actions/learn-github-actions/contexts#needs-context
// needs.<job_id>.result
const needs = JSON.parse(needsStr) as Record<string, Need>;
Expand All @@ -143,15 +147,15 @@ function getStatusFromNeedsContext(needsStr: string): 'error' | 'failure' | 'pen
const result = need.result;
switch (result) {
// success, failure, cancelled, or skipped
case 'success':
case 'skipped':
case 'failure':
return 'failure';
case 'cancelled':
return 'failure';
case "success":
case "skipped":
case "failure":
return "failure";
case "cancelled":
return "failure";
default:
throw `result ${result} is invalid`;
}
}
return 'success';
return "success";
}

0 comments on commit 065074b

Please sign in to comment.