[Repo Request] thala-for-reason #67
This file contains hidden or 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: Create Team PR | |
| on: | |
| issues: | |
| types: [labeled] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| create_pr: | |
| if: | | |
| github.event.issue.labels && contains(join(github.event.issue.labels.*.name, ','), 'team-request') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Extract Team Details | |
| id: extract | |
| run: | | |
| ISSUE_BODY="${{ github.event.issue.body }}" | |
| echo "Issue Body:" | |
| echo "$ISSUE_BODY" | |
| TEAM_NAME=$(echo "$ISSUE_BODY" | awk '/^### Team Name$/{getline; getline; print}' | sed 's/[`]//g' | xargs) | |
| VISIBILITY=$(echo "$ISSUE_BODY" | awk '/^### Visibility$/{getline; getline; print}' | sed 's/[`]//g' | xargs) | |
| PURPOSE=$(echo "$ISSUE_BODY" | awk '/^### Purpose$/{getline; getline; print}' | sed 's/[`]//g' | xargs) | |
| MAINTAINERS=$(echo "$ISSUE_BODY" | awk '/^### Maintainers \(comma-separated\)$/{getline; getline; print}' | sed 's/[`]//g' | xargs) | |
| TEAM_MEMBERS=$(echo "$ISSUE_BODY" | awk '/^### Team Members \(comma-separated\)$/{getline; getline; print}' | sed 's/[`]//g' | xargs) | |
| PARENT_TEAM=$(echo "$ISSUE_BODY" | awk '/^### Parent Team \(optional\)$/{getline; getline; print}' | sed 's/[`]//g' | xargs) | |
| echo "Extracted Values:" | |
| echo "Team Name: '$TEAM_NAME'" | |
| echo "Visibility: '$VISIBILITY'" | |
| echo "Purpose: '$PURPOSE'" | |
| echo "Maintainers: '$MAINTAINERS'" | |
| echo "Team Members: '$TEAM_MEMBERS'" | |
| echo "Parent Team: '$PARENT_TEAM'" | |
| if [[ ! "$TEAM_NAME" =~ ^TEAM-[a-zA-Z0-9_-]{3,20}$ ]]; then | |
| echo "::error::Invalid team name format: '$TEAM_NAME'" | |
| exit 1 | |
| fi | |
| VISIBILITY=${VISIBILITY:-Visible} | |
| PURPOSE=${PURPOSE:-Team created via automation} | |
| MAINTAINERS=${MAINTAINERS:-none} | |
| TEAM_MEMBERS=${TEAM_MEMBERS:-none} | |
| PARENT_TEAM=${PARENT_TEAM:-none} | |
| echo "$TEAM_NAME" > team-name.txt | |
| echo "team_name=$TEAM_NAME" >> "$GITHUB_ENV" | |
| echo "visibility=$VISIBILITY" >> "$GITHUB_ENV" | |
| echo "purpose=$PURPOSE" >> "$GITHUB_ENV" | |
| echo "maintainers=$MAINTAINERS" >> "$GITHUB_ENV" | |
| echo "team_members=$TEAM_MEMBERS" >> "$GITHUB_ENV" | |
| echo "parent_team=$PARENT_TEAM" >> "$GITHUB_ENV" | |
| - name: Create Pull Request | |
| uses: peter-evans/create-pull-request@v5 | |
| with: | |
| token: ${{ secrets.GH_PAT }} | |
| commit-message: "Add team: ${{ env.team_name }}" | |
| title: "Create team: ${{ env.team_name }}" | |
| body: | | |
| ### Team Creation Request | |
| **Team Name:** ${{ env.team_name }} | |
| **Visibility:** ${{ env.visibility }} | |
| **Purpose:** ${{ env.purpose }} | |
| **Parent Team:** ${{ env.parent_team }} | |
| **Maintainers:** ${{ env.maintainers }} | |
| **Team Members:** ${{ env.team_members }} | |
| Generated from issue #${{ github.event.issue.number }} | |
| branch: "team-request/${{ github.event.issue.number }}" | |
| labels: "team-creation" | |
| paths: | | |
| team-name.txt | |
| - name: Post a message in Slack | |
| uses: slackapi/slack-github-action@v2.0.0 | |
| with: | |
| webhook: ${{ secrets.SLACK_TOKEN }} | |
| webhook-type: incoming-webhook | |
| payload: | | |
| text: "*New Team PR Created: `${{ env.team_name }}`*" | |
| blocks: | |
| - type: section | |
| text: | |
| type: mrkdwn | |
| text: ":tada: A new PR has been created for team *`${{ env.team_name }}`*!\n*Purpose:* ${{ env.purpose }}\n*Maintainers:* ${{ env.maintainers }}\n*Parent:* `${{ env.parent_team }}`\n<https://github.com/${{ github.repository }}/pull/${{ steps.create_pr.outputs.pull-request-number }}|View Pull Request>" | |