diff --git a/README.md b/README.md index dbd767d..8ac5dc8 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea | `username` | (**required**) Docker Hub username. If updating a Docker Hub repository belonging to an organization, this user must have `Admin` permissions for the repository. | | | `password` | (**required**) Docker Hub password. | | | `repository` | Docker Hub repository in the format `/`. | `github.repository` | +| `short-description` | Docker Hub repository short description. Input exceeding 100 characters will be truncated. | | | `readme-filepath` | Path to the repository readme. | `./README.md` | #### Specifying the file path diff --git a/action.yml b/action.yml index 2525a27..87e81c0 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,10 @@ inputs: description: > Docker Hub repository in the format `/` Default: `github.repository` + short-description: + description: > + Docker Hub repository short description + Input exceeding 100 characters will be truncated readme-filepath: description: > Path to the repository readme diff --git a/dist/index.js b/dist/index.js index 6783d46..e99f9ff 100644 --- a/dist/index.js +++ b/dist/index.js @@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.updateRepositoryDescription = exports.getToken = void 0; const core = __importStar(__webpack_require__(186)); const fetch = __importStar(__webpack_require__(467)); +const DESCRIPTION_MAX_CHARS = 100; function getToken(username, password) { return __awaiter(this, void 0, void 0, function* () { const body = { @@ -56,11 +57,14 @@ function getToken(username, password) { }); } exports.getToken = getToken; -function updateRepositoryDescription(token, repository, fullDescription) { +function updateRepositoryDescription(token, repository, description, fullDescription) { return __awaiter(this, void 0, void 0, function* () { const body = { full_description: fullDescription }; + if (description) { + body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS); + } yield fetch(`https://hub.docker.com/v2/repositories/${repository}`, { method: 'patch', body: JSON.stringify(body), @@ -109,6 +113,7 @@ function getInputs() { username: core.getInput('username'), password: core.getInput('password'), repository: core.getInput('repository'), + shortDescription: core.getInput('short-description'), readmeFilepath: core.getInput('readme-filepath') }; // Environment variable input alternatives and their aliases @@ -130,6 +135,9 @@ function getInputs() { if (!inputs.repository && process.env['DOCKER_REPOSITORY']) { 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']; } @@ -151,7 +159,6 @@ function checkRequiredInput(input, name) { function validateInputs(inputs) { checkRequiredInput(inputs.username, 'username'); checkRequiredInput(inputs.password, 'password'); - checkRequiredInput(inputs.repository, 'repository'); } exports.validateInputs = validateInputs; @@ -217,7 +224,7 @@ function run() { 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.repository, readmeContent); + yield dockerhubHelper.updateRepositoryDescription(token, inputs.repository, inputs.shortDescription, readmeContent); core.info('Request successful'); } catch (error) { diff --git a/src/dockerhub-helper.ts b/src/dockerhub-helper.ts index f2463cf..1aeccd8 100644 --- a/src/dockerhub-helper.ts +++ b/src/dockerhub-helper.ts @@ -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 { 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), diff --git a/src/input-helper.ts b/src/input-helper.ts index 085f1c6..f4c5997 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -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') } diff --git a/src/main.ts b/src/main.ts index 460fbef..a21ebf6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -35,6 +35,7 @@ async function run(): Promise { await dockerhubHelper.updateRepositoryDescription( token, inputs.repository, + inputs.shortDescription, readmeContent ) core.info('Request successful')