From 033d20d1209922fd102168fa477d8c4755909aba Mon Sep 17 00:00:00 2001 From: marocchino Date: Tue, 4 Feb 2020 17:24:40 +0900 Subject: [PATCH] build: build custom header implement - c873eaf - test it --- .github/workflows/comment_on_pull_request.yml | 2 ++ .github/workflows/comment_on_push.yml | 1 + lib/comment.js | 17 ++++++++++------- lib/main.js | 7 ++++--- src/comment.ts | 8 ++++---- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.github/workflows/comment_on_pull_request.yml b/.github/workflows/comment_on_pull_request.yml index 5bbf51f..9e9384f 100644 --- a/.github/workflows/comment_on_pull_request.yml +++ b/.github/workflows/comment_on_pull_request.yml @@ -10,5 +10,7 @@ jobs: - uses: ./ with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + header: FromPR message: | Test ${{ github.sha }} is successfully ended. + This is message from PR. diff --git a/.github/workflows/comment_on_push.yml b/.github/workflows/comment_on_push.yml index 6524873..22d4e47 100644 --- a/.github/workflows/comment_on_push.yml +++ b/.github/workflows/comment_on_push.yml @@ -17,3 +17,4 @@ jobs: number: ${{ steps.finder.outputs.pr }} message: | Test ${{ github.sha }} is successfully ended. + This is message from push. diff --git a/lib/comment.js b/lib/comment.js index e287e6b..2e4aabb 100644 --- a/lib/comment.js +++ b/lib/comment.js @@ -9,23 +9,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); -const HEADER = ""; -function findPreviousComment(octokit, repo, issue_number) { +function headerComment(header) { + return ``; +} +function findPreviousComment(octokit, repo, issue_number, header) { return __awaiter(this, void 0, void 0, function* () { const { data: comments } = yield octokit.issues.listComments(Object.assign(Object.assign({}, repo), { issue_number })); - return comments.find(comment => comment.body.startsWith(HEADER)); + const h = headerComment(header); + return comments.find(comment => comment.body.startsWith(h)); }); } exports.findPreviousComment = findPreviousComment; -function updateComment(octokit, repo, comment_id, body) { +function updateComment(octokit, repo, comment_id, body, header) { return __awaiter(this, void 0, void 0, function* () { - yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: `${HEADER}\n${body}` })); + yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: `${headerComment(header)}\n${body}` })); }); } exports.updateComment = updateComment; -function createComment(octokit, repo, issue_number, body) { +function createComment(octokit, repo, issue_number, body, header) { return __awaiter(this, void 0, void 0, function* () { - yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: `${HEADER}\n${body}` })); + yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: `${headerComment(header)}\n${body}` })); }); } exports.createComment = createComment; diff --git a/lib/main.js b/lib/main.js index 8f5ac6c..913c4aa 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,14 +31,15 @@ function run() { try { const repo = github_1.context.repo; const body = core.getInput("message", { required: true }); + const header = core.getInput("header", { required: false }) || ""; const githubToken = core.getInput("GITHUB_TOKEN", { required: true }); const octokit = new github_1.GitHub(githubToken); - const previous = yield comment_1.findPreviousComment(octokit, repo, number); + const previous = yield comment_1.findPreviousComment(octokit, repo, number, header); if (previous) { - yield comment_1.updateComment(octokit, repo, previous.id, body); + yield comment_1.updateComment(octokit, repo, previous.id, body, header); } else { - yield comment_1.createComment(octokit, repo, number, body); + yield comment_1.createComment(octokit, repo, number, body, header); } } catch ({ message }) { diff --git a/src/comment.ts b/src/comment.ts index 549a5f1..7544984 100644 --- a/src/comment.ts +++ b/src/comment.ts @@ -1,3 +1,7 @@ +function headerComment(header) { + return ``; +} + export async function findPreviousComment(octokit, repo, issue_number, header) { const { data: comments } = await octokit.issues.listComments({ ...repo, @@ -20,7 +24,3 @@ export async function createComment(octokit, repo, issue_number, body, header) { body: `${headerComment(header)}\n${body}` }); } - -function headerComment(header) { - return ``; -}