Skip to content

Commit 210a99a

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

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

.github/workflows/setup-repo.yml

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,57 @@
1-
name: Setup Repository
1+
name: Setup Repository Metadata
22

33
on:
44
push:
55
branches:
66
- main
7-
workflow_dispatch:
8-
9-
permissions:
10-
contents: write
7+
paths:
8+
- '.github/workflows/setup-repo.yml'
119

1210
jobs:
13-
add-topics:
11+
setup-metadata:
1412
runs-on: ubuntu-latest
13+
1514
steps:
15+
- name: Checkout Code
16+
uses: actions/checkout@v4
17+
1618
- name: Extract Repository Info
1719
id: extract
1820
run: |
19-
REPO_NAME="${{ github.event.repository.name }}"
20-
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:]')
25-
26-
echo "department=$DEPT" >> $GITHUB_OUTPUT
27-
echo "course=$COURSE" >> $GITHUB_OUTPUT
28-
echo "project=$PROJECT" >> $GITHUB_OUTPUT
29-
echo "section=$SECTION" >> $GITHUB_OUTPUT
21+
echo "REPO_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_OUTPUT
22+
NAME_PARTS=$(echo "${GITHUB_REPOSITORY#*/}" | tr '_' '\n')
23+
echo "${NAME_PARTS}" | nl
24+
echo "TOPICS=[]" > topics.json
25+
26+
mapfile -t parts <<< "$NAME_PARTS"
27+
28+
# Predefined base topics
29+
BASE_TOPICS=("template")
30+
31+
for word in ${NAME_PARTS}; do
32+
BASE_TOPICS+=("$(echo $word | tr '[:upper:]' '[:lower:]')")
33+
done
34+
35+
echo "TOPICS=$(jq -nc --argjson arr "$(printf '%s\n' "${BASE_TOPICS[@]}" | jq -R . | jq -s .)" '$arr')" >> $GITHUB_OUTPUT
36+
37+
- name: Print Extracted Info
38+
run: |
39+
echo "Repo Name: ${{ steps.extract.outputs.REPO_NAME }}"
40+
echo "Topics: ${{ steps.extract.outputs.TOPICS }}"
3041
31-
- name: Add Topics
42+
- name: Set Repository Topics
3243
uses: actions/github-script@v7
3344
with:
34-
github-token: ${{ secrets.GITHUB_TOKEN }}
45+
github-token: ${{ secrets.PAT_TOKEN }}
3546
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;
47+
const repo = context.repo.repo;
48+
const owner = context.repo.owner;
49+
const topics = JSON.parse(`${{ steps.extract.outputs.TOPICS }}`);
50+
4451
await github.rest.repos.replaceAllTopics({
45-
owner: repo.owner,
46-
repo: repo.repo,
52+
owner,
53+
repo,
4754
names: topics
4855
});
4956
50-
console.log("✅ Topics set: " + topics.join(', '));
57+
console.log(`Topics set for ${repo}:`, topics);

0 commit comments

Comments
 (0)