This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Add new issues to PatternFly Extensions project | |
on: | |
issues: | |
types: | |
- opened | |
jobs: | |
add-to-project: | |
name: Add issue to project | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/[email protected] | |
with: | |
project-url: https://github.com/orgs/patternfly/projects/7 | |
github-token: ${{ secrets.GH_PROJECTS }} | |
label-issue: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if the author is on the team | |
id: check_team_membership | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const { Octokit } = require("@octokit/core"); | |
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }); | |
try { | |
const username = context.payload.issue.user.login; | |
console.log(`Checking membership for user: ${username}`); | |
// List all members of the team and check if the user is one of them | |
const { data: members } = await octokit.request('GET /orgs/{org}/teams/{team_slug}/members', { | |
org: 'patternfly', | |
team_slug: 'frequent-flyers', | |
}); | |
const isTeamMember = members.some(member => member.login === username); | |
console.log(`User is ${isTeamMember ? '' : 'not '}a member of the team.`); | |
return { is_team_member: isTeamMember ? 'true' : 'false' }; | |
} catch (error) { | |
console.error(`Error checking team membership: ${error.message}`); | |
return { is_team_member: 'false' }; | |
} | |
- name: Add label if user is a team member | |
if: steps.check_team_membership.outputs.is_team_member == 'true' | |
run: | | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \ | |
-d '{"labels":["Team Member"]}' |