[TEAM] TEAM-KLP #46
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: Process Repository Request | |
| on: | |
| issues: | |
| types: [labeled] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| create_repo_pr: | |
| if: | | |
| github.event.issue.labels && contains(join(github.event.issue.labels.*.name, ','), 'repo-creation') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Parse Issue Details (Debug) | |
| run: | | |
| echo "Full ISSUE_BODY content:" | |
| jq -r '.issue.body' "$GITHUB_EVENT_PATH" | |
| - name: Parse Issue Details | |
| id: parse | |
| run: | | |
| ISSUE_BODY=$(jq -r '.issue.body' "$GITHUB_EVENT_PATH") | |
| TEAM_NAMING=$(echo "$ISSUE_BODY" | awk -F'\n' '/^### Team Naming Convention$/{getline; getline; print $0}' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | |
| REPO_NAME=$(echo "$ISSUE_BODY" | awk -F'\n' '/^### Repository Name$/{getline; getline; print $0}' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | |
| BRANCH=$(echo "$ISSUE_BODY" | awk -F'\n' '/^### Default Branch$/{getline; getline; print $0}' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | |
| INCLUDE_README=$(echo "$ISSUE_BODY" | awk -F'\n' '/^### Include README$/{getline; getline; print $0}' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | |
| VISIBILITY=$(echo "$ISSUE_BODY" | awk -F'\n' '/^### Repository Visibility$/{getline; getline; print $0}' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | |
| CODEOWNERS=$(echo "$ISSUE_BODY" | awk -F'\n' '/^### Repository Code Owner\(s\)/{getline; getline; print $0}' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | |
| if [ "$TEAM_NAMING" = "lifeworks" ]; then | |
| TEAM_PREFIX="LW" | |
| elif [ "$TEAM_NAMING" = "telushealth" ]; then | |
| TEAM_PREFIX="TH" | |
| else | |
| echo "Error: Unknown team naming convention" | |
| exit 1 | |
| fi | |
| FULL_REPO_NAME="${TEAM_PREFIX}-${REPO_NAME}" | |
| echo "Extracted Team Naming: '$TEAM_NAMING'" | |
| echo "Team Prefix: '$TEAM_PREFIX'" | |
| echo "Full Repository Name: '$FULL_REPO_NAME'" | |
| echo "Branch: '$BRANCH'" | |
| echo "Include README: '$INCLUDE_README'" | |
| echo "Visibility: '$VISIBILITY'" | |
| echo "Code Owners: '$CODEOWNERS'" | |
| echo "TEAM_NAMING=$TEAM_NAMING" >> $GITHUB_ENV | |
| echo "TEAM_PREFIX=$TEAM_PREFIX" >> $GITHUB_ENV | |
| echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV | |
| echo "FULL_REPO_NAME=$FULL_REPO_NAME" >> $GITHUB_ENV | |
| echo "BRANCH=$BRANCH" >> $GITHUB_ENV | |
| echo "INCLUDE_README=$INCLUDE_README" >> $GITHUB_ENV | |
| echo "VISIBILITY=$VISIBILITY" >> $GITHUB_ENV | |
| echo "CODEOWNERS=$CODEOWNERS" >> $GITHUB_ENV | |
| - name: Set Git Identity | |
| run: | | |
| git config --global user.name "github-actions" | |
| git config --global user.email "github-actions@github.com" | |
| - name: Create Repository Structure | |
| run: | | |
| mkdir -p repos/${{ env.FULL_REPO_NAME }} | |
| cd repos/${{ env.FULL_REPO_NAME }} | |
| git init -b ${{ env.BRANCH }} | |
| if [[ "${{ env.INCLUDE_README }}" == "Yes" ]]; then | |
| echo "# ${{ env.FULL_REPO_NAME }}" > README.md | |
| else | |
| touch .gitkeep | |
| fi | |
| git add . | |
| git commit -m "Initial commit for ${{ env.FULL_REPO_NAME }}" | |
| - name: Commit Changes | |
| run: | | |
| cd repos/${{ env.FULL_REPO_NAME }} | |
| git add . | |
| git commit -m "Add repository structure for ${{ env.FULL_REPO_NAME }}" || echo "No changes to commit" | |
| - name: Create Pull Request | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| token: ${{ secrets.GH_PAT }} | |
| title: "Create new repository: ${{ env.FULL_REPO_NAME }}" | |
| body: | | |
| Repository Details: | |
| - **Name**: ${{ env.FULL_REPO_NAME }} | |
| - **Team Prefix**: ${{ env.TEAM_PREFIX }} | |
| - **Default Branch**: ${{ env.BRANCH }} | |
| - **Include README**: ${{ env.INCLUDE_README }} | |
| - **Repository Visibility**: ${{ env.VISIBILITY }} | |
| - **Code Owner(s)**: ${{ env.CODEOWNERS }} | |
| branch: "create-${{ env.FULL_REPO_NAME }}" | |
| labels: "repo-creation" |