Skip to content

Commit

Permalink
refactor: remove repeated code for first/last find (#163)
Browse files Browse the repository at this point in the history
* refactor: remove dup implementation for first/last

* remove `;` for linter
  • Loading branch information
NiloCK authored Apr 25, 2023
1 parent 14b3555 commit e5e598e
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,17 @@ export async function findComment(
issue_number: inputs.issueNumber
}

if (inputs.direction == 'first') {
for await (const {data: comments} of octokit.paginate.iterator(
octokit.rest.issues.listComments,
parameters
)) {
// Search each page for the comment
const comment = comments.find(comment =>
findCommentPredicate(inputs, comment)
)
if (comment) return comment
}
} else {
// direction == 'last'
const comments = await octokit.paginate(
octokit.rest.issues.listComments,
parameters
)
const comments = await octokit.paginate(
octokit.rest.issues.listComments,
parameters
)
if (inputs.direction == 'last') {
comments.reverse()
const comment = comments.find(comment =>
findCommentPredicate(inputs, comment)
)
if (comment) return comment
}
const comment = comments.find(comment =>
findCommentPredicate(inputs, comment)
)
if (comment) return comment

return undefined
}

0 comments on commit e5e598e

Please sign in to comment.