๐Ÿ› fix find issue

This commit is contained in:
marocchino 2021-10-21 01:20:15 +09:00
parent a57b4690ec
commit 3c38ed8cd4
No known key found for this signature in database
GPG key ID: DEFF05E6B5B0FF97
5 changed files with 9 additions and 9 deletions

View file

@ -18,9 +18,12 @@ const repo = {
repo: "sticky-pull-request-comment"
}
it("findPreviousComment", async () => {
const authenticatedUser = {
const authenticatedBotUser = {
login: "github-actions[bot]"
}
const authenticatedUser = {
login: "github-actions"
}
const otherUser = {
login: "some-user"
}
@ -64,7 +67,7 @@ it("findPreviousComment", async () => {
]
const octokit = getOctokit("github-token")
jest.spyOn(octokit, "graphql").mockResolvedValue({
viewer: authenticatedUser,
viewer: authenticatedBotUser,
repository: {
pullRequest: {
comments: {

3
dist/index.js generated vendored
View file

@ -70,14 +70,13 @@ function findPreviousComment(octokit, repo, number, header) {
}
}
`, Object.assign(Object.assign({}, repo), { after, number }));
core.warning(JSON.stringify(data));
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const viewer = data.viewer;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const repository = data.repository;
const target = (_c = (_b = (_a = repository.pullRequest) === null || _a === void 0 ? void 0 : _a.comments) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.find((node) => {
var _a, _b;
return ((_a = node === null || node === void 0 ? void 0 : node.author) === null || _a === void 0 ? void 0 : _a.login) === viewer.login &&
return ((_a = node === null || node === void 0 ? void 0 : node.author) === null || _a === void 0 ? void 0 : _a.login) === viewer.login.replace("[bot]", "") &&
!(node === null || node === void 0 ? void 0 : node.isMinimized) &&
((_b = node === null || node === void 0 ? void 0 : node.body) === null || _b === void 0 ? void 0 : _b.includes(h));
});

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

3
lib/comment.js generated
View file

@ -63,14 +63,13 @@ function findPreviousComment(octokit, repo, number, header) {
}
}
`, Object.assign(Object.assign({}, repo), { after, number }));
core.warning(JSON.stringify(data));
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const viewer = data.viewer;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const repository = data.repository;
const target = (_c = (_b = (_a = repository.pullRequest) === null || _a === void 0 ? void 0 : _a.comments) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.find((node) => {
var _a, _b;
return ((_a = node === null || node === void 0 ? void 0 : node.author) === null || _a === void 0 ? void 0 : _a.login) === viewer.login &&
return ((_a = node === null || node === void 0 ? void 0 : node.author) === null || _a === void 0 ? void 0 : _a.login) === viewer.login.replace("[bot]", "") &&
!(node === null || node === void 0 ? void 0 : node.isMinimized) &&
((_b = node === null || node === void 0 ? void 0 : node.body) === null || _b === void 0 ? void 0 : _b.includes(h));
});

View file

@ -45,14 +45,13 @@ export async function findPreviousComment(
`,
{...repo, after, number}
)
core.warning(JSON.stringify(data))
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const viewer = data.viewer as User
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const repository = data.repository as Repository
const target = repository.pullRequest?.comments?.nodes?.find(
(node: IssueComment | null | undefined) =>
node?.author?.login === viewer.login &&
node?.author?.login === viewer.login.replace("[bot]", "") &&
!node?.isMinimized &&
node?.body?.includes(h)
)