Merge branch 'master' into replace-option

This commit is contained in:
marocchino 2020-06-25 14:51:01 +09:00 committed by GitHub
commit 8cea69fb3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 744 additions and 606 deletions

View file

@ -10,14 +10,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: {
@ -29,14 +35,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]
}) })
) )
} }
@ -46,6 +52,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 () => {
@ -59,22 +66,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 () => {
@ -88,14 +95,14 @@ 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 -->"
}); });
}); });

View file

@ -17,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, 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* () {
yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: previousBody ? `${previousBody}\n${body}` : `${headerComment(header)}\n${body}` })); yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}` }));
}); });
} }
exports.createComment = createComment; exports.createComment = createComment;

1303
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -24,10 +24,10 @@
"@actions/github": "^2.2.0" "@actions/github": "^2.2.0"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.0", "@types/jest": "^26.0.3",
"@types/node": "^14.0.13", "@types/node": "^14.0.14",
"jest": "^25.5.4", "jest": "^25.5.4",
"jest-circus": "^26.0.1", "jest-circus": "^26.1.0",
"ts-jest": "^25.5.1", "ts-jest": "^25.5.1",
"typescript": "^3.9.5" "typescript": "^3.9.5"
} }

View file

@ -8,20 +8,20 @@ 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, previousBody?) { export async function createComment(octokit, repo, issue_number, body, header, previousBody?) {
await octokit.issues.createComment({ await octokit.issues.createComment({
...repo, ...repo,
issue_number, issue_number,
body: previousBody ? `${previousBody}\n${body}` : `${headerComment(header)}\n${body}` body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}`
}); });
} }
export async function deleteComment(octokit, repo, comment_id) { export async function deleteComment(octokit, repo, comment_id) {