-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix location we get org from #95
base: master
Are you sure you want to change the base?
Changes from all commits
ff8e2b5
88b9ad8
da03efc
2c05c12
eea49fb
546fcca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,20 @@ async function assign_reviewers(reviewers) { | |
}); | ||
} | ||
|
||
// https://docs.github.com/en/rest/teams/members?apiVersion=2022-11-28#list-team-members | ||
async function get_team_members(team) { | ||
const context = get_context(); | ||
const octokit = get_octokit(); | ||
const org = context.payload.repository.owner.login; | ||
|
||
const { data } = await octokit.teams.listMembersInOrg({ | ||
org, | ||
team_slug: team, | ||
}); | ||
|
||
return data?.map((member) => member.login); | ||
} | ||
Comment on lines
+116
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will it happen if you call this function in a repository under an individual account? |
||
|
||
/* Private */ | ||
|
||
let context_cache; | ||
|
@@ -158,4 +172,5 @@ module.exports = { | |
fetch_changed_files, | ||
assign_reviewers, | ||
clear_cache, | ||
get_team_members, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
const core = require('@actions/core'); | ||
const minimatch = require('minimatch'); | ||
const sample_size = require('lodash/sampleSize'); | ||
const github = require('./github'); // Don't destructure this object to stub with sinon in tests | ||
|
||
function fetch_other_group_members({ author, config }) { | ||
const DEFAULT_OPTIONS = { | ||
|
@@ -65,21 +66,46 @@ function identify_reviewers_by_changed_files({ config, changed_files, excludes = | |
return [ ...new Set(individuals) ].filter((reviewer) => !excludes.includes(reviewer)); | ||
} | ||
|
||
function identify_reviewers_by_author({ config, 'author': specified_author }) { | ||
async function identify_reviewers_by_author({ config, 'author': specified_author }) { | ||
if (!(config.reviewers && config.reviewers.per_author)) { | ||
core.info('"per_author" is not set; returning no reviewers for the author.'); | ||
return []; | ||
} | ||
|
||
// async behavior must happen first | ||
const team_member_promises = await Object.keys(config.reviewers.per_author).map(async (author) => { | ||
if (author.startsWith('team:')) { | ||
const team = author.replace('team:', ''); | ||
|
||
return { | ||
author, | ||
members: await github.get_team_members(team) || [], | ||
}; | ||
} | ||
|
||
return { | ||
author, | ||
members: [], | ||
}; | ||
}); | ||
const team_members = await Promise.all(team_member_promises); | ||
|
||
// More than one author can be matched because groups are set as authors | ||
const matching_authors = Object.keys(config.reviewers.per_author).filter((author) => { | ||
if (author === specified_author) { | ||
return true; | ||
} | ||
|
||
if (author.startsWith('team:')) { | ||
const { members } = team_members.find((team) => team.author === author); | ||
if (members.includes(specified_author)) { | ||
return true; | ||
} | ||
} | ||
|
||
const individuals_in_author_setting = replace_groups_with_individuals({ reviewers: [ author ], config }); | ||
|
||
if (individuals_in_author_setting.includes(specified_author)) { | ||
if (individuals_in_author_setting?.includes(specified_author)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you need to add |
||
return true; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
data
can't benull
orundefined
, I wouldn't add?
since it can hide some unexpected errors. In what case candata
benull
orundefined
?