feat: truncate short description exceeding the byte limit (#143)
Some checks failed
Publish Docker Image / publish (push) Has been cancelled

* feat: truncate short description exceeding the byte limit

* fix tests
This commit is contained in:
Peter Evans
2023-04-07 09:16:46 +09:00
committed by GitHub
parent 3ba533f0ff
commit 4b1a4bb484
7 changed files with 80 additions and 47 deletions

View File

@@ -2,12 +2,10 @@ import * as core from '@actions/core'
import * as inputHelper from './input-helper'
import * as dockerhubHelper from './dockerhub-helper'
import * as readmeHelper from './readme-helper'
import * as utils from './utils'
import {inspect} from 'util'
function getErrorMessage(error: unknown) {
if (error instanceof Error) return error.message
return String(error)
}
const SHORT_DESCRIPTION_MAX_BYTES = 100
async function run(): Promise<void> {
try {
@@ -25,6 +23,17 @@ async function run(): Promise<void> {
)
core.debug(readmeContent)
// Truncate the short description if it is too long
const truncatedShortDescription = utils.truncateToBytes(
inputs.shortDescription,
SHORT_DESCRIPTION_MAX_BYTES
)
if (truncatedShortDescription.length !== inputs.shortDescription.length) {
core.warning(
`The short description exceeds DockerHub's limit and has been truncated to ${SHORT_DESCRIPTION_MAX_BYTES} bytes.`
)
}
// Acquire a token for the Docker Hub API
core.info('Acquiring token')
const token = await dockerhubHelper.getToken(
@@ -42,7 +51,7 @@ async function run(): Promise<void> {
core.info('Request successful')
} catch (error) {
core.debug(inspect(error))
core.setFailed(getErrorMessage(error))
core.setFailed(utils.getErrorMessage(error))
}
}