mirror of
https://github.com/peter-evans/dockerhub-description.git
synced 2024-11-22 03:59:34 +01:00
feat: add input for short description
This commit is contained in:
parent
9db4dd4244
commit
8fa8201677
6 changed files with 28 additions and 4 deletions
|
@ -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. | |
|
| `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. | |
|
| `password` | (**required**) Docker Hub password. | |
|
||||||
| `repository` | Docker Hub repository in the format `<namespace>/<name>`. | `github.repository` |
|
| `repository` | Docker Hub repository in the format `<namespace>/<name>`. | `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` |
|
| `readme-filepath` | Path to the repository readme. | `./README.md` |
|
||||||
|
|
||||||
#### Specifying the file path
|
#### Specifying the file path
|
||||||
|
|
|
@ -12,6 +12,10 @@ inputs:
|
||||||
description: >
|
description: >
|
||||||
Docker Hub repository in the format `<namespace>/<name>`
|
Docker Hub repository in the format `<namespace>/<name>`
|
||||||
Default: `github.repository`
|
Default: `github.repository`
|
||||||
|
short-description:
|
||||||
|
description: >
|
||||||
|
Docker Hub repository short description
|
||||||
|
Input exceeding 100 characters will be truncated
|
||||||
readme-filepath:
|
readme-filepath:
|
||||||
description: >
|
description: >
|
||||||
Path to the repository readme
|
Path to the repository readme
|
||||||
|
|
13
dist/index.js
vendored
13
dist/index.js
vendored
|
@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.updateRepositoryDescription = exports.getToken = void 0;
|
exports.updateRepositoryDescription = exports.getToken = void 0;
|
||||||
const core = __importStar(__webpack_require__(186));
|
const core = __importStar(__webpack_require__(186));
|
||||||
const fetch = __importStar(__webpack_require__(467));
|
const fetch = __importStar(__webpack_require__(467));
|
||||||
|
const DESCRIPTION_MAX_CHARS = 100;
|
||||||
function getToken(username, password) {
|
function getToken(username, password) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const body = {
|
const body = {
|
||||||
|
@ -56,11 +57,14 @@ function getToken(username, password) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getToken = getToken;
|
exports.getToken = getToken;
|
||||||
function updateRepositoryDescription(token, repository, fullDescription) {
|
function updateRepositoryDescription(token, repository, description, fullDescription) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const body = {
|
const body = {
|
||||||
full_description: fullDescription
|
full_description: fullDescription
|
||||||
};
|
};
|
||||||
|
if (description) {
|
||||||
|
body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS);
|
||||||
|
}
|
||||||
yield fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
yield fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
||||||
method: 'patch',
|
method: 'patch',
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
|
@ -109,6 +113,7 @@ function getInputs() {
|
||||||
username: core.getInput('username'),
|
username: core.getInput('username'),
|
||||||
password: core.getInput('password'),
|
password: core.getInput('password'),
|
||||||
repository: core.getInput('repository'),
|
repository: core.getInput('repository'),
|
||||||
|
shortDescription: core.getInput('short-description'),
|
||||||
readmeFilepath: core.getInput('readme-filepath')
|
readmeFilepath: core.getInput('readme-filepath')
|
||||||
};
|
};
|
||||||
// Environment variable input alternatives and their aliases
|
// Environment variable input alternatives and their aliases
|
||||||
|
@ -130,6 +135,9 @@ function getInputs() {
|
||||||
if (!inputs.repository && process.env['DOCKER_REPOSITORY']) {
|
if (!inputs.repository && process.env['DOCKER_REPOSITORY']) {
|
||||||
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']) {
|
if (!inputs.readmeFilepath && process.env['README_FILEPATH']) {
|
||||||
inputs.readmeFilepath = process.env['README_FILEPATH'];
|
inputs.readmeFilepath = process.env['README_FILEPATH'];
|
||||||
}
|
}
|
||||||
|
@ -151,7 +159,6 @@ function checkRequiredInput(input, name) {
|
||||||
function validateInputs(inputs) {
|
function validateInputs(inputs) {
|
||||||
checkRequiredInput(inputs.username, 'username');
|
checkRequiredInput(inputs.username, 'username');
|
||||||
checkRequiredInput(inputs.password, 'password');
|
checkRequiredInput(inputs.password, 'password');
|
||||||
checkRequiredInput(inputs.repository, 'repository');
|
|
||||||
}
|
}
|
||||||
exports.validateInputs = validateInputs;
|
exports.validateInputs = validateInputs;
|
||||||
|
|
||||||
|
@ -217,7 +224,7 @@ function run() {
|
||||||
const token = yield dockerhubHelper.getToken(inputs.username, inputs.password);
|
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.repository, readmeContent);
|
yield dockerhubHelper.updateRepositoryDescription(token, inputs.repository, inputs.shortDescription, readmeContent);
|
||||||
core.info('Request successful');
|
core.info('Request successful');
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as fetch from 'node-fetch'
|
import * as fetch from 'node-fetch'
|
||||||
|
|
||||||
|
const DESCRIPTION_MAX_CHARS = 100
|
||||||
|
|
||||||
export async function getToken(
|
export async function getToken(
|
||||||
username: string,
|
username: string,
|
||||||
password: string
|
password: string
|
||||||
|
@ -22,11 +24,15 @@ export async function getToken(
|
||||||
export async function updateRepositoryDescription(
|
export async function updateRepositoryDescription(
|
||||||
token: string,
|
token: string,
|
||||||
repository: string,
|
repository: string,
|
||||||
|
description: string,
|
||||||
fullDescription: string
|
fullDescription: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const body = {
|
const body = {
|
||||||
full_description: fullDescription
|
full_description: fullDescription
|
||||||
}
|
}
|
||||||
|
if (description) {
|
||||||
|
body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS)
|
||||||
|
}
|
||||||
await fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
await fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
||||||
method: 'patch',
|
method: 'patch',
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
|
|
|
@ -6,6 +6,7 @@ interface Inputs {
|
||||||
username: string
|
username: string
|
||||||
password: string
|
password: string
|
||||||
repository: string
|
repository: string
|
||||||
|
shortDescription: string
|
||||||
readmeFilepath: string
|
readmeFilepath: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ export function getInputs(): Inputs {
|
||||||
username: core.getInput('username'),
|
username: core.getInput('username'),
|
||||||
password: core.getInput('password'),
|
password: core.getInput('password'),
|
||||||
repository: core.getInput('repository'),
|
repository: core.getInput('repository'),
|
||||||
|
shortDescription: core.getInput('short-description'),
|
||||||
readmeFilepath: core.getInput('readme-filepath')
|
readmeFilepath: core.getInput('readme-filepath')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +42,10 @@ export function getInputs(): Inputs {
|
||||||
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']) {
|
if (!inputs.readmeFilepath && process.env['README_FILEPATH']) {
|
||||||
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 {
|
export function validateInputs(inputs: Inputs): void {
|
||||||
checkRequiredInput(inputs.username, 'username')
|
checkRequiredInput(inputs.username, 'username')
|
||||||
checkRequiredInput(inputs.password, 'password')
|
checkRequiredInput(inputs.password, 'password')
|
||||||
checkRequiredInput(inputs.repository, 'repository')
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ async function run(): Promise<void> {
|
||||||
await dockerhubHelper.updateRepositoryDescription(
|
await dockerhubHelper.updateRepositoryDescription(
|
||||||
token,
|
token,
|
||||||
inputs.repository,
|
inputs.repository,
|
||||||
|
inputs.shortDescription,
|
||||||
readmeContent
|
readmeContent
|
||||||
)
|
)
|
||||||
core.info('Request successful')
|
core.info('Request successful')
|
||||||
|
|
Loading…
Reference in a new issue