mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-14 12:31:14 +00:00
Merge pull request #140 from jakemhiller/hidden-comment-last
Update hidden identifier comment to come last instead of first
This commit is contained in:
commit
b0efe931e3
4 changed files with 44 additions and 24 deletions
|
|
@ -9,14 +9,20 @@ it("findPreviousComment", async () => {
|
|||
user: {
|
||||
login: "github-actions[bot]"
|
||||
},
|
||||
body: "<!-- Sticky Pull Request Comment -->\nprevious message"
|
||||
body: "previous message\n<!-- Sticky Pull Request Comment -->"
|
||||
};
|
||||
const commentWithCustomHeader = {
|
||||
user: {
|
||||
login: "github-actions[bot]"
|
||||
},
|
||||
body: "<!-- Sticky Pull Request CommentTypeA -->\nprevious message"
|
||||
body: "previous message\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||
};
|
||||
const headerFirstComment = {
|
||||
user: {
|
||||
login: "github-actions[bot]"
|
||||
},
|
||||
body: "<!-- Sticky Pull Request CommentLegacyComment -->\nheader first message"
|
||||
}
|
||||
const otherComments = [
|
||||
{
|
||||
user: {
|
||||
|
|
@ -28,14 +34,14 @@ it("findPreviousComment", async () => {
|
|||
user: {
|
||||
login: "github-actions[bot]"
|
||||
},
|
||||
body: "<!-- Sticky Pull Request CommentTypeB -->\nprevious message"
|
||||
}
|
||||
body: "previous message\n<!-- Sticky Pull Request CommentTypeB -->"
|
||||
},
|
||||
];
|
||||
const octokit = {
|
||||
issues: {
|
||||
listComments: jest.fn(() =>
|
||||
Promise.resolve({
|
||||
data: [commentWithCustomHeader, comment, ...otherComments]
|
||||
data: [commentWithCustomHeader, comment, headerFirstComment, ...otherComments]
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -45,6 +51,7 @@ it("findPreviousComment", async () => {
|
|||
expect(await findPreviousComment(octokit, repo, 123, "TypeA")).toBe(
|
||||
commentWithCustomHeader
|
||||
);
|
||||
expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(headerFirstComment)
|
||||
expect(octokit.issues.listComments).toBeCalledWith({ issue_number: 123 });
|
||||
});
|
||||
it("updateComment", async () => {
|
||||
|
|
@ -58,22 +65,22 @@ it("updateComment", async () => {
|
|||
).toBeUndefined();
|
||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
body: "<!-- Sticky Pull Request Comment -->\nhello there"
|
||||
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
||||
});
|
||||
expect(
|
||||
await updateComment(octokit, repo, 456, "hello there", "TypeA")
|
||||
).toBeUndefined();
|
||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
body: "<!-- Sticky Pull Request CommentTypeA -->\nhello there"
|
||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||
});
|
||||
|
||||
expect(
|
||||
await updateComment(octokit, repo, 456, "hello there", "TypeA", "<!-- Sticky Pull Request CommentTypeA -->\nhello there")
|
||||
await updateComment(octokit, repo, 456, "hello there", "TypeA", "hello there\n<!-- Sticky Pull Request CommentTypeA -->")
|
||||
).toBeUndefined();
|
||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
body: "<!-- Sticky Pull Request CommentTypeA -->\nhello there\nhello there"
|
||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there"
|
||||
});
|
||||
});
|
||||
it("createComment", async () => {
|
||||
|
|
@ -87,13 +94,13 @@ it("createComment", async () => {
|
|||
).toBeUndefined();
|
||||
expect(octokit.issues.createComment).toBeCalledWith({
|
||||
issue_number: 456,
|
||||
body: "<!-- Sticky Pull Request Comment -->\nhello there"
|
||||
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
||||
});
|
||||
expect(
|
||||
await createComment(octokit, repo, 456, "hello there", "TypeA")
|
||||
).toBeUndefined();
|
||||
expect(octokit.issues.createComment).toBeCalledWith({
|
||||
issue_number: 456,
|
||||
body: "<!-- Sticky Pull Request CommentTypeA -->\nhello there"
|
||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
||||
function headerComment(header) {
|
||||
return `<!-- Sticky Pull Request Comment${header} -->`;
|
||||
}
|
||||
|
|
@ -16,19 +17,19 @@ 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 }));
|
||||
const h = headerComment(header);
|
||||
return comments.find(comment => comment.body.startsWith(h));
|
||||
return comments.find(comment => comment.body.includes(h));
|
||||
});
|
||||
}
|
||||
exports.findPreviousComment = findPreviousComment;
|
||||
function updateComment(octokit, repo, comment_id, body, header, previousBody) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: previousBody ? `${previousBody}\n${body}` : `${headerComment(header)}\n${body}` }));
|
||||
yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}` }));
|
||||
});
|
||||
}
|
||||
exports.updateComment = updateComment;
|
||||
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: `${headerComment(header)}\n${body}` }));
|
||||
yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: `${body}\n${headerComment(header)}` }));
|
||||
});
|
||||
}
|
||||
exports.createComment = createComment;
|
||||
|
|
|
|||
26
lib/main.js
26
lib/main.js
|
|
@ -1,4 +1,23 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
|
|
@ -8,13 +27,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
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(require("@actions/core"));
|
||||
const github_1 = require("@actions/github");
|
||||
|
|
|
|||
|
|
@ -8,19 +8,19 @@ export async function findPreviousComment(octokit, repo, issue_number, header) {
|
|||
issue_number
|
||||
});
|
||||
const h = headerComment(header);
|
||||
return comments.find(comment => comment.body.startsWith(h));
|
||||
return comments.find(comment => comment.body.includes(h));
|
||||
}
|
||||
export async function updateComment(octokit, repo, comment_id, body, header, previousBody?) {
|
||||
await octokit.issues.updateComment({
|
||||
...repo,
|
||||
comment_id,
|
||||
body: previousBody ? `${previousBody}\n${body}` : `${headerComment(header)}\n${body}`
|
||||
body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}`
|
||||
});
|
||||
}
|
||||
export async function createComment(octokit, repo, issue_number, body, header) {
|
||||
await octokit.issues.createComment({
|
||||
...repo,
|
||||
issue_number,
|
||||
body: `${headerComment(header)}\n${body}`
|
||||
body: `${body}\n${headerComment(header)}`
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue