|
1 | | -name: Assign Topics Automatically |
| 1 | +name: Setup Repository |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | 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 |
7 | 11 |
|
8 | 12 | jobs: |
9 | | - assign-topics: |
| 13 | + add-topics: |
10 | 14 | runs-on: ubuntu-latest |
11 | | - |
12 | | - permissions: |
13 | | - contents: read |
14 | | - repository-projects: write |
15 | | - metadata: write |
16 | | - |
17 | 15 | steps: |
18 | | - - name: Extract Repo Info |
| 16 | + - name: Extract Repository Info |
19 | 17 | id: extract |
20 | 18 | run: | |
21 | | - REPO="${GITHUB_REPOSITORY##*/}" |
| 19 | + REPO_NAME="${{ github.event.repository.name }}" |
22 | 20 |
|
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:]') |
24 | 25 |
|
25 | | - IFS='_' read -r INSTITUTE DEPT COURSE PROJECT SECTION TEAM <<< "$REPO" |
26 | | -
|
27 | | - echo "institute=$INSTITUTE" >> $GITHUB_OUTPUT |
28 | 26 | echo "department=$DEPT" >> $GITHUB_OUTPUT |
29 | 27 | echo "course=$COURSE" >> $GITHUB_OUTPUT |
30 | 28 | echo "project=$PROJECT" >> $GITHUB_OUTPUT |
31 | 29 | echo "section=$SECTION" >> $GITHUB_OUTPUT |
32 | | - echo "team_id=$TEAM" >> $GITHUB_OUTPUT |
33 | 30 |
|
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