mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-16 21:18:27 +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: {
|
user: {
|
||||||
login: "github-actions[bot]"
|
login: "github-actions[bot]"
|
||||||
},
|
},
|
||||||
body: "<!-- Sticky Pull Request Comment -->\nprevious message"
|
body: "previous message\n<!-- Sticky Pull Request Comment -->"
|
||||||
};
|
};
|
||||||
const commentWithCustomHeader = {
|
const commentWithCustomHeader = {
|
||||||
user: {
|
user: {
|
||||||
login: "github-actions[bot]"
|
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 = [
|
const otherComments = [
|
||||||
{
|
{
|
||||||
user: {
|
user: {
|
||||||
|
|
@ -28,14 +34,14 @@ it("findPreviousComment", async () => {
|
||||||
user: {
|
user: {
|
||||||
login: "github-actions[bot]"
|
login: "github-actions[bot]"
|
||||||
},
|
},
|
||||||
body: "<!-- Sticky Pull Request CommentTypeB -->\nprevious message"
|
body: "previous message\n<!-- Sticky Pull Request CommentTypeB -->"
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
const octokit = {
|
const octokit = {
|
||||||
issues: {
|
issues: {
|
||||||
listComments: jest.fn(() =>
|
listComments: jest.fn(() =>
|
||||||
Promise.resolve({
|
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(
|
expect(await findPreviousComment(octokit, repo, 123, "TypeA")).toBe(
|
||||||
commentWithCustomHeader
|
commentWithCustomHeader
|
||||||
);
|
);
|
||||||
|
expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(headerFirstComment)
|
||||||
expect(octokit.issues.listComments).toBeCalledWith({ issue_number: 123 });
|
expect(octokit.issues.listComments).toBeCalledWith({ issue_number: 123 });
|
||||||
});
|
});
|
||||||
it("updateComment", async () => {
|
it("updateComment", async () => {
|
||||||
|
|
@ -58,22 +65,22 @@ it("updateComment", async () => {
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||||
comment_id: 456,
|
comment_id: 456,
|
||||||
body: "<!-- Sticky Pull Request Comment -->\nhello there"
|
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
await updateComment(octokit, repo, 456, "hello there", "TypeA")
|
await updateComment(octokit, repo, 456, "hello there", "TypeA")
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||||
comment_id: 456,
|
comment_id: 456,
|
||||||
body: "<!-- Sticky Pull Request CommentTypeA -->\nhello there"
|
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
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();
|
).toBeUndefined();
|
||||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||||
comment_id: 456,
|
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 () => {
|
it("createComment", async () => {
|
||||||
|
|
@ -87,13 +94,13 @@ it("createComment", async () => {
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
expect(octokit.issues.createComment).toBeCalledWith({
|
expect(octokit.issues.createComment).toBeCalledWith({
|
||||||
issue_number: 456,
|
issue_number: 456,
|
||||||
body: "<!-- Sticky Pull Request Comment -->\nhello there"
|
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
await createComment(octokit, repo, 456, "hello there", "TypeA")
|
await createComment(octokit, repo, 456, "hello there", "TypeA")
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
expect(octokit.issues.createComment).toBeCalledWith({
|
expect(octokit.issues.createComment).toBeCalledWith({
|
||||||
issue_number: 456,
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
||||||
function headerComment(header) {
|
function headerComment(header) {
|
||||||
return `<!-- Sticky Pull Request Comment${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* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const { data: comments } = yield octokit.issues.listComments(Object.assign(Object.assign({}, repo), { issue_number }));
|
const { data: comments } = yield octokit.issues.listComments(Object.assign(Object.assign({}, repo), { issue_number }));
|
||||||
const h = headerComment(header);
|
const h = headerComment(header);
|
||||||
return comments.find(comment => comment.body.startsWith(h));
|
return comments.find(comment => comment.body.includes(h));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.findPreviousComment = findPreviousComment;
|
exports.findPreviousComment = findPreviousComment;
|
||||||
function updateComment(octokit, repo, comment_id, body, header, previousBody) {
|
function updateComment(octokit, repo, comment_id, body, header, previousBody) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
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;
|
exports.updateComment = updateComment;
|
||||||
function createComment(octokit, repo, issue_number, body, header) {
|
function createComment(octokit, repo, issue_number, body, header) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
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;
|
exports.createComment = createComment;
|
||||||
|
|
|
||||||
26
lib/main.js
26
lib/main.js
|
|
@ -1,4 +1,23 @@
|
||||||
"use strict";
|
"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) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
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());
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const github_1 = require("@actions/github");
|
const github_1 = require("@actions/github");
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,19 @@ export async function findPreviousComment(octokit, repo, issue_number, header) {
|
||||||
issue_number
|
issue_number
|
||||||
});
|
});
|
||||||
const h = headerComment(header);
|
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?) {
|
export async function updateComment(octokit, repo, comment_id, body, header, previousBody?) {
|
||||||
await octokit.issues.updateComment({
|
await octokit.issues.updateComment({
|
||||||
...repo,
|
...repo,
|
||||||
comment_id,
|
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) {
|
export async function createComment(octokit, repo, issue_number, body, header) {
|
||||||
await octokit.issues.createComment({
|
await octokit.issues.createComment({
|
||||||
...repo,
|
...repo,
|
||||||
issue_number,
|
issue_number,
|
||||||
body: `${headerComment(header)}\n${body}`
|
body: `${body}\n${headerComment(header)}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue