mirror of
https://github.com/peter-evans/dockerhub-description.git
synced 2024-11-22 12:09:33 +01:00
refactor: rename inputs
This commit is contained in:
parent
08f06f46d8
commit
ad0054eb7a
4 changed files with 52 additions and 52 deletions
|
@ -2,14 +2,14 @@ name: 'Docker Hub Description'
|
||||||
author: 'Peter Evans'
|
author: 'Peter Evans'
|
||||||
description: 'An action to update a Docker Hub repository description from README.md'
|
description: 'An action to update a Docker Hub repository description from README.md'
|
||||||
inputs:
|
inputs:
|
||||||
dockerhub-username:
|
username:
|
||||||
description: Docker Hub username
|
description: Docker Hub username
|
||||||
required: true
|
required: true
|
||||||
dockerhub-password:
|
password:
|
||||||
description: Docker Hub password
|
description: Docker Hub password
|
||||||
required: true
|
required: true
|
||||||
dockerhub-repository:
|
repository:
|
||||||
description: Docker Hub repository to update in the format `<namespace>/<name>`
|
description: Docker Hub repository in the format `<namespace>/<name>`
|
||||||
required: true
|
required: true
|
||||||
readme-filepath:
|
readme-filepath:
|
||||||
description: Path to the repository readme. Defaults to `./README.md`.
|
description: Path to the repository readme. Defaults to `./README.md`.
|
||||||
|
|
44
dist/index.js
vendored
44
dist/index.js
vendored
|
@ -106,32 +106,32 @@ const core = __importStar(__webpack_require__(186));
|
||||||
const README_FILEPATH_DEFAULT = './README.md';
|
const README_FILEPATH_DEFAULT = './README.md';
|
||||||
function getInputs() {
|
function getInputs() {
|
||||||
const inputs = {
|
const inputs = {
|
||||||
dockerhubUsername: core.getInput('dockerhub-username'),
|
username: core.getInput('username'),
|
||||||
dockerhubPassword: core.getInput('dockerhub-password'),
|
password: core.getInput('password'),
|
||||||
dockerhubRepository: core.getInput('dockerhub-repository'),
|
repository: core.getInput('repository'),
|
||||||
readmeFilepath: core.getInput('readme-filepath')
|
readmeFilepath: core.getInput('readme-filepath')
|
||||||
};
|
};
|
||||||
// Environment variable input alternatives and their aliases
|
// Environment variable input alternatives and their aliases
|
||||||
if (!inputs.dockerhubUsername && process.env['DOCKERHUB_USERNAME']) {
|
if (!inputs.username && process.env['DOCKERHUB_USERNAME']) {
|
||||||
inputs.dockerhubUsername = process.env['DOCKERHUB_USERNAME'];
|
inputs.username = process.env['DOCKERHUB_USERNAME'];
|
||||||
}
|
}
|
||||||
if (!inputs.dockerhubUsername && process.env['DOCKER_USERNAME']) {
|
if (!inputs.username && process.env['DOCKER_USERNAME']) {
|
||||||
inputs.dockerhubUsername = process.env['DOCKER_USERNAME'];
|
inputs.username = process.env['DOCKER_USERNAME'];
|
||||||
}
|
}
|
||||||
if (!inputs.dockerhubPassword && process.env['DOCKERHUB_PASSWORD']) {
|
if (!inputs.password && process.env['DOCKERHUB_PASSWORD']) {
|
||||||
inputs.dockerhubPassword = process.env['DOCKERHUB_PASSWORD'];
|
inputs.password = process.env['DOCKERHUB_PASSWORD'];
|
||||||
}
|
}
|
||||||
if (!inputs.dockerhubPassword && process.env['DOCKER_PASSWORD']) {
|
if (!inputs.password && process.env['DOCKER_PASSWORD']) {
|
||||||
inputs.dockerhubPassword = process.env['DOCKER_PASSWORD'];
|
inputs.password = process.env['DOCKER_PASSWORD'];
|
||||||
}
|
}
|
||||||
if (!inputs.dockerhubRepository && process.env['DOCKERHUB_REPOSITORY']) {
|
if (!inputs.repository && process.env['DOCKERHUB_REPOSITORY']) {
|
||||||
inputs.dockerhubRepository = process.env['DOCKERHUB_REPOSITORY'];
|
inputs.repository = process.env['DOCKERHUB_REPOSITORY'];
|
||||||
}
|
}
|
||||||
if (!inputs.dockerhubRepository && process.env['DOCKER_REPOSITORY']) {
|
if (!inputs.repository && process.env['DOCKER_REPOSITORY']) {
|
||||||
inputs.dockerhubRepository = process.env['DOCKER_REPOSITORY'];
|
inputs.repository = process.env['DOCKER_REPOSITORY'];
|
||||||
}
|
}
|
||||||
if (!inputs.dockerhubRepository && process.env['GITHUB_REPOSITORY']) {
|
if (!inputs.repository && process.env['GITHUB_REPOSITORY']) {
|
||||||
inputs.dockerhubRepository = process.env['GITHUB_REPOSITORY'];
|
inputs.repository = process.env['GITHUB_REPOSITORY'];
|
||||||
}
|
}
|
||||||
if (!inputs.readmeFilepath && process.env['README_FILEPATH']) {
|
if (!inputs.readmeFilepath && process.env['README_FILEPATH']) {
|
||||||
inputs.readmeFilepath = process.env['README_FILEPATH'];
|
inputs.readmeFilepath = process.env['README_FILEPATH'];
|
||||||
|
@ -149,9 +149,9 @@ function checkRequiredInput(input, name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function validateInputs(inputs) {
|
function validateInputs(inputs) {
|
||||||
checkRequiredInput(inputs.dockerhubUsername, 'dockerhub-username');
|
checkRequiredInput(inputs.username, 'username');
|
||||||
checkRequiredInput(inputs.dockerhubPassword, 'dockerhub-password');
|
checkRequiredInput(inputs.password, 'password');
|
||||||
checkRequiredInput(inputs.dockerhubRepository, 'dockerhub-repository');
|
checkRequiredInput(inputs.repository, 'repository');
|
||||||
}
|
}
|
||||||
exports.validateInputs = validateInputs;
|
exports.validateInputs = validateInputs;
|
||||||
|
|
||||||
|
@ -214,10 +214,10 @@ function run() {
|
||||||
}
|
}
|
||||||
// Acquire a token for the Docker Hub API
|
// Acquire a token for the Docker Hub API
|
||||||
core.info('Acquiring token');
|
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
|
// Send a PATCH request to update the description of the repository
|
||||||
core.info('Sending PATCH request');
|
core.info('Sending PATCH request');
|
||||||
yield dockerhubHelper.updateRepositoryDescription(token, inputs.dockerhubRepository, readmeContent);
|
yield dockerhubHelper.updateRepositoryDescription(token, inputs.repository, readmeContent);
|
||||||
core.info('Request successful');
|
core.info('Request successful');
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
|
@ -3,44 +3,44 @@ import * as core from '@actions/core'
|
||||||
const README_FILEPATH_DEFAULT = './README.md'
|
const README_FILEPATH_DEFAULT = './README.md'
|
||||||
|
|
||||||
interface Inputs {
|
interface Inputs {
|
||||||
dockerhubUsername: string
|
username: string
|
||||||
dockerhubPassword: string
|
password: string
|
||||||
dockerhubRepository: string
|
repository: string
|
||||||
readmeFilepath: string
|
readmeFilepath: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getInputs(): Inputs {
|
export function getInputs(): Inputs {
|
||||||
const inputs = {
|
const inputs = {
|
||||||
dockerhubUsername: core.getInput('dockerhub-username'),
|
username: core.getInput('username'),
|
||||||
dockerhubPassword: core.getInput('dockerhub-password'),
|
password: core.getInput('password'),
|
||||||
dockerhubRepository: core.getInput('dockerhub-repository'),
|
repository: core.getInput('repository'),
|
||||||
readmeFilepath: core.getInput('readme-filepath')
|
readmeFilepath: core.getInput('readme-filepath')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Environment variable input alternatives and their aliases
|
// Environment variable input alternatives and their aliases
|
||||||
|
|
||||||
if (!inputs.dockerhubUsername && process.env['DOCKERHUB_USERNAME']) {
|
if (!inputs.username && process.env['DOCKERHUB_USERNAME']) {
|
||||||
inputs.dockerhubUsername = process.env['DOCKERHUB_USERNAME']
|
inputs.username = process.env['DOCKERHUB_USERNAME']
|
||||||
}
|
}
|
||||||
if (!inputs.dockerhubUsername && process.env['DOCKER_USERNAME']) {
|
if (!inputs.username && process.env['DOCKER_USERNAME']) {
|
||||||
inputs.dockerhubUsername = process.env['DOCKER_USERNAME']
|
inputs.username = process.env['DOCKER_USERNAME']
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inputs.dockerhubPassword && process.env['DOCKERHUB_PASSWORD']) {
|
if (!inputs.password && process.env['DOCKERHUB_PASSWORD']) {
|
||||||
inputs.dockerhubPassword = process.env['DOCKERHUB_PASSWORD']
|
inputs.password = process.env['DOCKERHUB_PASSWORD']
|
||||||
}
|
}
|
||||||
if (!inputs.dockerhubPassword && process.env['DOCKER_PASSWORD']) {
|
if (!inputs.password && process.env['DOCKER_PASSWORD']) {
|
||||||
inputs.dockerhubPassword = process.env['DOCKER_PASSWORD']
|
inputs.password = process.env['DOCKER_PASSWORD']
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inputs.dockerhubRepository && process.env['DOCKERHUB_REPOSITORY']) {
|
if (!inputs.repository && process.env['DOCKERHUB_REPOSITORY']) {
|
||||||
inputs.dockerhubRepository = process.env['DOCKERHUB_REPOSITORY']
|
inputs.repository = process.env['DOCKERHUB_REPOSITORY']
|
||||||
}
|
}
|
||||||
if (!inputs.dockerhubRepository && process.env['DOCKER_REPOSITORY']) {
|
if (!inputs.repository && process.env['DOCKER_REPOSITORY']) {
|
||||||
inputs.dockerhubRepository = process.env['DOCKER_REPOSITORY']
|
inputs.repository = process.env['DOCKER_REPOSITORY']
|
||||||
}
|
}
|
||||||
if (!inputs.dockerhubRepository && process.env['GITHUB_REPOSITORY']) {
|
if (!inputs.repository && process.env['GITHUB_REPOSITORY']) {
|
||||||
inputs.dockerhubRepository = process.env['GITHUB_REPOSITORY']
|
inputs.repository = process.env['GITHUB_REPOSITORY']
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inputs.readmeFilepath && process.env['README_FILEPATH']) {
|
if (!inputs.readmeFilepath && process.env['README_FILEPATH']) {
|
||||||
|
@ -62,7 +62,7 @@ function checkRequiredInput(input: string, name: string): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateInputs(inputs: Inputs): void {
|
export function validateInputs(inputs: Inputs): void {
|
||||||
checkRequiredInput(inputs.dockerhubUsername, 'dockerhub-username')
|
checkRequiredInput(inputs.username, 'username')
|
||||||
checkRequiredInput(inputs.dockerhubPassword, 'dockerhub-password')
|
checkRequiredInput(inputs.password, 'password')
|
||||||
checkRequiredInput(inputs.dockerhubRepository, 'dockerhub-repository')
|
checkRequiredInput(inputs.repository, 'repository')
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,14 @@ async function run(): Promise<void> {
|
||||||
// Acquire a token for the Docker Hub API
|
// Acquire a token for the Docker Hub API
|
||||||
core.info('Acquiring token')
|
core.info('Acquiring token')
|
||||||
const token = await dockerhubHelper.getToken(
|
const token = await dockerhubHelper.getToken(
|
||||||
inputs.dockerhubUsername,
|
inputs.username,
|
||||||
inputs.dockerhubPassword
|
inputs.password
|
||||||
)
|
)
|
||||||
// Send a PATCH request to update the description of the repository
|
// Send a PATCH request to update the description of the repository
|
||||||
core.info('Sending PATCH request')
|
core.info('Sending PATCH request')
|
||||||
await dockerhubHelper.updateRepositoryDescription(
|
await dockerhubHelper.updateRepositoryDescription(
|
||||||
token,
|
token,
|
||||||
inputs.dockerhubRepository,
|
inputs.repository,
|
||||||
readmeContent
|
readmeContent
|
||||||
)
|
)
|
||||||
core.info('Request successful')
|
core.info('Request successful')
|
||||||
|
|
Loading…
Reference in a new issue