Skip to content

Commit 033d20d

Browse files
committed
build: build custom header implement
- c873eaf - test it
1 parent c873eaf commit 033d20d

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

.github/workflows/comment_on_pull_request.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ jobs:
1010
- uses: ./
1111
with:
1212
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
header: FromPR
1314
message: |
1415
Test ${{ github.sha }} is successfully ended.
16+
This is message from PR.

.github/workflows/comment_on_push.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ jobs:
1717
number: ${{ steps.finder.outputs.pr }}
1818
message: |
1919
Test ${{ github.sha }} is successfully ended.
20+
This is message from push.

lib/comment.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
99
});
1010
};
1111
Object.defineProperty(exports, "__esModule", { value: true });
12-
const HEADER = "<!-- Sticky Pull Request Comment -->";
13-
function findPreviousComment(octokit, repo, issue_number) {
12+
function headerComment(header) {
13+
return `<!-- Sticky Pull Request Comment${header} -->`;
14+
}
15+
function findPreviousComment(octokit, repo, issue_number, header) {
1416
return __awaiter(this, void 0, void 0, function* () {
1517
const { data: comments } = yield octokit.issues.listComments(Object.assign(Object.assign({}, repo), { issue_number }));
16-
return comments.find(comment => comment.body.startsWith(HEADER));
18+
const h = headerComment(header);
19+
return comments.find(comment => comment.body.startsWith(h));
1720
});
1821
}
1922
exports.findPreviousComment = findPreviousComment;
20-
function updateComment(octokit, repo, comment_id, body) {
23+
function updateComment(octokit, repo, comment_id, body, header) {
2124
return __awaiter(this, void 0, void 0, function* () {
22-
yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: `${HEADER}\n${body}` }));
25+
yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: `${headerComment(header)}\n${body}` }));
2326
});
2427
}
2528
exports.updateComment = updateComment;
26-
function createComment(octokit, repo, issue_number, body) {
29+
function createComment(octokit, repo, issue_number, body, header) {
2730
return __awaiter(this, void 0, void 0, function* () {
28-
yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: `${HEADER}\n${body}` }));
31+
yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: `${headerComment(header)}\n${body}` }));
2932
});
3033
}
3134
exports.createComment = createComment;

lib/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ function run() {
3131
try {
3232
const repo = github_1.context.repo;
3333
const body = core.getInput("message", { required: true });
34+
const header = core.getInput("header", { required: false }) || "";
3435
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
3536
const octokit = new github_1.GitHub(githubToken);
36-
const previous = yield comment_1.findPreviousComment(octokit, repo, number);
37+
const previous = yield comment_1.findPreviousComment(octokit, repo, number, header);
3738
if (previous) {
38-
yield comment_1.updateComment(octokit, repo, previous.id, body);
39+
yield comment_1.updateComment(octokit, repo, previous.id, body, header);
3940
}
4041
else {
41-
yield comment_1.createComment(octokit, repo, number, body);
42+
yield comment_1.createComment(octokit, repo, number, body, header);
4243
}
4344
}
4445
catch ({ message }) {

src/comment.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
function headerComment(header) {
2+
return `<!-- Sticky Pull Request Comment${header} -->`;
3+
}
4+
15
export async function findPreviousComment(octokit, repo, issue_number, header) {
26
const { data: comments } = await octokit.issues.listComments({
37
...repo,
@@ -20,7 +24,3 @@ export async function createComment(octokit, repo, issue_number, body, header) {
2024
body: `${headerComment(header)}\n${body}`
2125
});
2226
}
23-
24-
function headerComment(header) {
25-
return `<!-- Sticky Pull Request Comment${header} -->`;
26-
}

0 commit comments

Comments
 (0)