|
1 | | -name: Auto-tag Repo After Template Use |
| 1 | +name: Assign Topics Automatically |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: |
6 | | - - main |
7 | | - |
8 | | -permissions: |
9 | | - contents: write |
| 5 | + branches: [main] |
| 6 | + # This ensures it runs only once after repo is created with initial push |
10 | 7 |
|
11 | 8 | jobs: |
12 | | - tag-repo: |
| 9 | + assign-topics: |
13 | 10 | runs-on: ubuntu-latest |
14 | 11 |
|
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + repository-projects: write |
| 15 | + metadata: write |
| 16 | + |
15 | 17 | steps: |
16 | | - - name: Extract repo name |
| 18 | + - name: Extract Repo Info |
17 | 19 | id: extract |
18 | 20 | run: | |
19 | | - REPO_NAME="${{ github.repository }}" |
20 | | - REPO_ONLY="${REPO_NAME#*/}" |
21 | | - echo "repo_only=$REPO_ONLY" >> $GITHUB_OUTPUT |
| 21 | + REPO="${GITHUB_REPOSITORY##*/}" |
22 | 22 |
|
23 | | - - name: Parse and set topics |
24 | | - env: |
25 | | - GH_TOKEN: ${{ secrets.REPO_SETUP_TOKEN }} |
26 | | - REPO: ${{ github.repository }} |
27 | | - REPO_NAME: ${{ steps.extract.outputs.repo_only }} |
28 | | - run: | |
29 | | - IFS='_' read -r _ DEPT SUBJECT TITLE SECTION ID <<< "$REPO_NAME" |
| 23 | + echo "Full Repo Name: $REPO" |
30 | 24 |
|
31 | | - echo "Applying topics: $DEPT $SUBJECT $SECTION" |
| 25 | + IFS='_' read -r INSTITUTE DEPT COURSE PROJECT SECTION TEAM <<< "$REPO" |
32 | 26 |
|
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\"]}" |
| 27 | + echo "institute=$INSTITUTE" >> $GITHUB_OUTPUT |
| 28 | + echo "department=$DEPT" >> $GITHUB_OUTPUT |
| 29 | + echo "course=$COURSE" >> $GITHUB_OUTPUT |
| 30 | + echo "project=$PROJECT" >> $GITHUB_OUTPUT |
| 31 | + echo "section=$SECTION" >> $GITHUB_OUTPUT |
| 32 | + echo "team_id=$TEAM" >> $GITHUB_OUTPUT |
| 33 | +
|
| 34 | + - name: Set Topics via GitHub API |
| 35 | + env: |
| 36 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + run: | |
| 38 | + gh api repos/${{ github.repository }} \ |
| 39 | + --method PUT \ |
| 40 | + -H "Accept: application/vnd.github.mercy-preview+json" \ |
| 41 | + -f name='${{ github.event.repository.name }}' \ |
| 42 | + -f description='Auto-tagged repository for ${{ steps.extract.outputs.project }} project' \ |
| 43 | + -F topics='${{ steps.extract.outputs.institute }},${{ steps.extract.outputs.department }},${{ steps.extract.outputs.course }},${{ steps.extract.outputs.project }},${{ steps.extract.outputs.section }},${{ steps.extract.outputs.team_id }}' |
0 commit comments