Skip to content

Commit b507fa7

Browse files
authored
Create map-issues.yml
1 parent e4644b9 commit b507fa7

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.github/workflows/map-issues.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Map Issues to Project
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
issues: read
8+
projects: write
9+
contents: read
10+
11+
jobs:
12+
map_issues:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: '16'
23+
24+
- name: Install GitHub CLI
25+
run: |
26+
sudo apt update
27+
sudo apt install -y gh
28+
29+
- name: Authenticate GitHub CLI
30+
env:
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: |
33+
gh auth login --with-token <<< "${GH_TOKEN}"
34+
35+
- name: Get All Issues
36+
id: get_issues
37+
env:
38+
REPO: ${{ github.repository }}
39+
run: |
40+
gh issue list --state all --json number,title,labels,state -R $REPO > all_issues.json
41+
42+
- name: Map Issues to Project
43+
env:
44+
PROJECT_URL: https://github.com/users/sameerasw/projects/2
45+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
run: |
47+
# Extract project ID from the URL
48+
PROJECT_ID=$(echo "${PROJECT_URL}" | grep -oE "projects/[0-9]+" | cut -d'/' -f2)
49+
50+
# Iterate through all issues and add them to the project
51+
for issue_number in $(jq -r '.[].number' all_issues.json); do
52+
issue_data=$(jq ".[] | select(.number == ${issue_number})" all_issues.json)
53+
title=$(echo "$issue_data" | jq -r '.title')
54+
labels=$(echo "$issue_data" | jq -c '.labels | map(.name)')
55+
state=$(echo "$issue_data" | jq -r '.state')
56+
57+
echo "Adding issue #${issue_number} (${title}) to project..."
58+
59+
# Add issue to the project
60+
gh api -X POST "/projects/${PROJECT_ID}/items" \
61+
-F content_id="$(gh issue view ${issue_number} --json id -q .id)" \
62+
-F content_type="Issue" \
63+
-H "Authorization: token ${GH_TOKEN}"
64+
done

0 commit comments

Comments
 (0)