-
Notifications
You must be signed in to change notification settings - Fork 4
187 lines (175 loc) · 6.33 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
184
185
186
187
name: "Copy issues"
on:
workflow_dispatch:
jobs:
get-issue-labels:
if: github.repository != 'yumemi-inc/ios-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.0
with:
route: GET /repos/yumemi-inc/ios-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 "::set-output name=value::${result}"
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.0
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/ios-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.0
with:
route: GET /repos/yumemi-inc/ios-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 "::set-output name=value::${result}"
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.0
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.0
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/%0A/g' | sed -z 's/\r/%0D/g')
echo "::set-output name=value::${result}"
get-issues:
if: github.repository != 'yumemi-inc/ios-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.0
with:
route: GET /repos/yumemi-inc/ios-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 }}' | sed -z 's/\n/%0A/g' | sed -z 's/\r/%0D/g')
echo "::set-output name=value::${result}"
- run: echo -e '${{ steps.output_issues_data.outputs.value }}'
get-myrepo-issues:
if: github.repository != 'yumemi-inc/ios-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.0
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/%0A/g' | sed -z 's/\r/%0D/g')
echo "::set-output name=value::${result}"
- run: echo -e '${{ steps.output_issues_data.outputs.value }}'
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 "::set-output name=number::${milestone_number}"
- name: Create a issue
if: ${{ matrix.issue.pull_request == null }}
run: |
body=$(echo '${{ matrix.issue.body }}')
body="${body//$'\n'/\\n}"
body="${body//$'\r'/\\r}"
if [[ "$body" =~ '#'[0-9] ]]; then
link=$(echo "$body" | grep -o "#[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: token ${{ 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 }}
}"