diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d3bd312..26ad82b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) ## [Unreleased] +## [1.1.0] - 2020-05-10 +## Added +* Add "overwrites-pull-request-comment" input + +### Changed +* Overwrite comment on pull request by default + - You can use `overwrites-pull-request-comment: false` not to overwrite +* Update dependencies + ## [1.0.13] - 2020-05-09 ### Changed * Update dependencies @@ -86,7 +95,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) * Deploy to Netlify * Comment on GitHub PR -[Unreleased]: https://github.com/nwtgck/actions-netlify/compare/v1.0.13...HEAD +[Unreleased]: https://github.com/nwtgck/actions-netlify/compare/v1.1.0...HEAD +[1.1.0]: https://github.com/nwtgck/actions-netlify/compare/v1.0.13...v1.1.0 [1.0.13]: https://github.com/nwtgck/actions-netlify/compare/v1.0.12...v1.0.13 [1.0.12]: https://github.com/nwtgck/actions-netlify/compare/v1.0.11...v1.0.12 [1.0.11]: https://github.com/nwtgck/actions-netlify/compare/v1.0.10...v1.0.11 diff --git a/README.md b/README.md index 665d791b..c89ee57f 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,15 @@ jobs: # ... - name: Deploy to Netlify - uses: nwtgck/actions-netlify@v1.0 + uses: nwtgck/actions-netlify@v1.1 with: publish-dir: './dist' production-branch: master github-token: ${{ secrets.GITHUB_TOKEN }} deploy-message: "Deploy from GitHub Actions" + enable-pull-request-comment: true + enable-commit-comment: true + overwrites-pull-request-comment: true env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} @@ -49,7 +52,8 @@ jobs: - `github-token: ${{ secrets.GITHUB_TOKEN }}` - `deploy-message` A custom deploy message to see on Netlify deployment (e.g. `${{ github.event.pull_request.title }}`) - `enable-pull-request-comment: true` Comment on pull request (default: true) -- `enable-commit-comment: true` Comment on GitHub commit (default) +- `enable-commit-comment: true` Comment on GitHub commit (default: true) +- `overwrites-pull-request-comment: true` Overwirtes comment on pull request (default: true) ### Outputs - `deploy-url` A deployment URL generated by Netlify diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index ede47523..6ba2b688 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -2,6 +2,144 @@ import {wait} from '../src/wait' import * as process from 'process' import * as cp from 'child_process' import * as path from 'path' +import {defaultInputs} from '../src/inputs' + +/** + * With input + * @param inputName + * @param value + * @param f + */ +export async function withInput( + inputName: string, + value: string, + f: () => void | Promise +): Promise { + // (from: https://github.com/actions/toolkit/blob/83dd3ef0f1e5bc93c5ab7072e1edf1715a01ba9d/packages/core/src/core.ts#L71) + const envName = `INPUT_${inputName.replace(/ /g, '_').toUpperCase()}` + process.env[envName] = value + await f() + // NOTE: Not sure this is correct deletion + delete process.env[envName] +} + +describe('defaultInputs', () => { + test('publishDir', () => { + withInput('publish-dir', './my_publish_dir', () => { + const publishDir: string = defaultInputs.publishDir() + expect(publishDir).toBe('./my_publish_dir') + }) + }) + + describe('deployMessage', () => { + test('it should be a string when specified', () => { + withInput('deploy-message', 'Deploy with GitHub Actions', () => { + const deployMessage: string | undefined = defaultInputs.deployMessage() + expect(deployMessage).toBe('Deploy with GitHub Actions') + }) + }) + + test('it should be undefined when not specified', () => { + const deployMessage: string | undefined = defaultInputs.deployMessage() + expect(deployMessage).toBe(undefined) + }) + }) + + describe('productionBranch', () => { + test('it should be a string when specified', () => { + withInput('production-branch', 'master', () => { + const productionBranch: + | string + | undefined = defaultInputs.productionBranch() + expect(productionBranch).toBe('master') + }) + }) + + test('it should be undefined when not specified', () => { + const deployMessage: string | undefined = defaultInputs.productionBranch() + expect(deployMessage).toBe(undefined) + }) + }) + + describe('enablePullRequestComment', () => { + test('it should be default value (true) when not specified', () => { + const b: boolean = defaultInputs.enablePullRequestComment() + expect(b).toBe(true) + }) + + test('it should be true when "true" specified', () => { + withInput('enable-pull-request-comment', 'true', () => { + const b: boolean = defaultInputs.enablePullRequestComment() + expect(b).toBe(true) + }) + }) + + test('it should be true when "false" specified', () => { + withInput('enable-pull-request-comment', 'false', () => { + const b: boolean = defaultInputs.enablePullRequestComment() + expect(b).toBe(false) + }) + }) + }) + + describe('enableCommitComment', () => { + test('it should be default value (true) when not specified', () => { + const b: boolean = defaultInputs.enableCommitComment() + expect(b).toBe(true) + }) + + test('it should be true when "true" specified', () => { + withInput('enable-commit-comment', 'true', () => { + const b: boolean = defaultInputs.enableCommitComment() + expect(b).toBe(true) + }) + }) + + test('it should be true when "false" specified', () => { + withInput('enable-commit-comment', 'false', () => { + const b: boolean = defaultInputs.enableCommitComment() + expect(b).toBe(false) + }) + }) + }) + + describe('enableCommitComment', () => { + test('it should be empty string when not specified', () => { + const t: string = defaultInputs.githubToken() + expect(t).toBe('') + }) + + test('it should be a string when specified', () => { + withInput('github-token', 'DUMMY_GITHUB_TOKEN', () => { + const t: string = defaultInputs.githubToken() + expect(t).toBe('DUMMY_GITHUB_TOKEN') + }) + }) + }) + + describe('overwritesPullRequestComment', () => { + test('it should be default value (true) when not specified', () => { + const b: boolean = defaultInputs.overwritesPullRequestComment() + expect(b).toBe(true) + }) + + test('it should be true when "true" specified', () => { + withInput('overwrites-pull-request-comment', 'true', () => { + const b: boolean = defaultInputs.overwritesPullRequestComment() + expect(b).toBe(true) + }) + }) + + test('it should be true when "false" specified', () => { + withInput('overwrites-pull-request-comment', 'false', () => { + const b: boolean = defaultInputs.overwritesPullRequestComment() + expect(b).toBe(false) + }) + }) + }) +}) + +// Old tests below test('throws invalid number', async () => { const input = parseInt('foo', 10) diff --git a/action.yml b/action.yml index 6a7c42a5..4b2f2e32 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,9 @@ inputs: enable-commit-comment: description: Enable commit comment required: false + overwrites-pull-request-comment: + description: Overwrites pull request comment + required: false outputs: deploy-url: description: Deploy URL diff --git a/dist/index.js b/dist/index.js index 1e5f876c..1eff73d4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -41876,7 +41876,27 @@ const core = __importStar(__webpack_require__(470)); const github_1 = __webpack_require__(469); const netlify_1 = __importDefault(__webpack_require__(326)); const path = __importStar(__webpack_require__(622)); -function run() { +const inputs_1 = __webpack_require__(840); +const commentIdentifierString = ''; +function findIssueComment(githubClient) { + return __awaiter(this, void 0, void 0, function* () { + const listCommentsRes = yield githubClient.issues.listComments({ + owner: github_1.context.issue.owner, + repo: github_1.context.issue.repo, + // eslint-disable-next-line @typescript-eslint/camelcase + issue_number: github_1.context.issue.number + }); + const comments = listCommentsRes.data; + for (const comment of comments) { + // If comment contains the comment identifier + if (comment.body.includes(commentIdentifierString)) { + return comment.id; + } + } + return undefined; + }); +} +function run(inputs) { return __awaiter(this, void 0, void 0, function* () { try { const netlifyAuthToken = process.env.NETLIFY_AUTH_TOKEN; @@ -41886,15 +41906,14 @@ function run() { process.stdout.write('Netlify credentials not provided, not deployable'); return; } - const dir = core.getInput('publish-dir', { required: true }); - const deployMessage = core.getInput('deploy-message') || undefined; - const productionBranch = core.getInput('production-branch'); - // Default: true - const enablePullRequestComment = (core.getInput('enable-pull-request-comment') || 'true') === 'true'; - // Default: true - const enableCommitComment = (core.getInput('enable-commit-comment') || 'true') === 'true'; - // NOTE: if production-branch is not specified, it is "", so isDraft is always true - const isDraft = github_1.context.ref !== `refs/heads/${productionBranch}`; + const dir = inputs.publishDir(); + const deployMessage = inputs.deployMessage(); + const productionBranch = inputs.productionBranch(); + const enablePullRequestComment = inputs.enablePullRequestComment(); + const enableCommitComment = inputs.enableCommitComment(); + const overwritesPullRequestComment = inputs.overwritesPullRequestComment(); + const isDraft = productionBranch === undefined || + github_1.context.ref !== `refs/heads/${productionBranch}`; // Create Netlify API client const netlifyClient = new netlify_1.default(netlifyAuthToken); // Resolve publish directory @@ -41913,8 +41932,9 @@ function run() { // Set the deploy URL to outputs for GitHub Actions core.setOutput('deploy-url', isDraft ? deploy.deploy.deploy_ssl_url : deploy.deploy.ssl_url); // Get GitHub token - const githubToken = core.getInput('github-token'); + const githubToken = inputs.githubToken(); if (githubToken !== '') { + const markdownComment = `${commentIdentifierString}\n${message}`; // Create GitHub client const githubClient = new github_1.GitHub(githubToken); if (enableCommitComment) { @@ -41923,7 +41943,7 @@ function run() { repo: github_1.context.repo.repo, // eslint-disable-next-line @typescript-eslint/camelcase commit_sha: github_1.context.sha, - body: message + body: markdownComment }; // TODO: Remove try // NOTE: try-catch is experimentally used because commit message may not be done in some conditions. @@ -41938,13 +41958,30 @@ function run() { } // If it is a pull request and enable comment on pull request if (github_1.context.issue.number !== undefined && enablePullRequestComment) { + let commentId = undefined; + if (overwritesPullRequestComment) { + // Find issue comment + commentId = yield findIssueComment(githubClient); + } + // NOTE: if not overwrite, commentId is always undefined + if (commentId !== undefined) { + // Update comment of the deploy URL + yield githubClient.issues.updateComment({ + owner: github_1.context.issue.owner, + repo: github_1.context.issue.repo, + // eslint-disable-next-line @typescript-eslint/camelcase + comment_id: commentId, + body: markdownComment + }); + return; + } // Comment the deploy URL yield githubClient.issues.createComment({ // eslint-disable-next-line @typescript-eslint/camelcase issue_number: github_1.context.issue.number, owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, - body: message + body: markdownComment }); } } @@ -41954,7 +41991,7 @@ function run() { } }); } -run(); +run(inputs_1.defaultInputs); /***/ }), @@ -75483,7 +75520,7 @@ module.exports = setup; /* 487 */ /***/ (function(module) { -module.exports = {"_from":"@typescript-eslint/typescript-estree@2.31.0","_id":"@typescript-eslint/typescript-estree@2.31.0","_inBundle":false,"_integrity":"sha512-vxW149bXFXXuBrAak0eKHOzbcu9cvi6iNcJDzEtOkRwGHxJG15chiAQAwhLOsk+86p9GTr/TziYvw+H9kMaIgA==","_location":"/@typescript-eslint/typescript-estree","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"@typescript-eslint/typescript-estree@2.31.0","name":"@typescript-eslint/typescript-estree","escapedName":"@typescript-eslint%2ftypescript-estree","scope":"@typescript-eslint","rawSpec":"2.31.0","saveSpec":null,"fetchSpec":"2.31.0"},"_requiredBy":["/@typescript-eslint/experimental-utils","/@typescript-eslint/parser","/detective-typescript"],"_resolved":"https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.31.0.tgz","_shasum":"ac536c2d46672aa1f27ba0ec2140d53670635cfd","_spec":"@typescript-eslint/typescript-estree@2.31.0","_where":"/Users/ryo/dev/actions/actions-netlify/node_modules/@typescript-eslint/parser","bugs":{"url":"https://github.com/typescript-eslint/typescript-eslint/issues"},"bundleDependencies":false,"dependencies":{"debug":"^4.1.1","eslint-visitor-keys":"^1.1.0","glob":"^7.1.6","is-glob":"^4.0.1","lodash":"^4.17.15","semver":"^6.3.0","tsutils":"^3.17.1"},"deprecated":false,"description":"A parser that converts TypeScript source code into an ESTree compatible form","devDependencies":{"@babel/code-frame":"^7.8.3","@babel/parser":"^7.8.3","@babel/types":"^7.8.3","@types/babel__code-frame":"^7.0.1","@types/debug":"^4.1.5","@types/glob":"^7.1.1","@types/is-glob":"^4.0.1","@types/lodash":"^4.14.149","@types/semver":"^6.2.0","@types/tmp":"^0.1.0","@typescript-eslint/shared-fixtures":"2.31.0","tmp":"^0.1.0","typescript":"*"},"engines":{"node":"^8.10.0 || ^10.13.0 || >=11.10.1"},"files":["dist","README.md","LICENSE"],"funding":{"type":"opencollective","url":"https://opencollective.com/typescript-eslint"},"gitHead":"176054c2171b682217d6855208e50b15e1712675","homepage":"https://github.com/typescript-eslint/typescript-eslint#readme","keywords":["ast","estree","ecmascript","javascript","typescript","parser","syntax"],"license":"BSD-2-Clause","main":"dist/parser.js","name":"@typescript-eslint/typescript-estree","peerDependenciesMeta":{"typescript":{"optional":true}},"repository":{"type":"git","url":"git+https://github.com/typescript-eslint/typescript-eslint.git","directory":"packages/typescript-estree"},"scripts":{"build":"tsc -b tsconfig.build.json","clean":"tsc -b tsconfig.build.json --clean","format":"prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore","lint":"eslint . --ext .js,.ts --ignore-path='../../.eslintignore'","test":"jest --coverage","typecheck":"tsc -p tsconfig.json --noEmit"},"types":"dist/parser.d.ts","version":"2.31.0"}; +module.exports = {"name":"@typescript-eslint/typescript-estree","version":"2.31.0","description":"A parser that converts TypeScript source code into an ESTree compatible form","main":"dist/parser.js","types":"dist/parser.d.ts","files":["dist","README.md","LICENSE"],"engines":{"node":"^8.10.0 || ^10.13.0 || >=11.10.1"},"repository":{"type":"git","url":"https://github.com/typescript-eslint/typescript-eslint.git","directory":"packages/typescript-estree"},"bugs":{"url":"https://github.com/typescript-eslint/typescript-eslint/issues"},"license":"BSD-2-Clause","keywords":["ast","estree","ecmascript","javascript","typescript","parser","syntax"],"scripts":{"build":"tsc -b tsconfig.build.json","clean":"tsc -b tsconfig.build.json --clean","format":"prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore","lint":"eslint . --ext .js,.ts --ignore-path='../../.eslintignore'","test":"jest --coverage","typecheck":"tsc -p tsconfig.json --noEmit"},"dependencies":{"debug":"^4.1.1","eslint-visitor-keys":"^1.1.0","glob":"^7.1.6","is-glob":"^4.0.1","lodash":"^4.17.15","semver":"^6.3.0","tsutils":"^3.17.1"},"devDependencies":{"@babel/code-frame":"^7.8.3","@babel/parser":"^7.8.3","@babel/types":"^7.8.3","@types/babel__code-frame":"^7.0.1","@types/debug":"^4.1.5","@types/glob":"^7.1.1","@types/is-glob":"^4.0.1","@types/lodash":"^4.14.149","@types/semver":"^6.2.0","@types/tmp":"^0.1.0","@typescript-eslint/shared-fixtures":"2.31.0","tmp":"^0.1.0","typescript":"*"},"peerDependenciesMeta":{"typescript":{"optional":true}},"funding":{"type":"opencollective","url":"https://opencollective.com/typescript-eslint"},"gitHead":"176054c2171b682217d6855208e50b15e1712675","_resolved":"https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.31.0.tgz","_integrity":"sha512-vxW149bXFXXuBrAak0eKHOzbcu9cvi6iNcJDzEtOkRwGHxJG15chiAQAwhLOsk+86p9GTr/TziYvw+H9kMaIgA==","_from":"@typescript-eslint/typescript-estree@2.31.0"}; /***/ }), /* 488 */ @@ -245551,7 +245588,49 @@ exports.ArraySet = ArraySet; /***/ }), /* 839 */, -/* 840 */, +/* 840 */ +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const core = __importStar(__webpack_require__(470)); +exports.defaultInputs = { + publishDir() { + return core.getInput('publish-dir', { required: true }); + }, + deployMessage() { + return core.getInput('deploy-message') || undefined; + }, + productionBranch() { + return core.getInput('production-branch') || undefined; + }, + enablePullRequestComment() { + // Default: true + return (core.getInput('enable-pull-request-comment') || 'true') === 'true'; + }, + enableCommitComment() { + // Default: true + return (core.getInput('enable-commit-comment') || 'true') === 'true'; + }, + githubToken() { + return core.getInput('github-token'); + }, + overwritesPullRequestComment() { + // Default: true + return ((core.getInput('overwrites-pull-request-comment') || 'true') === 'true'); + } +}; + + +/***/ }), /* 841 */, /* 842 */ /***/ (function(__unusedmodule, exports, __webpack_require__) { diff --git a/package-lock.json b/package-lock.json index cd30e821..a38dd045 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "actions-netlify", - "version": "1.0.13", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -8700,9 +8700,9 @@ } }, "ts-jest": { - "version": "25.5.0", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-25.5.0.tgz", - "integrity": "sha512-govrjbOk1UEzcJ5cX5k8X8IUtFuP3lp3mrF3ZuKtCdAOQzdeCM7qualhb/U8s8SWFwEDutOqfF5PLkJ+oaYD4w==", + "version": "25.5.1", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-25.5.1.tgz", + "integrity": "sha512-kHEUlZMK8fn8vkxDjwbHlxXRB9dHYpyzqKIGDNxbzs+Rz+ssNDSDNusEK8Fk/sDd4xE6iKoQLfFkFVaskmTJyw==", "dev": true, "requires": { "bs-logger": "0.x", diff --git a/package.json b/package.json index af6d396a..76bb330b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "actions-netlify", - "version": "1.0.13", + "version": "1.1.0", "private": true, "description": "GitHub Actions for Netlify", "main": "lib/main.js", @@ -40,7 +40,7 @@ "jest-circus": "^26.0.1", "js-yaml": "^3.13.1", "prettier": "^2.0.5", - "ts-jest": "^25.5.0", + "ts-jest": "^25.5.1", "typescript": "^3.8.3" } } diff --git a/src/inputs.ts b/src/inputs.ts new file mode 100644 index 00000000..964f76d1 --- /dev/null +++ b/src/inputs.ts @@ -0,0 +1,41 @@ +import * as core from '@actions/core' + +// Why use function rather than raw string? => Inputs should be lazy evaluated. +export interface Inputs { + publishDir(): string + deployMessage(): string | undefined + productionBranch(): string | undefined + enablePullRequestComment(): boolean + enableCommitComment(): boolean + githubToken(): string + overwritesPullRequestComment(): boolean +} + +export const defaultInputs: Inputs = { + publishDir() { + return core.getInput('publish-dir', {required: true}) + }, + deployMessage() { + return core.getInput('deploy-message') || undefined + }, + productionBranch() { + return core.getInput('production-branch') || undefined + }, + enablePullRequestComment() { + // Default: true + return (core.getInput('enable-pull-request-comment') || 'true') === 'true' + }, + enableCommitComment() { + // Default: true + return (core.getInput('enable-commit-comment') || 'true') === 'true' + }, + githubToken() { + return core.getInput('github-token') + }, + overwritesPullRequestComment() { + // Default: true + return ( + (core.getInput('overwrites-pull-request-comment') || 'true') === 'true' + ) + } +} diff --git a/src/main.ts b/src/main.ts index d02d1057..427fc7aa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,8 +2,32 @@ import * as core from '@actions/core' import {context, GitHub} from '@actions/github' import NetlifyAPI from 'netlify' import * as path from 'path' +import {defaultInputs, Inputs} from './inputs' -async function run(): Promise { +const commentIdentifierString = + '' + +async function findIssueComment( + githubClient: GitHub +): Promise { + const listCommentsRes = await githubClient.issues.listComments({ + owner: context.issue.owner, + repo: context.issue.repo, + // eslint-disable-next-line @typescript-eslint/camelcase + issue_number: context.issue.number + }) + + const comments = listCommentsRes.data + for (const comment of comments) { + // If comment contains the comment identifier + if (comment.body.includes(commentIdentifierString)) { + return comment.id + } + } + return undefined +} + +async function run(inputs: Inputs): Promise { try { const netlifyAuthToken = process.env.NETLIFY_AUTH_TOKEN const siteId = process.env.NETLIFY_SITE_ID @@ -12,17 +36,15 @@ async function run(): Promise { process.stdout.write('Netlify credentials not provided, not deployable') return } - const dir = core.getInput('publish-dir', {required: true}) - const deployMessage = core.getInput('deploy-message') || undefined - const productionBranch = core.getInput('production-branch') - // Default: true - const enablePullRequestComment: boolean = - (core.getInput('enable-pull-request-comment') || 'true') === 'true' - // Default: true - const enableCommitComment: boolean = - (core.getInput('enable-commit-comment') || 'true') === 'true' - // NOTE: if production-branch is not specified, it is "", so isDraft is always true - const isDraft: boolean = context.ref !== `refs/heads/${productionBranch}` + const dir = inputs.publishDir() + const deployMessage: string | undefined = inputs.deployMessage() + const productionBranch: string | undefined = inputs.productionBranch() + const enablePullRequestComment: boolean = inputs.enablePullRequestComment() + const enableCommitComment: boolean = inputs.enableCommitComment() + const overwritesPullRequestComment: boolean = inputs.overwritesPullRequestComment() + const isDraft: boolean = + productionBranch === undefined || + context.ref !== `refs/heads/${productionBranch}` // Create Netlify API client const netlifyClient = new NetlifyAPI(netlifyAuthToken) @@ -47,8 +69,10 @@ async function run(): Promise { ) // Get GitHub token - const githubToken = core.getInput('github-token') + const githubToken = inputs.githubToken() if (githubToken !== '') { + const markdownComment = `${commentIdentifierString}\n${message}` + // Create GitHub client const githubClient = new GitHub(githubToken) @@ -58,7 +82,7 @@ async function run(): Promise { repo: context.repo.repo, // eslint-disable-next-line @typescript-eslint/camelcase commit_sha: context.sha, - body: message + body: markdownComment } // TODO: Remove try // NOTE: try-catch is experimentally used because commit message may not be done in some conditions. @@ -73,13 +97,32 @@ async function run(): Promise { // If it is a pull request and enable comment on pull request if (context.issue.number !== undefined && enablePullRequestComment) { + let commentId: number | undefined = undefined + if (overwritesPullRequestComment) { + // Find issue comment + commentId = await findIssueComment(githubClient) + } + + // NOTE: if not overwrite, commentId is always undefined + if (commentId !== undefined) { + // Update comment of the deploy URL + await githubClient.issues.updateComment({ + owner: context.issue.owner, + repo: context.issue.repo, + // eslint-disable-next-line @typescript-eslint/camelcase + comment_id: commentId, + body: markdownComment + }) + return + } + // Comment the deploy URL await githubClient.issues.createComment({ // eslint-disable-next-line @typescript-eslint/camelcase issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: message + body: markdownComment }) } } @@ -88,4 +131,4 @@ async function run(): Promise { } } -run() +run(defaultInputs)