Skip to content

Commit 8d37896

Browse files
committed
support root issue
1 parent 40b361b commit 8d37896

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

graphql/query.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ query TrackIssuesQuery($owner: String!, $repository_name: String!, $number: Int!
1010
repository(owner: $owner, name:$repository_name) {
1111
issue(number: $number){
1212
title
13+
number
14+
state
15+
url
1316
trackedIssues(first: 10){
1417
nodes {
1518
number

src/main.rs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ pub struct IssueQuery;
2727
)]
2828
pub struct TrackIssuesQuery;
2929

30-
type IssueGraph = HashMap<i64, Vec<Issue>>;
30+
type IssueGraph = HashMap<Issue, Vec<Issue>>;
31+
32+
#[derive(Hash, PartialEq, Eq)]
3133
struct Issue {
3234
number: i64,
3335
title: String,
@@ -72,11 +74,14 @@ async fn run(client: Client, args: CliArgs) -> Result<(), anyhow::Error> {
7274
fn build_mermaid(issue_map: IssueGraph) -> String {
7375
let mut body = vec![];
7476
let mut links = vec![];
75-
for (number, issues) in issue_map {
77+
for (parent_issue, issues) in issue_map {
7678
for issue in issues {
7779
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,
8085
child = issue.number,
8186
title = issue.title,
8287
state = issue.state,
@@ -124,52 +129,55 @@ async fn fetch_tracked_issue(
124129
#[async_recursion]
125130
async fn _fetch_tracked_issue(
126131
client: &reqwest::Client,
127-
root_issue: i64,
132+
root_issue_number: i64,
128133
owner: &str,
129134
repository: &str,
130135
issue_graph: &mut IssueGraph,
131136
) -> Result<(), anyhow::Error> {
132137
let v = track_issues_query::Variables {
133138
owner: owner.into(),
134139
repository_name: repository.into(),
135-
number: root_issue,
140+
number: root_issue_number,
136141
};
137142
let request_body = TrackIssuesQuery::build_query(v);
138143

139144
let res = client.post(GITHUB_URL).json(&request_body).send().await?;
140145
let response_body: Response<track_issues_query::ResponseData> = res.json().await?;
141146

142-
// FIXME unwrap地獄を修正したい
143-
for i in response_body
147+
let parent_issue = response_body
144148
.data
145149
.expect("Response is None")
146150
.repository
147151
.expect("Not found repository")
148152
.issue
149-
.expect("Not found issue")
153+
.expect("Not found issue");
154+
155+
// FIXME unwrap地獄を修正したい
156+
for i in parent_issue
150157
.tracked_issues
151158
.nodes
152159
.expect("Not found tracked issues")
153160
{
154161
let i = i.as_ref().unwrap();
155162

156-
let state = match i.state {
157-
track_issues_query::IssueState::OPEN => "OPEN",
158-
track_issues_query::IssueState::CLOSED => "CLOSED",
159-
_ => "OTHER",
160-
};
161-
162163
let issue = Issue {
163164
number: i.number,
164165
url: i.url.clone().into(),
165166
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),
167175
};
168176

169-
if let Some(issues) = issue_graph.get_mut(&root_issue) {
177+
if let Some(issues) = issue_graph.get_mut(&parent_issue) {
170178
issues.push(issue);
171179
} else {
172-
issue_graph.insert(root_issue, vec![issue]);
180+
issue_graph.insert(parent_issue, vec![issue]);
173181
}
174182

175183
_fetch_tracked_issue(client, i.number, owner, repository, issue_graph).await?;
@@ -191,3 +199,12 @@ fn github_client(github_token: &str) -> Result<Client, Error> {
191199
.build()?;
192200
Ok(client)
193201
}
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

Comments
 (0)