18 Commits

Author SHA1 Message Date
Peter Evans
579f64ca0a fix: use the truncated short description (#148)
Some checks failed
Publish Docker Image / publish (push) Has been cancelled
2023-04-10 08:18:10 +09:00
dependabot[bot]
3f29bdade4 build(deps-dev): bump eslint from 8.37.0 to 8.38.0 (#146)
Bumps [eslint](https://github.com/eslint/eslint) from 8.37.0 to 8.38.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.37.0...v8.38.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-09 14:58:56 +00:00
dependabot[bot]
8b56ea036f build(deps-dev): bump @typescript-eslint/parser from 5.57.0 to 5.57.1 (#144)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.57.0 to 5.57.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.57.1/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-09 14:58:35 +00:00
dependabot[bot]
2e2fadf6e3 build(deps): bump peter-evans/create-pull-request from 4 to 5 (#145)
Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from 4 to 5.
- [Release notes](https://github.com/peter-evans/create-pull-request/releases)
- [Commits](https://github.com/peter-evans/create-pull-request/compare/v4...v5)

---
updated-dependencies:
- dependency-name: peter-evans/create-pull-request
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-09 14:58:34 +00:00
Peter Evans
015b1b5f51 docs: update readme 2023-04-07 09:21:58 +09:00
Peter Evans
4b1a4bb484 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
2023-04-07 09:16:46 +09:00
dependabot[bot]
3ba533f0ff build(deps-dev): bump @types/node from 16.18.21 to 16.18.23 (#140)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 16.18.21 to 16.18.23.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-02 15:02:35 +00:00
dependabot[bot]
f866d47eb4 build(deps-dev): bump eslint from 8.36.0 to 8.37.0 (#141)
Bumps [eslint](https://github.com/eslint/eslint) from 8.36.0 to 8.37.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.36.0...v8.37.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-02 15:01:15 +00:00
dependabot[bot]
03ca5ee9b4 build(deps-dev): bump @typescript-eslint/parser from 5.56.0 to 5.57.0 (#139)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.56.0 to 5.57.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.57.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-02 15:00:10 +00:00
dependabot[bot]
a57cec0ff6 build(deps-dev): bump @typescript-eslint/parser from 5.55.0 to 5.56.0 (#138)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.55.0 to 5.56.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.56.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-26 15:03:44 +00:00
dependabot[bot]
2a3abf56ec build(deps-dev): bump eslint-plugin-github from 4.6.1 to 4.7.0 (#137)
Bumps [eslint-plugin-github](https://github.com/github/eslint-plugin-github) from 4.6.1 to 4.7.0.
- [Release notes](https://github.com/github/eslint-plugin-github/releases)
- [Commits](https://github.com/github/eslint-plugin-github/compare/v4.6.1...v4.7.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-github
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-26 15:01:30 +00:00
dependabot[bot]
9e64bda1bc build(deps-dev): bump @types/node from 16.18.16 to 16.18.21 (#136)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 16.18.16 to 16.18.21.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-26 15:00:56 +00:00
dependabot[bot]
dd732b0272 build(deps-dev): bump prettier from 2.8.4 to 2.8.7 (#135)
Bumps [prettier](https://github.com/prettier/prettier) from 2.8.4 to 2.8.7.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.8.4...2.8.7)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-26 15:00:32 +00:00
dependabot[bot]
24d9720e95 build(deps): bump peter-evans/enable-pull-request-automerge from 2 to 3 (#134)
Bumps [peter-evans/enable-pull-request-automerge](https://github.com/peter-evans/enable-pull-request-automerge) from 2 to 3.
- [Release notes](https://github.com/peter-evans/enable-pull-request-automerge/releases)
- [Commits](https://github.com/peter-evans/enable-pull-request-automerge/compare/v2...v3)

---
updated-dependencies:
- dependency-name: peter-evans/enable-pull-request-automerge
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-26 14:59:44 +00:00
dependabot[bot]
74d5634479 build(deps-dev): bump @types/node from 16.18.14 to 16.18.16 (#133)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 16.18.14 to 16.18.16.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-19 15:04:03 +00:00
dependabot[bot]
f92370924c build(deps-dev): bump @typescript-eslint/parser from 5.54.1 to 5.55.0 (#132)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.54.1 to 5.55.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.55.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-19 15:00:54 +00:00
dependabot[bot]
32a61cce5a build(deps-dev): bump eslint from 8.35.0 to 8.36.0 (#131)
Bumps [eslint](https://github.com/eslint/eslint) from 8.35.0 to 8.36.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.35.0...v8.36.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-12 14:58:50 +00:00
dependabot[bot]
4a4792c2ca build(deps-dev): bump @typescript-eslint/parser from 5.54.0 to 5.54.1 (#130)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.54.0 to 5.54.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.54.1/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-12 14:58:34 +00:00
12 changed files with 179 additions and 117 deletions

View File

@@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]' if: github.actor == 'dependabot[bot]'
steps: steps:
- uses: peter-evans/enable-pull-request-automerge@v2 - uses: peter-evans/enable-pull-request-automerge@v3
with: with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }} token: ${{ secrets.ACTIONS_BOT_TOKEN }}
pull-request-number: ${{ github.event.pull_request.number }} pull-request-number: ${{ github.event.pull_request.number }}

View File

@@ -92,7 +92,7 @@ jobs:
name: dist name: dist
path: dist path: dist
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v4 uses: peter-evans/create-pull-request@v5
with: with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }} token: ${{ secrets.ACTIONS_BOT_TOKEN }}
commit-message: 'build: update distribution' commit-message: 'build: update distribution'

View File

@@ -31,7 +31,7 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea
#### Content limits #### Content limits
DockerHub has content limits. DockerHub has content limits.
The readme content is limited to 25,000 bytes, and `short-description` is limited to 100 characters. The readme content is limited to 25,000 bytes, and `short-description` is limited to 100 bytes.
This action truncates content to prevent the request being rejected. This action truncates content to prevent the request being rejected.
If the content has been truncated a warning will be issued in the run log. If the content has been truncated a warning will be issued in the run log.

View File

@@ -1,4 +1,4 @@
import {completeRelativeUrls, truncateToBytes} from '../src/readme-helper' import {completeRelativeUrls} from '../src/readme-helper'
describe('complete relative urls tests', () => { describe('complete relative urls tests', () => {
const GITHUB_SERVER_URL = process.env['GITHUB_SERVER_URL'] const GITHUB_SERVER_URL = process.env['GITHUB_SERVER_URL']
@@ -333,12 +333,3 @@ describe('complete relative urls tests', () => {
) )
}) })
}) })
describe('truncate to bytes tests', () => {
test('unicode aware truncation to a number of bytes', async () => {
expect(truncateToBytes('test string to be truncated', 10)).toEqual(
'test strin'
)
expect(truncateToBytes('😀😁😂🤣😃😄😅', 10)).toEqual('😀😁')
})
})

View File

@@ -0,0 +1,10 @@
import {truncateToBytes} from '../src/utils'
describe('truncate to bytes tests', () => {
test('unicode aware truncation to a number of bytes', async () => {
expect(truncateToBytes('test string to be truncated', 10)).toEqual(
'test strin'
)
expect(truncateToBytes('😀😁😂🤣😃😄😅', 10)).toEqual('😀😁')
})
})

60
dist/index.js vendored
View File

@@ -42,7 +42,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.updateRepositoryDescription = exports.getToken = void 0; exports.updateRepositoryDescription = exports.getToken = void 0;
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const fetch = __importStar(__nccwpck_require__(467)); const fetch = __importStar(__nccwpck_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 = {
@@ -69,7 +68,7 @@ function updateRepositoryDescription(token, repository, description, fullDescrip
full_description: fullDescription full_description: fullDescription
}; };
if (description) { if (description) {
body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS); body['description'] = description;
} }
yield fetch(`https://hub.docker.com/v2/repositories/${repository}`, { yield fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
method: 'patch', method: 'patch',
@@ -238,12 +237,9 @@ const core = __importStar(__nccwpck_require__(2186));
const inputHelper = __importStar(__nccwpck_require__(5480)); const inputHelper = __importStar(__nccwpck_require__(5480));
const dockerhubHelper = __importStar(__nccwpck_require__(1812)); const dockerhubHelper = __importStar(__nccwpck_require__(1812));
const readmeHelper = __importStar(__nccwpck_require__(3367)); const readmeHelper = __importStar(__nccwpck_require__(3367));
const utils = __importStar(__nccwpck_require__(918));
const util_1 = __nccwpck_require__(3837); const util_1 = __nccwpck_require__(3837);
function getErrorMessage(error) { const SHORT_DESCRIPTION_MAX_BYTES = 100;
if (error instanceof Error)
return error.message;
return String(error);
}
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
@@ -254,17 +250,23 @@ function run() {
core.info('Reading description source file'); core.info('Reading description source file');
const readmeContent = yield readmeHelper.getReadmeContent(inputs.readmeFilepath, inputs.enableUrlCompletion, inputs.imageExtensions); const readmeContent = yield readmeHelper.getReadmeContent(inputs.readmeFilepath, inputs.enableUrlCompletion, inputs.imageExtensions);
core.debug(readmeContent); 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.`);
}
core.debug(`Truncated short description: ${truncatedShortDescription}`);
// 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.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, inputs.shortDescription, readmeContent); yield dockerhubHelper.updateRepositoryDescription(token, inputs.repository, truncatedShortDescription, readmeContent);
core.info('Request successful'); core.info('Request successful');
} }
catch (error) { catch (error) {
core.debug((0, util_1.inspect)(error)); core.debug((0, util_1.inspect)(error));
core.setFailed(getErrorMessage(error)); core.setFailed(utils.getErrorMessage(error));
} }
}); });
} }
@@ -311,10 +313,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}); });
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.completeRelativeUrls = exports.getReadmeContent = exports.truncateToBytes = exports.ENABLE_URL_COMPLETION_DEFAULT = exports.IMAGE_EXTENSIONS_DEFAULT = exports.README_FILEPATH_DEFAULT = void 0; exports.completeRelativeUrls = exports.getReadmeContent = exports.ENABLE_URL_COMPLETION_DEFAULT = exports.IMAGE_EXTENSIONS_DEFAULT = exports.README_FILEPATH_DEFAULT = void 0;
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const fs = __importStar(__nccwpck_require__(7147)); const fs = __importStar(__nccwpck_require__(7147));
const unicodeSubstring = __nccwpck_require__(6986); const utils = __importStar(__nccwpck_require__(918));
exports.README_FILEPATH_DEFAULT = './README.md'; exports.README_FILEPATH_DEFAULT = './README.md';
exports.IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp'; exports.IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp';
exports.ENABLE_URL_COMPLETION_DEFAULT = false; exports.ENABLE_URL_COMPLETION_DEFAULT = false;
@@ -323,14 +325,6 @@ const REPOSITORY_URL = `${process.env['GITHUB_SERVER_URL']}/${process.env['GITHU
const BLOB_PREFIX = `${REPOSITORY_URL}/blob/${process.env['GITHUB_REF_NAME']}/`; const BLOB_PREFIX = `${REPOSITORY_URL}/blob/${process.env['GITHUB_REF_NAME']}/`;
const RAW_PREFIX = `${REPOSITORY_URL}/raw/${process.env['GITHUB_REF_NAME']}/`; const RAW_PREFIX = `${REPOSITORY_URL}/raw/${process.env['GITHUB_REF_NAME']}/`;
const MAX_BYTES = 25000; const MAX_BYTES = 25000;
function truncateToBytes(s, n) {
let len = n;
while (Buffer.byteLength(s) > n) {
s = unicodeSubstring(s, 0, len--);
}
return s;
}
exports.truncateToBytes = truncateToBytes;
function getReadmeContent(readmeFilepath, enableUrlCompletion, imageExtensions) { function getReadmeContent(readmeFilepath, enableUrlCompletion, imageExtensions) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// Fetch the readme content // Fetch the readme content
@@ -338,7 +332,7 @@ function getReadmeContent(readmeFilepath, enableUrlCompletion, imageExtensions)
encoding: 'utf8' encoding: 'utf8'
}); });
readmeContent = completeRelativeUrls(readmeContent, readmeFilepath, enableUrlCompletion, imageExtensions); readmeContent = completeRelativeUrls(readmeContent, readmeFilepath, enableUrlCompletion, imageExtensions);
const truncatedReadmeContent = truncateToBytes(readmeContent, MAX_BYTES); const truncatedReadmeContent = utils.truncateToBytes(readmeContent, MAX_BYTES);
if (truncatedReadmeContent.length !== readmeContent.length) { if (truncatedReadmeContent.length !== readmeContent.length) {
core.warning(`The README content exceeds DockerHub's limit and has been truncated to ${MAX_BYTES} bytes.`); core.warning(`The README content exceeds DockerHub's limit and has been truncated to ${MAX_BYTES} bytes.`);
} }
@@ -446,6 +440,32 @@ function getRelativeUrlRules() {
} }
/***/ }),
/***/ 918:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.truncateToBytes = exports.getErrorMessage = void 0;
const unicodeSubstring = __nccwpck_require__(6986);
function getErrorMessage(error) {
if (error instanceof Error)
return error.message;
return String(error);
}
exports.getErrorMessage = getErrorMessage;
function truncateToBytes(s, n) {
let len = n;
while (Buffer.byteLength(s) > n) {
s = unicodeSubstring(s, 0, len--);
}
return s;
}
exports.truncateToBytes = truncateToBytes;
/***/ }), /***/ }),
/***/ 7351: /***/ 7351:

147
package-lock.json generated
View File

@@ -15,16 +15,16 @@
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.3", "@types/jest": "^27.0.3",
"@types/node": "^16.18.14", "@types/node": "^16.18.23",
"@typescript-eslint/parser": "^5.54.0", "@typescript-eslint/parser": "^5.57.1",
"@vercel/ncc": "^0.36.1", "@vercel/ncc": "^0.36.1",
"eslint": "^8.35.0", "eslint": "^8.38.0",
"eslint-plugin-github": "^4.6.1", "eslint-plugin-github": "^4.7.0",
"eslint-plugin-jest": "^25.7.0", "eslint-plugin-jest": "^25.7.0",
"jest": "^27.5.1", "jest": "^27.5.1",
"jest-circus": "^27.5.1", "jest-circus": "^27.5.1",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "^2.8.4", "prettier": "^2.8.7",
"ts-jest": "^27.1.5", "ts-jest": "^27.1.5",
"typescript": "^4.9.5" "typescript": "^4.9.5"
} }
@@ -683,15 +683,39 @@
"integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==",
"dev": true "dev": true
}, },
"node_modules/@eslint-community/eslint-utils": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.2.0.tgz",
"integrity": "sha512-gB8T4H4DEfX2IV9zGDJPOBgP1e/DbfCPDTtEqUMckpvzS1OYtva8JdFYBqMwYk7xAQ429WGF/UPqn8uQ//h2vQ==",
"dev": true,
"dependencies": {
"eslint-visitor-keys": "^3.3.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"peerDependencies": {
"eslint": "^6.0.0 || ^7.0.0 || >=8.0.0"
}
},
"node_modules/@eslint-community/regexpp": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.4.0.tgz",
"integrity": "sha512-A9983Q0LnDGdLPjxyXQ00sbV+K+O+ko2Dr+CZigbHWtX9pNfxlaBkMR8X1CztI73zuEyEBXTVjx7CE+/VSwDiQ==",
"dev": true,
"engines": {
"node": "^12.0.0 || ^14.0.0 || >=16.0.0"
}
},
"node_modules/@eslint/eslintrc": { "node_modules/@eslint/eslintrc": {
"version": "2.0.0", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.0.tgz", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.2.tgz",
"integrity": "sha512-fluIaaV+GyV24CCu/ggiHdV+j4RNh85yQnAYS/G2mZODZgGmmlrgCydjUcV3YvxCm9x8nMAfThsqTni4KiXT4A==", "integrity": "sha512-3W4f5tDUra+pA+FzgugqL2pRimUTDJWKr7BINqOpkZrC0uYI0NIc0/JFgBROCU07HR6GieA5m3/rsPIhDmCXTQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"ajv": "^6.12.4", "ajv": "^6.12.4",
"debug": "^4.3.2", "debug": "^4.3.2",
"espree": "^9.4.0", "espree": "^9.5.1",
"globals": "^13.19.0", "globals": "^13.19.0",
"ignore": "^5.2.0", "ignore": "^5.2.0",
"import-fresh": "^3.2.1", "import-fresh": "^3.2.1",
@@ -707,9 +731,9 @@
} }
}, },
"node_modules/@eslint/js": { "node_modules/@eslint/js": {
"version": "8.35.0", "version": "8.38.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.35.0.tgz", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.38.0.tgz",
"integrity": "sha512-JXdzbRiWclLVoD8sNUjR443VVlYqiYmDVT6rGUEIEHU5YJW0gaVZwV2xgM7D4arkvASqD0IlLUVjHiFuxaftRw==", "integrity": "sha512-IoD2MfUnOV58ghIHCiil01PcohxjbYR/qCxsoC+xNgUwh1EY8jOOrYmu3d3a71+tJJ23uscEV4X2HJWMsPJu4g==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@@ -1270,9 +1294,9 @@
"dev": true "dev": true
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "16.18.14", "version": "16.18.23",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.14.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.23.tgz",
"integrity": "sha512-wvzClDGQXOCVNU4APPopC2KtMYukaF1MN/W3xAmslx22Z4/IF1/izDMekuyoUlwfnDHYCIZGaj7jMwnJKBTxKw==", "integrity": "sha512-XAMpaw1s1+6zM+jn2tmw8MyaRDIJfXxqmIQIS0HfoGYPuf7dUWeiUKopwq13KFX9lEp1+THGtlaaYx39Nxr58g==",
"dev": true "dev": true
}, },
"node_modules/@types/prettier": { "node_modules/@types/prettier": {
@@ -1381,14 +1405,14 @@
} }
}, },
"node_modules/@typescript-eslint/parser": { "node_modules/@typescript-eslint/parser": {
"version": "5.54.0", "version": "5.57.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.54.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.57.1.tgz",
"integrity": "sha512-aAVL3Mu2qTi+h/r04WI/5PfNWvO6pdhpeMRWk9R7rEV4mwJNzoWf5CCU5vDKBsPIFQFjEq1xg7XBI2rjiMXQbQ==", "integrity": "sha512-hlA0BLeVSA/wBPKdPGxoVr9Pp6GutGoY380FEhbVi0Ph4WNe8kLvqIRx76RSQt1lynZKfrXKs0/XeEk4zZycuA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/scope-manager": "5.54.0", "@typescript-eslint/scope-manager": "5.57.1",
"@typescript-eslint/types": "5.54.0", "@typescript-eslint/types": "5.57.1",
"@typescript-eslint/typescript-estree": "5.54.0", "@typescript-eslint/typescript-estree": "5.57.1",
"debug": "^4.3.4" "debug": "^4.3.4"
}, },
"engines": { "engines": {
@@ -1408,13 +1432,13 @@
} }
}, },
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/scope-manager": { "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/scope-manager": {
"version": "5.54.0", "version": "5.57.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.54.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.57.1.tgz",
"integrity": "sha512-VTPYNZ7vaWtYna9M4oD42zENOBrb+ZYyCNdFs949GcN8Miwn37b8b7eMj+EZaq7VK9fx0Jd+JhmkhjFhvnovhg==", "integrity": "sha512-N/RrBwEUKMIYxSKl0oDK5sFVHd6VI7p9K5MyUlVYAY6dyNb/wHUqndkTd3XhpGlXgnQsBkRZuu4f9kAHghvgPw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.54.0", "@typescript-eslint/types": "5.57.1",
"@typescript-eslint/visitor-keys": "5.54.0" "@typescript-eslint/visitor-keys": "5.57.1"
}, },
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@@ -1425,9 +1449,9 @@
} }
}, },
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/types": { "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/types": {
"version": "5.54.0", "version": "5.57.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.54.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.57.1.tgz",
"integrity": "sha512-nExy+fDCBEgqblasfeE3aQ3NuafBUxZxgxXcYfzYRZFHdVvk5q60KhCSkG0noHgHRo/xQ/BOzURLZAafFpTkmQ==", "integrity": "sha512-bSs4LOgyV3bJ08F5RDqO2KXqg3WAdwHCu06zOqcQ6vqbTJizyBhuh1o1ImC69X4bV2g1OJxbH71PJqiO7Y1RuA==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@@ -1438,13 +1462,13 @@
} }
}, },
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": { "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": {
"version": "5.54.0", "version": "5.57.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.54.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.57.1.tgz",
"integrity": "sha512-X2rJG97Wj/VRo5YxJ8Qx26Zqf0RRKsVHd4sav8NElhbZzhpBI8jU54i6hfo9eheumj4oO4dcRN1B/zIVEqR/MQ==", "integrity": "sha512-A2MZqD8gNT0qHKbk2wRspg7cHbCDCk2tcqt6ScCFLr5Ru8cn+TCfM786DjPhqwseiS+PrYwcXht5ztpEQ6TFTw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.54.0", "@typescript-eslint/types": "5.57.1",
"@typescript-eslint/visitor-keys": "5.54.0", "@typescript-eslint/visitor-keys": "5.57.1",
"debug": "^4.3.4", "debug": "^4.3.4",
"globby": "^11.1.0", "globby": "^11.1.0",
"is-glob": "^4.0.3", "is-glob": "^4.0.3",
@@ -1465,12 +1489,12 @@
} }
}, },
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/visitor-keys": { "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/visitor-keys": {
"version": "5.54.0", "version": "5.57.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.54.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.57.1.tgz",
"integrity": "sha512-xu4wT7aRCakGINTLGeyGqDn+78BwFlggwBjnHa1ar/KaGagnmwLYmlrXIrgAaQ3AE1Vd6nLfKASm7LrFHNbKGA==", "integrity": "sha512-RjQrAniDU0CEk5r7iphkm731zKlFiUjvcBS2yHAg8WWqFMCaCrD0rKEVOMUyMMcbGPZ0bPp56srkGWrgfZqLRA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.54.0", "@typescript-eslint/types": "5.57.1",
"eslint-visitor-keys": "^3.3.0" "eslint-visitor-keys": "^3.3.0"
}, },
"engines": { "engines": {
@@ -2605,13 +2629,15 @@
} }
}, },
"node_modules/eslint": { "node_modules/eslint": {
"version": "8.35.0", "version": "8.38.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.35.0.tgz", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.38.0.tgz",
"integrity": "sha512-BxAf1fVL7w+JLRQhWl2pzGeSiGqbWumV4WNvc9Rhp6tiCtm4oHnyPBSEtMGZwrQgudFQ+otqzWoPB7x+hxoWsw==", "integrity": "sha512-pIdsD2jwlUGf/U38Jv97t8lq6HpaU/G9NKbYmpWpZGw3LdTNhZLbJePqxOXGB5+JEKfOPU/XLxYxFh03nr1KTg==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@eslint/eslintrc": "^2.0.0", "@eslint-community/eslint-utils": "^4.2.0",
"@eslint/js": "8.35.0", "@eslint-community/regexpp": "^4.4.0",
"@eslint/eslintrc": "^2.0.2",
"@eslint/js": "8.38.0",
"@humanwhocodes/config-array": "^0.11.8", "@humanwhocodes/config-array": "^0.11.8",
"@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/module-importer": "^1.0.1",
"@nodelib/fs.walk": "^1.2.8", "@nodelib/fs.walk": "^1.2.8",
@@ -2622,9 +2648,8 @@
"doctrine": "^3.0.0", "doctrine": "^3.0.0",
"escape-string-regexp": "^4.0.0", "escape-string-regexp": "^4.0.0",
"eslint-scope": "^7.1.1", "eslint-scope": "^7.1.1",
"eslint-utils": "^3.0.0", "eslint-visitor-keys": "^3.4.0",
"eslint-visitor-keys": "^3.3.0", "espree": "^9.5.1",
"espree": "^9.4.0",
"esquery": "^1.4.2", "esquery": "^1.4.2",
"esutils": "^2.0.2", "esutils": "^2.0.2",
"fast-deep-equal": "^3.1.3", "fast-deep-equal": "^3.1.3",
@@ -2646,7 +2671,6 @@
"minimatch": "^3.1.2", "minimatch": "^3.1.2",
"natural-compare": "^1.4.0", "natural-compare": "^1.4.0",
"optionator": "^0.9.1", "optionator": "^0.9.1",
"regexpp": "^3.2.0",
"strip-ansi": "^6.0.1", "strip-ansi": "^6.0.1",
"strip-json-comments": "^3.1.0", "strip-json-comments": "^3.1.0",
"text-table": "^0.2.0" "text-table": "^0.2.0"
@@ -2771,9 +2795,9 @@
} }
}, },
"node_modules/eslint-plugin-github": { "node_modules/eslint-plugin-github": {
"version": "4.6.1", "version": "4.7.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-github/-/eslint-plugin-github-4.6.1.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-github/-/eslint-plugin-github-4.7.0.tgz",
"integrity": "sha512-AjCxE+2JmT+ppq3AVNra3iJ0BTAj6rYmtHJtkEcIEtrBHVi9xmCl5ZdIYLh7U/YKGT2cttdcYvbe59HEYW67KA==", "integrity": "sha512-SIFSy6IXtN3aGQ6YyFWg/oxRUyAcYwg5G0wh+ov1HQCvmp+Pzs1GzeVjU8QcIQSSJfverQzuxWrJCAln/d2PuQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@github/browserslist-config": "^1.0.0", "@github/browserslist-config": "^1.0.0",
@@ -3013,12 +3037,15 @@
} }
}, },
"node_modules/eslint-visitor-keys": { "node_modules/eslint-visitor-keys": {
"version": "3.3.0", "version": "3.4.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.0.tgz",
"integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", "integrity": "sha512-HPpKPUBQcAsZOsHAFwTtIKcYlCje62XB7SEAcxjtmW6TD1WVpkS6i6/hOVtTZIl4zGj/mBqpFVGvaDneik+VoQ==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"funding": {
"url": "https://opencollective.com/eslint"
} }
}, },
"node_modules/eslint/node_modules/find-up": { "node_modules/eslint/node_modules/find-up": {
@@ -3104,14 +3131,14 @@
} }
}, },
"node_modules/espree": { "node_modules/espree": {
"version": "9.4.1", "version": "9.5.1",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.4.1.tgz", "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.1.tgz",
"integrity": "sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==", "integrity": "sha512-5yxtHSZXRSW5pvv3hAlXM5+/Oswi1AUFqBmbibKb5s6bp3rGIDkyXU6xCoyuuLhijr4SFwPrXRoZjz0AZDN9tg==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"acorn": "^8.8.0", "acorn": "^8.8.0",
"acorn-jsx": "^5.3.2", "acorn-jsx": "^5.3.2",
"eslint-visitor-keys": "^3.3.0" "eslint-visitor-keys": "^3.4.0"
}, },
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@@ -5685,9 +5712,9 @@
} }
}, },
"node_modules/prettier": { "node_modules/prettier": {
"version": "2.8.4", "version": "2.8.7",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.4.tgz", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.7.tgz",
"integrity": "sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==", "integrity": "sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw==",
"dev": true, "dev": true,
"bin": { "bin": {
"prettier": "bin-prettier.js" "prettier": "bin-prettier.js"

View File

@@ -33,16 +33,16 @@
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.3", "@types/jest": "^27.0.3",
"@types/node": "^16.18.14", "@types/node": "^16.18.23",
"@typescript-eslint/parser": "^5.54.0", "@typescript-eslint/parser": "^5.57.1",
"@vercel/ncc": "^0.36.1", "@vercel/ncc": "^0.36.1",
"eslint": "^8.35.0", "eslint": "^8.38.0",
"eslint-plugin-github": "^4.6.1", "eslint-plugin-github": "^4.7.0",
"eslint-plugin-jest": "^25.7.0", "eslint-plugin-jest": "^25.7.0",
"jest": "^27.5.1", "jest": "^27.5.1",
"jest-circus": "^27.5.1", "jest-circus": "^27.5.1",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "^2.8.4", "prettier": "^2.8.7",
"ts-jest": "^27.1.5", "ts-jest": "^27.1.5",
"typescript": "^4.9.5" "typescript": "^4.9.5"
} }

View File

@@ -1,8 +1,6 @@
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
@@ -36,7 +34,7 @@ export async function updateRepositoryDescription(
full_description: fullDescription full_description: fullDescription
} }
if (description) { if (description) {
body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS) body['description'] = description
} }
await fetch(`https://hub.docker.com/v2/repositories/${repository}`, { await fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
method: 'patch', method: 'patch',

View File

@@ -2,12 +2,10 @@ import * as core from '@actions/core'
import * as inputHelper from './input-helper' import * as inputHelper from './input-helper'
import * as dockerhubHelper from './dockerhub-helper' import * as dockerhubHelper from './dockerhub-helper'
import * as readmeHelper from './readme-helper' import * as readmeHelper from './readme-helper'
import * as utils from './utils'
import {inspect} from 'util' import {inspect} from 'util'
function getErrorMessage(error: unknown) { const SHORT_DESCRIPTION_MAX_BYTES = 100
if (error instanceof Error) return error.message
return String(error)
}
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
@@ -25,6 +23,18 @@ async function run(): Promise<void> {
) )
core.debug(readmeContent) 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.`
)
}
core.debug(`Truncated short description: ${truncatedShortDescription}`)
// 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(
@@ -36,13 +46,13 @@ async function run(): Promise<void> {
await dockerhubHelper.updateRepositoryDescription( await dockerhubHelper.updateRepositoryDescription(
token, token,
inputs.repository, inputs.repository,
inputs.shortDescription, truncatedShortDescription,
readmeContent readmeContent
) )
core.info('Request successful') core.info('Request successful')
} catch (error) { } catch (error) {
core.debug(inspect(error)) core.debug(inspect(error))
core.setFailed(getErrorMessage(error)) core.setFailed(utils.getErrorMessage(error))
} }
} }

View File

@@ -1,6 +1,6 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import * as fs from 'fs' import * as fs from 'fs'
import unicodeSubstring = require('unicode-substring') import * as utils from './utils'
export const README_FILEPATH_DEFAULT = './README.md' export const README_FILEPATH_DEFAULT = './README.md'
export const IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp' export const IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp'
@@ -28,14 +28,6 @@ type Rule = {
absUrlPrefix: string absUrlPrefix: string
} }
export function truncateToBytes(s: string, n: number): string {
let len = n
while (Buffer.byteLength(s) > n) {
s = unicodeSubstring(s, 0, len--)
}
return s
}
export async function getReadmeContent( export async function getReadmeContent(
readmeFilepath: string, readmeFilepath: string,
enableUrlCompletion: boolean, enableUrlCompletion: boolean,
@@ -53,7 +45,7 @@ export async function getReadmeContent(
imageExtensions imageExtensions
) )
const truncatedReadmeContent = truncateToBytes(readmeContent, MAX_BYTES) const truncatedReadmeContent = utils.truncateToBytes(readmeContent, MAX_BYTES)
if (truncatedReadmeContent.length !== readmeContent.length) { if (truncatedReadmeContent.length !== readmeContent.length) {
core.warning( core.warning(
`The README content exceeds DockerHub's limit and has been truncated to ${MAX_BYTES} bytes.` `The README content exceeds DockerHub's limit and has been truncated to ${MAX_BYTES} bytes.`

14
src/utils.ts Normal file
View File

@@ -0,0 +1,14 @@
import unicodeSubstring = require('unicode-substring')
export function getErrorMessage(error: unknown) {
if (error instanceof Error) return error.message
return String(error)
}
export function truncateToBytes(s: string, n: number): string {
let len = n
while (Buffer.byteLength(s) > n) {
s = unicodeSubstring(s, 0, len--)
}
return s
}