Skip to content

Commit

Permalink
fix: Correctly handle assignees
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Manouvrier committed Jul 17, 2023
1 parent efafc95 commit fb1a45b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
13 changes: 10 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

26 changes: 23 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ async function run(): Promise<void> {

const changedFiles = await octokit.rest.pulls.listFiles({
...github.context.repo,
pull_number: github.context.issue.number
pull_number: github.context.issue.number,
per_page: 100
})
core.debug(
`Changed files: ${JSON.stringify(
Expand All @@ -27,14 +28,33 @@ async function run(): Promise<void> {
const watchersForChangedFiles = changedFiles.data.flatMap(file =>
watchers.getOwner(file.filename)
)
const uniqueWatchers = [...new Set(watchersForChangedFiles)]
const uniqueWatchers = new Set(watchersForChangedFiles)
core.debug(`Filtered watchers: ${JSON.stringify(uniqueWatchers)}`)

// Set assignees
const assignees = await octokit.rest.issues.listAssignees({
...github.context.repo,
issue_number: github.context.issue.number,
per_page: 100
})
core.debug(
`Current assignees: ${JSON.stringify(
assignees.data.map(assignee => ({
username: assignee.login,
email: assignee.email
}))
)}`
)

const uniqueAssignees = assignees.data.filter(
assignee => assignee.email != null && uniqueWatchers.has(assignee.email)
)
core.debug(`Filtered assignees: ${JSON.stringify(uniqueAssignees)}`)

await octokit.rest.issues.addAssignees({
...github.context.repo,
issue_number: github.context.issue.number,
assignees: uniqueWatchers
assignees: uniqueAssignees.map(assignee => assignee.login)
})
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
Expand Down

0 comments on commit fb1a45b

Please sign in to comment.