Skip to content

Commit

Permalink
Update main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
anusha1908 authored Apr 29, 2024
1 parent b208ec0 commit 8e77d52
Showing 1 changed file with 15 additions and 42 deletions.
57 changes: 15 additions & 42 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,29 @@ jobs:
check_author_team_membership:
runs-on: ubuntu-latest
steps:
- name: Get teams
id: get_teams
uses: octokit/[email protected]
with:
route: GET /orgs/:org/teams
org: ${{ github.event.organization.login }}
headers:
authorization: ${{ secrets.GITHUB_TOKEN }}

- name: Check if author is a member of opsTrack team
id: check_author_membership
- name: Check if author is opsTrack member
id: check_author
run: |
const teams = ${{fromJson(steps.get_teams.outputs.data)}};
const opsTrackTeam = teams.find(team => team.slug === 'opsTrack');
const teamMembers = await github.rest.teams.listMembersInOrg({
org: context.payload.organization.login,
team_slug: opsTrackTeam.slug,
headers: {
authorization: `token ${{ secrets.GITHUB_TOKEN }}`
}
});
const author = context.payload.sender.login;
const isMember = teamMembers.some(member => member.login === author);
if (isMember) {
console.log('Author is a member of opsTrack team');
core.setOutput('opsTrackMember', 'true');
} else {
console.log('Author is not a member of opsTrack team');
core.setOutput('opsTrackMember', 'false');
}
response=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/orgs/${{ github.event.organization.login }}/teams/opsTrack/members")
if echo "$response" | grep -q "\"login\": \"${{ github.event.pull_request.user.login }}\""; then
echo "::set-output name=isMember::true"
else
echo "::set-output name=isMember::false"
fi
label_pr_needing_reviews:
needs: check_author_team_membership
runs-on: ubuntu-latest
steps:
- name: Check if opsTrack member
run: echo "Author is opsTrack member: ${{ needs.check_author_team_membership.outputs.opsTrackMember }}"
id: opsTrack_member_check
run: echo "Author is opsTrack member:${{ needs.check_author_team_membership.outputs.isMember }}"

- name: Add label if opsTrack member
if: steps.opsTrack_member_check.outputs.opsTrackMember == 'true'
uses: actions/github-script@v5
if: steps.check_author_team_membership.outputs.isMember == 'true'
uses: dessant/label-actions@v4
with:
script: |
github.issues.addLabels({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.payload.pull_request.number,
labels: ['codeowner reviews required']
});
script-output: |
{ token: '${{ secrets.GITHUB_TOKEN }}' }
action: add
labels: codeowner reviews required
repo-token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 8e77d52

Please sign in to comment.