Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improves input parameter parser
- Loading branch information
Showing
6 changed files
with
86 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
name: 'Clean Workflow Action' | ||
name: "Clean Workflow Action" | ||
|
||
description: 'Clean workflow run logs based on configuration' | ||
description: "Clean workflow run logs based on configuration" | ||
|
||
author: igor.js | ||
author: igorjs | ||
|
||
branding: | ||
icon: 'chevron-right' | ||
color: 'yellow' | ||
icon: "chevron-right" | ||
color: "yellow" | ||
|
||
inputs: | ||
token: | ||
description: 'The token to use to access the GitHub API' | ||
required: true | ||
owner: | ||
description: 'The owner of the repository' | ||
required: true | ||
repo: | ||
description: 'The name of the repository' | ||
description: "The token to use to access the GitHub API" | ||
required: true | ||
days_old: | ||
description: 'The amount of days old to delete' | ||
description: "The amount of days old to delete" | ||
required: false | ||
default: '7' | ||
default: "7" | ||
|
||
outputs: | ||
result: | ||
description: 'The number of workflows deleted' | ||
description: "The number of workflows deleted" | ||
|
||
runs: | ||
using: 'node12' | ||
main: 'dist/index.js' | ||
using: "node16" | ||
main: "dist/index.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getInput } from "@actions/core"; | ||
|
||
function throwError(message) { | ||
throw new Error(message); | ||
} | ||
|
||
export function getToken() { | ||
const value = getInput("token", { required: true, trimWhitespace: true }); | ||
|
||
return value || throwError("[Invalid Parameter] A token must be provided"); | ||
} | ||
|
||
export function getOwner() { | ||
const value = getInput("owner", { required: false, trimWhitespace: true }); | ||
|
||
return value || process.env["GITHUB_REPOSITORY_OWNER"]; | ||
} | ||
|
||
export function getRepo() { | ||
const value = getInput("repo", { required: false, trimWhitespace: true }); | ||
const currentRepository = process.env["GITHUB_REPOSITORY"]; | ||
|
||
return value || currentRepository.slice(currentRepository.indexOf("/") + 1); | ||
} | ||
|
||
export function getDaysOld() { | ||
const value = getInput("days_old", { required: false, trimWhitespace: true }); | ||
const numberValue = Number(value); | ||
|
||
if (Number.isSafeInteger(numberValue) && !Number.isNaN(numberValue)) { | ||
return numberValue; | ||
} | ||
|
||
return 7; // Default value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters