mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation and Context DevFlow currently starts PR reviews for all contributors. Align its review eligibility with Microsoft Agent Framework by checking membership in the internal developer team before running the review. ### Description - Split the workflow into `prepare_pr`, `team_check`, and `review` jobs. The review runs only when the team check succeeds. - Check the **PR author** for automatic runs and the **person starting the workflow** for manual runs. Draft PRs follow the same eligibility check as other PRs. - Add a team-membership helper that uses the team slug supplied by `DEVELOPER_TEAM`, plus a `team-check` GitHub App token profile with member and PR read permissions. - Keep SK's existing spam/relevance check and DevFlow review steps. - Add tests for the membership helper and token profile, and include the helper in the automation test workflow's path filters. --------- Co-authored-by: Copilot App <[email protected]>
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
async function checkTeamMembership({ github, context, teamSlug, prNumber, username = '' }) {
|
|
if (!teamSlug) {
|
|
throw new Error('DEVELOPER_TEAM must be configured with the developer team slug.');
|
|
}
|
|
|
|
const number = Number(prNumber);
|
|
if (!/^[1-9][0-9]*$/.test(prNumber) || !Number.isSafeInteger(number)) {
|
|
throw new Error('A valid PR number is required to check team membership.');
|
|
}
|
|
|
|
let author = username.trim() || context.payload?.pull_request?.user?.login;
|
|
if (!author) {
|
|
const { data: pr } = await github.rest.pulls.get({
|
|
...context.repo,
|
|
pull_number: number,
|
|
});
|
|
author = pr.user?.login;
|
|
}
|
|
if (!author) {
|
|
throw new Error('Could not determine PR author (user may be deleted).');
|
|
}
|
|
|
|
// Verify the team exists so a missing or inaccessible team is not mistaken for a nonmember.
|
|
await github.rest.teams.getByName({
|
|
org: context.repo.owner,
|
|
team_slug: teamSlug,
|
|
});
|
|
|
|
try {
|
|
const { data: membership } = await github.rest.teams.getMembershipForUserInOrg({
|
|
org: context.repo.owner,
|
|
team_slug: teamSlug,
|
|
username: author,
|
|
});
|
|
return { author, isTeamMember: membership.state === 'active' };
|
|
} catch (error) {
|
|
if (error.status === 404) {
|
|
return { author, isTeamMember: false };
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
module.exports = checkTeamMembership;
|