|
1 | | -name: Initial Repository Setup |
| 1 | +name: Auto-tag Repo After Template Use |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
|
7 | 7 |
|
8 | 8 | permissions: |
9 | 9 | contents: write |
10 | | - issues: write |
11 | | - pull-requests: write |
12 | 10 |
|
13 | 11 | jobs: |
14 | | - setup: |
15 | | - name: Setup Repo After First Commit |
| 12 | + tag-repo: |
16 | 13 | runs-on: ubuntu-latest |
17 | 14 |
|
18 | 15 | steps: |
19 | | - - name: Checkout code |
20 | | - uses: actions/checkout@v4 |
21 | | - |
22 | | - - name: Add collaborators (example) |
23 | | - uses: peter-evans/create-or-update-comment@v3 |
24 | | - with: |
25 | | - token: ${{ secrets.GITHUB_TOKEN }} |
26 | | - issue-number: 1 |
27 | | - body: | |
28 | | - ✅ Automated Setup Triggered! |
29 | | - Please wait while project-level configurations are applied. |
| 16 | + - name: Extract repo name |
| 17 | + id: extract |
| 18 | + run: | |
| 19 | + REPO_NAME="${{ github.repository }}" |
| 20 | + REPO_ONLY="${REPO_NAME#*/}" |
| 21 | + echo "repo_only=$REPO_ONLY" >> $GITHUB_OUTPUT |
30 | 22 |
|
31 | | - - name: Configure Collaborators via API |
| 23 | + - name: Parse and set topics |
32 | 24 | env: |
33 | | - GH_TOKEN: ${{ secrets.REPO_SETUP_TOKEN }} # Use a fine-grained PAT stored in org secrets |
34 | | - REPO_NAME: ${{ github.repository }} |
| 25 | + GH_TOKEN: ${{ secrets.REPO_SETUP_TOKEN }} |
| 26 | + REPO: ${{ github.repository }} |
| 27 | + REPO_NAME: ${{ steps.extract.outputs.repo_only }} |
35 | 28 | run: | |
36 | | - # Example collaborators to add (edit as needed) |
37 | | - curl -X PUT -H "Authorization: token $GH_TOKEN" \ |
38 | | - -H "Accept: application/vnd.github+json" \ |
39 | | - https://api.github.com/repos/$REPO_NAME/collaborators/username1 \ |
40 | | - -d '{"permission":"push"}' |
| 29 | + IFS='_' read -r _ DEPT SUBJECT TITLE SECTION ID <<< "$REPO_NAME" |
41 | 30 |
|
42 | | - curl -X PUT -H "Authorization: token $GH_TOKEN" \ |
43 | | - -H "Accept: application/vnd.github+json" \ |
44 | | - https://api.github.com/repos/$REPO_NAME/collaborators/username2 \ |
45 | | - -d '{"permission":"push"}' |
| 31 | + echo "Applying topics: $DEPT $SUBJECT $SECTION" |
46 | 32 |
|
47 | | - - name: Success message |
48 | | - run: echo "✅ Repo initialized and collaborators added!" |
| 33 | + curl -X PATCH -H "Authorization: token $GH_TOKEN" \ |
| 34 | + -H "Accept: application/vnd.github+json" \ |
| 35 | + https://api.github.com/repos/$REPO \ |
| 36 | + -d "{\"topics\": [\"$DEPT\", \"$SUBJECT\", \"$SECTION\"]}" |
0 commit comments