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