refactor: rename inputs

This commit is contained in:
Peter Evans 2020-09-25 11:13:16 +09:00
parent 08f06f46d8
commit ad0054eb7a
4 changed files with 52 additions and 52 deletions

View file

@ -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 `<namespace>/<name>`
repository:
description: Docker Hub repository in the format `<namespace>/<name>`
required: true
readme-filepath:
description: Path to the repository readme. Defaults to `./README.md`.

44
dist/index.js vendored
View file

@ -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) {

View file

@ -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')
}

View file

@ -27,14 +27,14 @@ async function run(): Promise<void> {
// 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')