feat: add input for short description

This commit is contained in:
Peter Evans
2020-09-25 15:22:36 +09:00
parent 9db4dd4244
commit 8fa8201677
6 changed files with 28 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
import * as core from '@actions/core'
import * as fetch from 'node-fetch'
const DESCRIPTION_MAX_CHARS = 100
export async function getToken(
username: string,
password: string
@@ -22,11 +24,15 @@ export async function getToken(
export async function updateRepositoryDescription(
token: string,
repository: string,
description: string,
fullDescription: string
): Promise<void> {
const body = {
full_description: fullDescription
}
if (description) {
body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS)
}
await fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
method: 'patch',
body: JSON.stringify(body),

View File

@@ -6,6 +6,7 @@ interface Inputs {
username: string
password: string
repository: string
shortDescription: string
readmeFilepath: string
}
@@ -14,6 +15,7 @@ export function getInputs(): Inputs {
username: core.getInput('username'),
password: core.getInput('password'),
repository: core.getInput('repository'),
shortDescription: core.getInput('short-description'),
readmeFilepath: core.getInput('readme-filepath')
}
@@ -40,6 +42,10 @@ export function getInputs(): Inputs {
inputs.repository = process.env['DOCKER_REPOSITORY']
}
if (!inputs.shortDescription && process.env['SHORT_DESCRIPTION']) {
inputs.shortDescription = process.env['SHORT_DESCRIPTION']
}
if (!inputs.readmeFilepath && process.env['README_FILEPATH']) {
inputs.readmeFilepath = process.env['README_FILEPATH']
}
@@ -64,5 +70,4 @@ function checkRequiredInput(input: string, name: string): void {
export function validateInputs(inputs: Inputs): void {
checkRequiredInput(inputs.username, 'username')
checkRequiredInput(inputs.password, 'password')
checkRequiredInput(inputs.repository, 'repository')
}

View File

@@ -35,6 +35,7 @@ async function run(): Promise<void> {
await dockerhubHelper.updateRepositoryDescription(
token,
inputs.repository,
inputs.shortDescription,
readmeContent
)
core.info('Request successful')