Fix: Ignore other users' comments (#332)

Make findPreviousComment only return comments made by the current user
(usually github-actions[bot])
This commit is contained in:
Rob Cowsill 2021-06-14 19:25:28 +01:00 committed by GitHub
parent 2020b5bc34
commit 65b0a353cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 309 additions and 283 deletions

View file

@ -16,45 +16,51 @@ const repo = {
repo: "sticky-pull-request-comment"
}
it("findPreviousComment", async () => {
const authenticatedUser = {
login: "github-actions[bot]"
}
const otherUser = {
login: "some-user"
}
const comment = {
user: {
login: "github-actions[bot]"
},
user: authenticatedUser,
body: "previous message\n<!-- Sticky Pull Request Comment -->"
}
const commentWithCustomHeader = {
user: {
login: "github-actions[bot]"
},
user: authenticatedUser,
body: "previous message\n<!-- Sticky Pull Request CommentTypeA -->"
}
const headerFirstComment = {
user: {
login: "github-actions[bot]"
},
user: authenticatedUser,
body: "<!-- Sticky Pull Request CommentLegacyComment -->\nheader first message"
}
const otherUserComment = {
user: otherUser,
body: "Fake previous message\n<!-- Sticky Pull Request Comment -->"
}
const otherComments = [
{
user: {
login: "some-user"
},
user: otherUser,
body: "lgtm"
},
{
user: {
login: "github-actions[bot]"
},
user: authenticatedUser,
body: "previous message\n<!-- Sticky Pull Request CommentTypeB -->"
}
]
const octokit: any = {
graphql: jest.fn(() =>
Promise.resolve({
viewer: authenticatedUser
})
),
rest: {
issues: {
listComments: jest.fn(() =>
Promise.resolve({
data: [
commentWithCustomHeader,
otherUserComment,
comment,
headerFirstComment,
...otherComments