Skip to content
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

Update main.yml #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 20 additions & 42 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,34 @@ 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'
run: |
echo "Author is a member of opsTrack team, adding label..."

- name: Add label
if: always()
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: 2 codeowners reviews required
repo-token: ${{ secrets.GITHUB_TOKEN }}
Loading