Skip to content

Commit 47de91a

Browse files
Update setup-repo.yml
1 parent e2900b8 commit 47de91a

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

.github/workflows/setup-repo.yml

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
1-
name: Assign Topics Automatically
1+
name: Setup Repository
22

33
on:
44
push:
5-
branches: [main]
6-
# This ensures it runs only once after repo is created with initial push
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
711

812
jobs:
9-
assign-topics:
13+
add-topics:
1014
runs-on: ubuntu-latest
11-
12-
permissions:
13-
contents: read
14-
repository-projects: write
15-
metadata: write
16-
1715
steps:
18-
- name: Extract Repo Info
16+
- name: Extract Repository Info
1917
id: extract
2018
run: |
21-
REPO="${GITHUB_REPOSITORY##*/}"
19+
REPO_NAME="${{ github.event.repository.name }}"
2220
23-
echo "Full Repo Name: $REPO"
21+
DEPT=$(echo "$REPO_NAME" | cut -d'_' -f2 | tr '[:upper:]' '[:lower:]')
22+
COURSE=$(echo "$REPO_NAME" | cut -d'_' -f3 | tr '[:upper:]' '[:lower:]')
23+
PROJECT=$(echo "$REPO_NAME" | cut -d'_' -f4 | tr '[:upper:]' '[:lower:]')
24+
SECTION=$(echo "$REPO_NAME" | cut -d'_' -f5 | tr '[:upper:]' '[:lower:]')
2425
25-
IFS='_' read -r INSTITUTE DEPT COURSE PROJECT SECTION TEAM <<< "$REPO"
26-
27-
echo "institute=$INSTITUTE" >> $GITHUB_OUTPUT
2826
echo "department=$DEPT" >> $GITHUB_OUTPUT
2927
echo "course=$COURSE" >> $GITHUB_OUTPUT
3028
echo "project=$PROJECT" >> $GITHUB_OUTPUT
3129
echo "section=$SECTION" >> $GITHUB_OUTPUT
32-
echo "team_id=$TEAM" >> $GITHUB_OUTPUT
3330
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 }}'
31+
- name: Add Topics
32+
uses: actions/github-script@v7
33+
with:
34+
github-token: ${{ secrets.GITHUB_TOKEN }}
35+
script: |
36+
const topics = [
37+
'${{ steps.extract.outputs.department }}',
38+
'${{ steps.extract.outputs.course }}',
39+
'${{ steps.extract.outputs.project }}',
40+
'${{ steps.extract.outputs.section }}'
41+
];
42+
43+
const repo = context.repo;
44+
await github.rest.repos.replaceAllTopics({
45+
owner: repo.owner,
46+
repo: repo.repo,
47+
names: topics
48+
});
49+
50+
console.log("✅ Topics set: " + topics.join(', '));

0 commit comments

Comments
 (0)