From ad0054eb7ab2ad68e035c7f6739fb94d797a1bc2 Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Fri, 25 Sep 2020 11:13:16 +0900 Subject: [PATCH] refactor: rename inputs --- action.yml | 8 ++++---- dist/index.js | 44 +++++++++++++++++++++---------------------- src/input-helper.ts | 46 ++++++++++++++++++++++----------------------- src/main.ts | 6 +++--- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/action.yml b/action.yml index 3c48e75..35cb92a 100644 --- a/action.yml +++ b/action.yml @@ -2,14 +2,14 @@ name: 'Docker Hub Description' author: 'Peter Evans' description: 'An action to update a Docker Hub repository description from README.md' inputs: - dockerhub-username: + username: description: Docker Hub username required: true - dockerhub-password: + password: description: Docker Hub password required: true - dockerhub-repository: - description: Docker Hub repository to update in the format `/` + repository: + description: Docker Hub repository in the format `/` required: true readme-filepath: description: Path to the repository readme. Defaults to `./README.md`. diff --git a/dist/index.js b/dist/index.js index c90a15b..ccdf443 100644 --- a/dist/index.js +++ b/dist/index.js @@ -106,32 +106,32 @@ const core = __importStar(__webpack_require__(186)); const README_FILEPATH_DEFAULT = './README.md'; function getInputs() { const inputs = { - dockerhubUsername: core.getInput('dockerhub-username'), - dockerhubPassword: core.getInput('dockerhub-password'), - dockerhubRepository: core.getInput('dockerhub-repository'), + username: core.getInput('username'), + password: core.getInput('password'), + repository: core.getInput('repository'), readmeFilepath: core.getInput('readme-filepath') }; // Environment variable input alternatives and their aliases - if (!inputs.dockerhubUsername && process.env['DOCKERHUB_USERNAME']) { - inputs.dockerhubUsername = process.env['DOCKERHUB_USERNAME']; + if (!inputs.username && process.env['DOCKERHUB_USERNAME']) { + inputs.username = process.env['DOCKERHUB_USERNAME']; } - if (!inputs.dockerhubUsername && process.env['DOCKER_USERNAME']) { - inputs.dockerhubUsername = process.env['DOCKER_USERNAME']; + if (!inputs.username && process.env['DOCKER_USERNAME']) { + inputs.username = process.env['DOCKER_USERNAME']; } - if (!inputs.dockerhubPassword && process.env['DOCKERHUB_PASSWORD']) { - inputs.dockerhubPassword = process.env['DOCKERHUB_PASSWORD']; + if (!inputs.password && process.env['DOCKERHUB_PASSWORD']) { + inputs.password = process.env['DOCKERHUB_PASSWORD']; } - if (!inputs.dockerhubPassword && process.env['DOCKER_PASSWORD']) { - inputs.dockerhubPassword = process.env['DOCKER_PASSWORD']; + if (!inputs.password && process.env['DOCKER_PASSWORD']) { + inputs.password = process.env['DOCKER_PASSWORD']; } - if (!inputs.dockerhubRepository && process.env['DOCKERHUB_REPOSITORY']) { - inputs.dockerhubRepository = process.env['DOCKERHUB_REPOSITORY']; + if (!inputs.repository && process.env['DOCKERHUB_REPOSITORY']) { + inputs.repository = process.env['DOCKERHUB_REPOSITORY']; } - if (!inputs.dockerhubRepository && process.env['DOCKER_REPOSITORY']) { - inputs.dockerhubRepository = process.env['DOCKER_REPOSITORY']; + if (!inputs.repository && process.env['DOCKER_REPOSITORY']) { + inputs.repository = process.env['DOCKER_REPOSITORY']; } - if (!inputs.dockerhubRepository && process.env['GITHUB_REPOSITORY']) { - inputs.dockerhubRepository = process.env['GITHUB_REPOSITORY']; + if (!inputs.repository && process.env['GITHUB_REPOSITORY']) { + inputs.repository = process.env['GITHUB_REPOSITORY']; } if (!inputs.readmeFilepath && process.env['README_FILEPATH']) { inputs.readmeFilepath = process.env['README_FILEPATH']; @@ -149,9 +149,9 @@ function checkRequiredInput(input, name) { } } function validateInputs(inputs) { - checkRequiredInput(inputs.dockerhubUsername, 'dockerhub-username'); - checkRequiredInput(inputs.dockerhubPassword, 'dockerhub-password'); - checkRequiredInput(inputs.dockerhubRepository, 'dockerhub-repository'); + checkRequiredInput(inputs.username, 'username'); + checkRequiredInput(inputs.password, 'password'); + checkRequiredInput(inputs.repository, 'repository'); } exports.validateInputs = validateInputs; @@ -214,10 +214,10 @@ function run() { } // Acquire a token for the Docker Hub API core.info('Acquiring token'); - const token = yield dockerhubHelper.getToken(inputs.dockerhubUsername, inputs.dockerhubPassword); + const token = yield dockerhubHelper.getToken(inputs.username, inputs.password); // Send a PATCH request to update the description of the repository core.info('Sending PATCH request'); - yield dockerhubHelper.updateRepositoryDescription(token, inputs.dockerhubRepository, readmeContent); + yield dockerhubHelper.updateRepositoryDescription(token, inputs.repository, readmeContent); core.info('Request successful'); } catch (error) { diff --git a/src/input-helper.ts b/src/input-helper.ts index 501edb4..b8dafc0 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -3,44 +3,44 @@ import * as core from '@actions/core' const README_FILEPATH_DEFAULT = './README.md' interface Inputs { - dockerhubUsername: string - dockerhubPassword: string - dockerhubRepository: string + username: string + password: string + repository: string readmeFilepath: string } export function getInputs(): Inputs { const inputs = { - dockerhubUsername: core.getInput('dockerhub-username'), - dockerhubPassword: core.getInput('dockerhub-password'), - dockerhubRepository: core.getInput('dockerhub-repository'), + username: core.getInput('username'), + password: core.getInput('password'), + repository: core.getInput('repository'), readmeFilepath: core.getInput('readme-filepath') } // Environment variable input alternatives and their aliases - if (!inputs.dockerhubUsername && process.env['DOCKERHUB_USERNAME']) { - inputs.dockerhubUsername = process.env['DOCKERHUB_USERNAME'] + if (!inputs.username && process.env['DOCKERHUB_USERNAME']) { + inputs.username = process.env['DOCKERHUB_USERNAME'] } - if (!inputs.dockerhubUsername && process.env['DOCKER_USERNAME']) { - inputs.dockerhubUsername = process.env['DOCKER_USERNAME'] + if (!inputs.username && process.env['DOCKER_USERNAME']) { + inputs.username = process.env['DOCKER_USERNAME'] } - if (!inputs.dockerhubPassword && process.env['DOCKERHUB_PASSWORD']) { - inputs.dockerhubPassword = process.env['DOCKERHUB_PASSWORD'] + if (!inputs.password && process.env['DOCKERHUB_PASSWORD']) { + inputs.password = process.env['DOCKERHUB_PASSWORD'] } - if (!inputs.dockerhubPassword && process.env['DOCKER_PASSWORD']) { - inputs.dockerhubPassword = process.env['DOCKER_PASSWORD'] + if (!inputs.password && process.env['DOCKER_PASSWORD']) { + inputs.password = process.env['DOCKER_PASSWORD'] } - if (!inputs.dockerhubRepository && process.env['DOCKERHUB_REPOSITORY']) { - inputs.dockerhubRepository = process.env['DOCKERHUB_REPOSITORY'] + if (!inputs.repository && process.env['DOCKERHUB_REPOSITORY']) { + inputs.repository = process.env['DOCKERHUB_REPOSITORY'] } - if (!inputs.dockerhubRepository && process.env['DOCKER_REPOSITORY']) { - inputs.dockerhubRepository = process.env['DOCKER_REPOSITORY'] + if (!inputs.repository && process.env['DOCKER_REPOSITORY']) { + inputs.repository = process.env['DOCKER_REPOSITORY'] } - if (!inputs.dockerhubRepository && process.env['GITHUB_REPOSITORY']) { - inputs.dockerhubRepository = process.env['GITHUB_REPOSITORY'] + if (!inputs.repository && process.env['GITHUB_REPOSITORY']) { + inputs.repository = process.env['GITHUB_REPOSITORY'] } if (!inputs.readmeFilepath && process.env['README_FILEPATH']) { @@ -62,7 +62,7 @@ function checkRequiredInput(input: string, name: string): void { } export function validateInputs(inputs: Inputs): void { - checkRequiredInput(inputs.dockerhubUsername, 'dockerhub-username') - checkRequiredInput(inputs.dockerhubPassword, 'dockerhub-password') - checkRequiredInput(inputs.dockerhubRepository, 'dockerhub-repository') + checkRequiredInput(inputs.username, 'username') + checkRequiredInput(inputs.password, 'password') + checkRequiredInput(inputs.repository, 'repository') } diff --git a/src/main.ts b/src/main.ts index c4b57a4..460fbef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -27,14 +27,14 @@ async function run(): Promise { // Acquire a token for the Docker Hub API core.info('Acquiring token') const token = await dockerhubHelper.getToken( - inputs.dockerhubUsername, - inputs.dockerhubPassword + inputs.username, + inputs.password ) // Send a PATCH request to update the description of the repository core.info('Sending PATCH request') await dockerhubHelper.updateRepositoryDescription( token, - inputs.dockerhubRepository, + inputs.repository, readmeContent ) core.info('Request successful')