Skip to content

Commit

Permalink
different approach to find comment
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Oct 22, 2024
1 parent d7727e9 commit 4b3cd00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

22 changes: 7 additions & 15 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,21 @@ const { createTable, createSummary } = require('./comment')

const packageLockParser = new PackageLockParser()

const getCommentId = async (octokit, oktokitParams, issueNumber, commentHeader) => {
const COMMENT_IDENTIFIER = '<!-- npm-lockfile-changes-action comment -->'

const getCommentId = async (octokit, oktokitParams, issueNumber) => {
const currentComments = await octokit.rest.issues.listComments({
...oktokitParams,
issue_number: issueNumber,
per_page: 100,
})
let actionUser = 'github-action[bot]'
try {
const authenticatedUser = await octokit.rest.users.getAuthenticated()
console.log(authenticatedUser)
actionUser = authenticatedUser.login
} catch (e) {
// ignore - this fails when running with the default github token for a
// workflow, but if using a github app token or a personal access token,
// then it's necessary.
console.error(e)
}
debug('Action user: ' + actionUser)

if (!currentComments || !currentComments.data) {
throw Error('💥 Cannot fetch PR comments data, aborting!')
}

return currentComments.data
.filter(({ user, body }) => user.login === actionUser.login && body.startsWith(commentHeader))
.filter(({ body }) => body.includes(COMMENT_IDENTIFIER))
.map(({ id }) => id)[0]
}

Expand Down Expand Up @@ -133,7 +123,9 @@ const run = async () => {
'<summary>Click to toggle table visibility</summary>\n<br/>\n\n' +
diffsTable +
'\n\n' +
'</details>'
'</details>' +
'\n\n' +
COMMENT_IDENTIFIER

if (updateComment) {
if (commentId) {
Expand Down

0 comments on commit 4b3cd00

Please sign in to comment.