-
Notifications
You must be signed in to change notification settings - Fork 6
183 lines (172 loc) · 6.39 KB
/
copy-issues.yml
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: "Copy issues"
on:
workflow_dispatch:
jobs:
get-issue-labels:
if: github.repository != 'yumemi-inc/android-engineer-codecheck'
runs-on: ubuntu-latest
outputs:
labels: ${{ steps.output_label_data.outputs.value }}
steps:
- name: Getting Labels data
id: get_label_data
uses: octokit/request-action@v2.1.7
with:
route: GET /repos/yumemi-inc/android-engineer-codecheck/labels
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- id: output_label_data
run: |
result=$(echo '${{ steps.get_label_data.outputs.data }}' | sed -z 's/\n//g')
echo "value=${result}" >> $GITHUB_OUTPUT
create-issue-labels:
needs: get-issue-labels
runs-on: ubuntu-latest
permissions:
issues: write
strategy:
matrix:
label: ${{ fromJson(needs.get-issue-labels.outputs.labels) }}
steps:
- name: Create a label
uses: octokit/request-action@v2.1.7
with:
route: POST /repos/${{ github.repository }}/labels
name: ${{ matrix.label.name }}
color: ${{ matrix.label.color }}
description: ${{ matrix.label.description }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
get-milestones:
if: github.repository != 'yumemi-inc/android-engineer-codecheck'
runs-on: ubuntu-latest
outputs:
milestones: ${{ steps.output_milestones_data.outputs.value }}
steps:
- name: Getting Milestones data
id: get_milestones_data
uses: octokit/request-action@v2.1.7
with:
route: GET /repos/yumemi-inc/android-engineer-codecheck/milestones
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- id: output_milestones_data
run: |
result=$(echo '${{ steps.get_milestones_data.outputs.data }}' | sed -z 's/\n//g')
echo "value=${result}" >> $GITHUB_OUTPUT
create-milestones:
needs: get-milestones
runs-on: ubuntu-latest
permissions:
issues: write
strategy:
matrix:
milestone: ${{ fromJson(needs.get-milestones.outputs.milestones) }}
steps:
- name: Create a milestone
uses: octokit/request-action@v2.1.7
with:
route: POST /repos/${{ github.repository }}/milestones
title: ${{ matrix.milestone.title }}
description: ${{ matrix.milestone.description }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
get-myrepo-milestones:
needs: create-milestones
runs-on: ubuntu-latest
permissions:
issues: read
outputs:
milestones: ${{ steps.output_milestones_data.outputs.value }}
steps:
- name: Getting Milestones data
id: get_milestones_data
uses: octokit/request-action@v2.1.7
with:
route: GET /repos/${{ github.repository }}/milestones
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- id: output_milestones_data
run: |
result=$(echo '${{ steps.get_milestones_data.outputs.data }}' | sed -z 's/\n//g')
echo "value=${result}" >> $GITHUB_OUTPUT
get-issues:
if: github.repository != 'yumemi-inc/android-engineer-codecheck'
runs-on: ubuntu-latest
outputs:
issues: ${{ steps.output_issues_data.outputs.value }}
steps:
- name: Getting issues data
id: get_issues_data
uses: octokit/request-action@v2.1.7
with:
route: GET /repos/yumemi-inc/android-engineer-codecheck/issues
sort: created
direction: asc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- id: output_issues_data
run: |
result=$(echo '${{ steps.get_issues_data.outputs.data }}' | jq -c '[.[] | select(has("milestone")) | select(.milestone != null)]')
echo "value=${result}" >> $GITHUB_OUTPUT
get-myrepo-issues:
if: github.repository != 'yumemi-inc/android-engineer-codecheck'
runs-on: ubuntu-latest
permissions:
issues: read
outputs:
issues: ${{ steps.output_issues_data.outputs.value }}
steps:
- name: Getting issues data
id: get_issues_data
uses: octokit/request-action@v2.1.7
with:
route: GET /repos/${{ github.repository }}/issues
state: all
per_page: 100
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- id: output_issues_data
run: |
result=$(echo '${{ steps.get_issues_data.outputs.data }}' | sed -z 's/\n//g')
echo "value=${result}" >> $GITHUB_OUTPUT
create-issues:
needs: [ create-issue-labels, get-myrepo-milestones, get-issues, get-myrepo-issues ]
runs-on: ubuntu-latest
permissions:
issues: write
strategy:
max-parallel: 1
matrix:
issue: ${{ fromJson(needs.get-issues.outputs.issues) }}
steps:
- name: Find milestone
id: find-milestone
run: |
milestones='${{ needs.get-myrepo-milestones.outputs.milestones }}'
milestone_number=$(echo ${milestones} | jq '.[] | select (.title=="${{ matrix.issue.milestone.title }}") | .number' )
echo "number=${milestone_number}" >> $GITHUB_OUTPUT
- name: Create a issue
run: |
body=$(echo '${{ matrix.issue.body }}')
body="${body//$'\n'/\\n}"
body="${body//$'\r'/\\r}"
if [[ "$body" =~ '#'[0-9] ]]; then
link=$(echo "$body" | grep -o -E "#[0-9]+")
num=$(echo $link | tr -d '#')
issues=$(echo '${{ needs.get-issues.outputs.issues }}' | jq '[ . as $d | keys[] | $d[.] + {index:.} ]')
issue_index=$(echo "$issues" | jq ".[] | select (.number==${num}) | .index")
my_issue_count=$(echo '${{ needs.get-myrepo-issues.outputs.issues }}' | jq '. | length')
num=$(($issue_index+$my_issue_count+1))
body=$(echo $body | sed "s/$link/#${num}/g")
fi
labels='${{ toJson(matrix.issue.labels.*.name) }}'
curl -X POST -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues \
-d "{
\"title\" : \"${{ matrix.issue.title }}\",
\"body\" : \"$body\",
\"labels\" : ${labels},
\"milestone\" : ${{ steps.find-milestone.outputs.number }}
}"