@@ -27,7 +27,9 @@ pub struct IssueQuery;
27
27
) ]
28
28
pub struct TrackIssuesQuery ;
29
29
30
- type IssueGraph = HashMap < i64 , Vec < Issue > > ;
30
+ type IssueGraph = HashMap < Issue , Vec < Issue > > ;
31
+
32
+ #[ derive( Hash , PartialEq , Eq ) ]
31
33
struct Issue {
32
34
number : i64 ,
33
35
title : String ,
@@ -72,11 +74,14 @@ async fn run(client: Client, args: CliArgs) -> Result<(), anyhow::Error> {
72
74
fn build_mermaid ( issue_map : IssueGraph ) -> String {
73
75
let mut body = vec ! [ ] ;
74
76
let mut links = vec ! [ ] ;
75
- for ( number , issues) in issue_map {
77
+ for ( parent_issue , issues) in issue_map {
76
78
for issue in issues {
77
79
let t = format ! (
78
- "{parent} --> {child}[\" {title} #{number}\" ]:::{state}" ,
79
- parent = number,
80
+ "{parent}[\" {parent_title} #{parent_number}\" ]:::{parent_state} --> {child}[\" {title} #{number}\" ]:::{state}" ,
81
+ parent = parent_issue. number,
82
+ parent_title = parent_issue. title,
83
+ parent_state = parent_issue. state,
84
+ parent_number = parent_issue. number,
80
85
child = issue. number,
81
86
title = issue. title,
82
87
state = issue. state,
@@ -124,52 +129,55 @@ async fn fetch_tracked_issue(
124
129
#[ async_recursion]
125
130
async fn _fetch_tracked_issue (
126
131
client : & reqwest:: Client ,
127
- root_issue : i64 ,
132
+ root_issue_number : i64 ,
128
133
owner : & str ,
129
134
repository : & str ,
130
135
issue_graph : & mut IssueGraph ,
131
136
) -> Result < ( ) , anyhow:: Error > {
132
137
let v = track_issues_query:: Variables {
133
138
owner : owner. into ( ) ,
134
139
repository_name : repository. into ( ) ,
135
- number : root_issue ,
140
+ number : root_issue_number ,
136
141
} ;
137
142
let request_body = TrackIssuesQuery :: build_query ( v) ;
138
143
139
144
let res = client. post ( GITHUB_URL ) . json ( & request_body) . send ( ) . await ?;
140
145
let response_body: Response < track_issues_query:: ResponseData > = res. json ( ) . await ?;
141
146
142
- // FIXME unwrap地獄を修正したい
143
- for i in response_body
147
+ let parent_issue = response_body
144
148
. data
145
149
. expect ( "Response is None" )
146
150
. repository
147
151
. expect ( "Not found repository" )
148
152
. issue
149
- . expect ( "Not found issue" )
153
+ . expect ( "Not found issue" ) ;
154
+
155
+ // FIXME unwrap地獄を修正したい
156
+ for i in parent_issue
150
157
. tracked_issues
151
158
. nodes
152
159
. expect ( "Not found tracked issues" )
153
160
{
154
161
let i = i. as_ref ( ) . unwrap ( ) ;
155
162
156
- let state = match i. state {
157
- track_issues_query:: IssueState :: OPEN => "OPEN" ,
158
- track_issues_query:: IssueState :: CLOSED => "CLOSED" ,
159
- _ => "OTHER" ,
160
- } ;
161
-
162
163
let issue = Issue {
163
164
number : i. number ,
164
165
url : i. url . clone ( ) . into ( ) ,
165
166
title : i. title . clone ( ) . into ( ) ,
166
- state : state. into ( ) ,
167
+ state : state_to_string ( & i. state ) ,
168
+ } ;
169
+
170
+ let parent_issue = Issue {
171
+ number : parent_issue. number ,
172
+ url : parent_issue. url . clone ( ) . into ( ) ,
173
+ title : parent_issue. title . clone ( ) . into ( ) ,
174
+ state : state_to_string ( & parent_issue. state ) ,
167
175
} ;
168
176
169
- if let Some ( issues) = issue_graph. get_mut ( & root_issue ) {
177
+ if let Some ( issues) = issue_graph. get_mut ( & parent_issue ) {
170
178
issues. push ( issue) ;
171
179
} else {
172
- issue_graph. insert ( root_issue , vec ! [ issue] ) ;
180
+ issue_graph. insert ( parent_issue , vec ! [ issue] ) ;
173
181
}
174
182
175
183
_fetch_tracked_issue ( client, i. number , owner, repository, issue_graph) . await ?;
@@ -191,3 +199,12 @@ fn github_client(github_token: &str) -> Result<Client, Error> {
191
199
. build ( ) ?;
192
200
Ok ( client)
193
201
}
202
+
203
+ fn state_to_string ( state : & track_issues_query:: IssueState ) -> String {
204
+ match state {
205
+ track_issues_query:: IssueState :: OPEN => "OPEN" ,
206
+ track_issues_query:: IssueState :: CLOSED => "CLOSED" ,
207
+ _ => "OTHER" ,
208
+ }
209
+ . to_string ( )
210
+ }
0 commit comments