-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_github_board.sh
97 lines (73 loc) · 3.35 KB
/
copy_github_board.sh
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
GITHUB_AUTH_TOKEN=$1
SOURCE_GITHUB_USERNAME=$2
SOURCE_REPO_NAME=$3
TARGET_GITHUB_USERNAME=$4
TARGET_REPO_NAME=$5
source_project_id=( $(curl \
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
-H "Accept: application/vnd.github.inertia-preview+json" \
https://api.github.com/repos/${SOURCE_GITHUB_USERNAME}/${SOURCE_REPO_NAME}/projects | jq .[0].id) )
target_project_id=( $(curl \
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
-H "Accept: application/vnd.github.inertia-preview+json" \
https://api.github.com/repos/${TARGET_GITHUB_USERNAME}/${TARGET_REPO_NAME}/projects | jq .[0].id) )
echo "source_project_id: ${source_project_id}"
sourceColumnIds=( $(curl \
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
-H "Accept: application/vnd.github.inertia-preview+json" \
https://api.github.com/projects/${source_project_id}/columns | jq .[].id) )
targetColumnIds=( $(curl \
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
-H "Accept: application/vnd.github.inertia-preview+json" \
https://api.github.com/projects/${target_project_id}/columns | jq .[].id) )
if [ "${#videos[@]}" -ne "${#subtitles[@]}" ]; then
echo "Different number of columns in between projects"
exit -1
fi
for sourceColumnIndex in "${!sourceColumnIds[@]}"
do
sourceColumnId=${sourceColumnIds[$sourceColumnIndex]}
sourceColumnId=${sourceColumnId//[^a-zA-Z0-9_]/}
targetColumnId=${targetColumnIds[$sourceColumnIndex]}
targetColumnId=${targetColumnId//[^a-zA-Z0-9_]/}
curl \
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
-H "Accept: application/vnd.github.inertia-preview+json" \
https://api.github.com/projects/columns/${sourceColumnId}/cards \
| jq reverse \
| jq -c '.[]' \
| while read card; do
# find issue linked into a card
source_issue_url=$(jq '.content_url' <<< "$card")
test="api.github.com/repos/microverseinc/curriculum-javascript/issues/4"
prefix="\"https://"
suffix="\""
source_issue_url=${source_issue_url/#$prefix}
source_issue_url=${source_issue_url/%$suffix}
title="$(curl \
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
"https://${source_issue_url}" | jq .title)"
body="$(curl \
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
"https://${source_issue_url}" | jq .body)"
# create a duplicate of the issue
issue_data='{"title":'${title}',"body":'${body}'}'
created_issue_id=( $(curl \
-X POST \
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
-d "${issue_data}" \
https://api.github.com/repos/${TARGET_GITHUB_USERNAME}/${TARGET_REPO_NAME}/issues | jq .id))
# create a duplicate of the card with a link to a newly created issue
card_data='{"content_id":'${created_issue_id}',"content_type":"Issue"}'
curl \
-w 'HTTP Status: %{http_code}' --silent --output /dev/null \
-X POST \
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \
-H "Accept: application/vnd.github.inertia-preview+json" \
-d "${card_data}" \
https://api.github.com/projects/columns/${targetColumnId}/cards
done
done