mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-02-24 03:41:45 +00:00
Merge pull request #201 from SvanBoxel/ignore-empty-body-update
Ignore empty body update
This commit is contained in:
commit
9e8e1d498c
3 changed files with 88 additions and 51 deletions
|
|
@ -4,6 +4,13 @@ import {
|
||||||
updateComment,
|
updateComment,
|
||||||
deleteComment
|
deleteComment
|
||||||
} from "../src/comment";
|
} from "../src/comment";
|
||||||
|
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
|
jest.mock('@actions/core', () => ({
|
||||||
|
warning: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
const repo = {};
|
const repo = {};
|
||||||
it("findPreviousComment", async () => {
|
it("findPreviousComment", async () => {
|
||||||
const comment = {
|
const comment = {
|
||||||
|
|
@ -55,55 +62,85 @@ it("findPreviousComment", async () => {
|
||||||
expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(headerFirstComment)
|
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 () => {
|
|
||||||
const octokit = {
|
describe("updateComment", () => {
|
||||||
issues: {
|
let octokit;
|
||||||
updateComment: jest.fn(() => Promise.resolve())
|
|
||||||
}
|
beforeEach(() => {
|
||||||
};
|
octokit = {
|
||||||
expect(
|
issues: {
|
||||||
await updateComment(octokit, repo, 456, "hello there", "")
|
updateComment: jest.fn(() => Promise.resolve())
|
||||||
).toBeUndefined();
|
}
|
||||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
};
|
||||||
comment_id: 456,
|
})
|
||||||
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
|
||||||
});
|
it("with comment body", async() => {
|
||||||
expect(
|
expect(
|
||||||
await updateComment(octokit, repo, 456, "hello there", "TypeA")
|
await updateComment(octokit, repo, 456, "hello there", "")
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||||
comment_id: 456,
|
comment_id: 456,
|
||||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
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: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
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: "hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
it("without comment body and previousbody", async() => {
|
||||||
await updateComment(octokit, repo, 456, "hello there", "TypeA", "hello there\n<!-- Sticky Pull Request CommentTypeA -->")
|
expect(
|
||||||
).toBeUndefined();
|
await updateComment(octokit, repo, 456, "", "")
|
||||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
).toBeUndefined();
|
||||||
comment_id: 456,
|
expect(octokit.issues.updateComment).not.toBeCalled();
|
||||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there"
|
expect(core.warning).toBeCalledWith('Comment body cannot be blank');
|
||||||
});
|
})
|
||||||
});
|
});
|
||||||
it("createComment", async () => {
|
|
||||||
const octokit = {
|
describe("createComment", () => {
|
||||||
issues: {
|
let octokit;
|
||||||
createComment: jest.fn(() => Promise.resolve())
|
|
||||||
}
|
beforeEach(() => {
|
||||||
};
|
octokit = {
|
||||||
expect(
|
issues: {
|
||||||
await createComment(octokit, repo, 456, "hello there", "")
|
createComment: jest.fn(() => Promise.resolve())
|
||||||
).toBeUndefined();
|
}
|
||||||
expect(octokit.issues.createComment).toBeCalledWith({
|
};
|
||||||
issue_number: 456,
|
})
|
||||||
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
|
||||||
});
|
it("with comment body or previousBody", async () => {
|
||||||
expect(
|
expect(
|
||||||
await createComment(octokit, repo, 456, "hello there", "TypeA")
|
await createComment(octokit, repo, 456, "hello there", "")
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
expect(octokit.issues.createComment).toBeCalledWith({
|
expect(octokit.issues.createComment).toBeCalledWith({
|
||||||
issue_number: 456,
|
issue_number: 456,
|
||||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
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: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||||
|
});
|
||||||
|
})
|
||||||
|
it("without comment body and previousBody", async () => {
|
||||||
|
expect(
|
||||||
|
await createComment(octokit, repo, 456, "", "")
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(octokit.issues.createComment).not.toBeCalled();
|
||||||
|
expect(core.warning).toBeCalledWith('Comment body cannot be blank');
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
it("deleteComment", async () => {
|
it("deleteComment", async () => {
|
||||||
|
|
|
||||||
|
|
@ -44,15 +44,15 @@ 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* () {
|
||||||
if (!body && !previousBody)
|
if (!body && !previousBody)
|
||||||
core.warning('Comment body cannot be blank');
|
return core.warning('Comment body cannot be blank');
|
||||||
yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}` }));
|
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, previousBody) {
|
function createComment(octokit, repo, issue_number, body, header, previousBody) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (!body)
|
if (!body && !previousBody)
|
||||||
core.warning('Comment body cannot be blank');
|
return core.warning('Comment body cannot be blank');
|
||||||
yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}` }));
|
yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}` }));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ export async function findPreviousComment(octokit, repo, issue_number, header) {
|
||||||
return comments.find(comment => comment.body.includes(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?) {
|
||||||
if (!body && !previousBody) core.warning('Comment body cannot be blank');
|
if (!body && !previousBody) return core.warning('Comment body cannot be blank');
|
||||||
|
|
||||||
await octokit.issues.updateComment({
|
await octokit.issues.updateComment({
|
||||||
...repo,
|
...repo,
|
||||||
|
|
@ -22,7 +22,7 @@ export async function updateComment(octokit, repo, comment_id, body, header, pre
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
export async function createComment(octokit, repo, issue_number, body, header, previousBody?) {
|
export async function createComment(octokit, repo, issue_number, body, header, previousBody?) {
|
||||||
if (!body) core.warning('Comment body cannot be blank');
|
if (!body && !previousBody) return core.warning('Comment body cannot be blank');
|
||||||
|
|
||||||
await octokit.issues.createComment({
|
await octokit.issues.createComment({
|
||||||
...repo,
|
...repo,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue