Skip to content

Commit e2900b8

Browse files
Update setup-repo.yml
1 parent 24211c0 commit e2900b8

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

.github/workflows/setup-repo.yml

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,43 @@
1-
name: Auto-tag Repo After Template Use
1+
name: Assign Topics Automatically
22

33
on:
44
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
107

118
jobs:
12-
tag-repo:
9+
assign-topics:
1310
runs-on: ubuntu-latest
1411

12+
permissions:
13+
contents: read
14+
repository-projects: write
15+
metadata: write
16+
1517
steps:
16-
- name: Extract repo name
18+
- name: Extract Repo Info
1719
id: extract
1820
run: |
19-
REPO_NAME="${{ github.repository }}"
20-
REPO_ONLY="${REPO_NAME#*/}"
21-
echo "repo_only=$REPO_ONLY" >> $GITHUB_OUTPUT
21+
REPO="${GITHUB_REPOSITORY##*/}"
2222
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"
3024
31-
echo "Applying topics: $DEPT $SUBJECT $SECTION"
25+
IFS='_' read -r INSTITUTE DEPT COURSE PROJECT SECTION TEAM <<< "$REPO"
3226
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

Comments
 (0)