-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsync_issues.rb
More file actions
executable file
·143 lines (128 loc) · 3.48 KB
/
Copy pathsync_issues.rb
File metadata and controls
executable file
·143 lines (128 loc) · 3.48 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
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
#!/usr/bin/env ruby
require 'json'
def query(q)
JSON.load(`gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='#{q}'`)
end
def get_issues(repo)
issues = []
# we can't get more than 100 issues at once, so parametrize query with cursor
query_builder = lambda do |condition| %Q{{
repository (owner: "zenithdb", name: "#{repo}") {
name
issues (first: 100, #{condition} states: [OPEN]) {
edges {
cursor
}
nodes {
id
number
title
timelineItems(first: 10, itemTypes: CROSS_REFERENCED_EVENT) {
nodes {
... on CrossReferencedEvent {
id
source {
... on Issue {
id
title
body
number
}
}
}
}
}
body
}
}
}
}}
end
# get first 100 issues
resp = query(query_builder.call(''))
# and continue until result is empty
while resp['data']['repository']['issues']['nodes'].size > 0 do
issues += resp['data']['repository']['issues']['nodes']
cursor = resp['data']['repository']['issues']['edges'][-1]['cursor']
# get next 100 issues
resp = query(query_builder.call("after: \"#{cursor}\","))
end
# fill tracked_in for all issues: check if issue that referenced this one has
# markdown list with our issue number
# XXX: cross-repo issues?
issues = issues.map do |issue|
{
'id' => issue['id'],
'number' => issue['number'],
'title' => issue['title'],
'tracked_in' => issue['timelineItems']['nodes']
.filter { |timeline_item|
body = timeline_item['source']['body']
num = issue['number']
body && (body.include?("- [ ] ##{num}") || body.include?("- [x] #{num}"))
}
.map { |timeline_item|
src = timeline_item['source']
"#{src['title']} (https://github.com/zenithdb/#{repo}/issues/#{src['number']})"
}
}
end
end
def add_item(project_id, repo, issue)
puts issue
r1 = query(%Q{
mutation {
addProjectNextItem(input: {
projectId: "#{project_id}"
contentId: "#{issue['id']}"
}) {
projectNextItem { id }
}
}
})
project_item_id = r1['data']['addProjectNextItem']['projectNextItem']['id']
# gh api graphql -f query='
# query{
# node(id: "PN_kwDOBKF3Cs1e-g") {
# ... on ProjectNext {
# fields(first: 20) {
# nodes {
# id
# name
# settings
# }
# }
# }
# }
# }'
tracked_field_id = 'MDE2OlByb2plY3ROZXh0RmllbGQ0ODg0OTM='
r2 = query(%Q{
mutation {
updateProjectNextItemField(input: {
projectId: "#{project_id}"
itemId: "#{project_item_id}"
fieldId: "#{tracked_field_id}"
value: "#{issue['tracked_in'].join(',')}"
}) {
projectNextItem { id }
}
}
})
puts r1
puts r2
end
# gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
# query {
# organization(login: "zenithdb"){
# projectNext(number: 6) {
# id
# }
# }
# }'
project_id = 'PN_kwDOBKF3Cs1e-g'
get_issues('zenith').each do |issue|
add_item(project_id, 'zenith', issue)
end
get_issues('console').each do |issue|
add_item(project_id, 'console', issue)
end