team-approval-check.js 983 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* eslint-env node */
  2. module.exports = {
  3. check: async ({github, context, core, team_slug}) => {
  4. const owner = context.repo.owner;
  5. const repo = context.repo.repo;
  6. const pull_number = context.issue.number;
  7. // Get all reviews for this PR
  8. const {data: reviews} = await github.rest.pulls.listReviews({
  9. owner,
  10. repo,
  11. pull_number,
  12. });
  13. // Collect all members of the team
  14. const {data: members} = await github.rest.teams.listMembersInOrg({
  15. org: owner,
  16. team_slug,
  17. });
  18. if (!members) {
  19. core.setFailed(`No members found in ${team_slug}`);
  20. return;
  21. }
  22. const memberIds = members.map(member => member.id);
  23. // Check if any member of the team approved this PR
  24. const isApprovedByMember = reviews.some(
  25. review => memberIds.includes(review.user.id) && review.state === 'APPROVED'
  26. );
  27. if (!isApprovedByMember) {
  28. core.setFailed(`No ${team_slug} member approved this PR`);
  29. }
  30. },
  31. };