@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
88
99use crate :: util:: comma;
1010
11- use super :: labels:: GhLabel ;
11+ use super :: { issue_id :: Repository , labels:: GhLabel } ;
1212
1313#[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , PartialOrd , Ord ) ]
1414pub struct ExistingGithubIssue {
@@ -77,13 +77,54 @@ impl std::fmt::Display for ExistingIssueState {
7777 }
7878}
7979
80+ pub struct CountIssues {
81+ pub open : u32 ,
82+ pub closed : u32 ,
83+ }
84+
85+ pub fn count_issues_matching_search (
86+ repository : & Repository ,
87+ search : & str ,
88+ ) -> anyhow:: Result < CountIssues > {
89+ #[ derive( Deserialize ) ]
90+ struct JustState {
91+ state : ExistingIssueState ,
92+ }
93+
94+ let output = Command :: new ( "gh" )
95+ . arg ( "-R" )
96+ . arg ( & repository. to_string ( ) )
97+ . arg ( "issue" )
98+ . arg ( "list" )
99+ . arg ( "-S" )
100+ . arg ( search)
101+ . arg ( "-s" )
102+ . arg ( "all" )
103+ . arg ( "--json" )
104+ . arg ( "state" )
105+ . output ( ) ?;
106+
107+ let existing_issues: Vec < JustState > = serde_json:: from_slice ( & output. stdout ) ?;
108+
109+ let mut count_issues = CountIssues { open : 0 , closed : 0 } ;
110+
111+ for issue in & existing_issues {
112+ match issue. state {
113+ ExistingIssueState :: Open => count_issues. open += 1 ,
114+ ExistingIssueState :: Closed => count_issues. closed += 1 ,
115+ }
116+ }
117+
118+ Ok ( count_issues)
119+ }
120+
80121pub fn list_issue_titles_in_milestone (
81- repository : & str ,
122+ repository : & Repository ,
82123 timeframe : & str ,
83124) -> anyhow:: Result < BTreeMap < String , ExistingGithubIssue > > {
84125 let output = Command :: new ( "gh" )
85126 . arg ( "-R" )
86- . arg ( repository)
127+ . arg ( & repository. to_string ( ) )
87128 . arg ( "issue" )
88129 . arg ( "list" )
89130 . arg ( "-m" )
@@ -124,7 +165,7 @@ pub fn list_issue_titles_in_milestone(
124165}
125166
126167pub fn create_issue (
127- repository : & str ,
168+ repository : & Repository ,
128169 body : & str ,
129170 title : & str ,
130171 labels : & [ String ] ,
@@ -133,7 +174,7 @@ pub fn create_issue(
133174) -> anyhow:: Result < ( ) > {
134175 let output = Command :: new ( "gh" )
135176 . arg ( "-R" )
136- . arg ( & repository)
177+ . arg ( & repository. to_string ( ) )
137178 . arg ( "issue" )
138179 . arg ( "create" )
139180 . arg ( "-b" )
@@ -160,15 +201,15 @@ pub fn create_issue(
160201}
161202
162203pub fn sync_assignees (
163- repository : & str ,
204+ repository : & Repository ,
164205 number : u64 ,
165206 remove_owners : & BTreeSet < String > ,
166207 add_owners : & BTreeSet < String > ,
167208) -> anyhow:: Result < ( ) > {
168209 let mut command = Command :: new ( "gh" ) ;
169210 command
170211 . arg ( "-R" )
171- . arg ( & repository)
212+ . arg ( & repository. to_string ( ) )
172213 . arg ( "issue" )
173214 . arg ( "edit" )
174215 . arg ( number. to_string ( ) ) ;
@@ -203,10 +244,10 @@ impl ExistingGithubIssue {
203244 }
204245}
205246
206- pub fn lock_issue ( repository : & str , number : u64 ) -> anyhow:: Result < ( ) > {
247+ pub fn lock_issue ( repository : & Repository , number : u64 ) -> anyhow:: Result < ( ) > {
207248 let output = Command :: new ( "gh" )
208249 . arg ( "-R" )
209- . arg ( repository)
250+ . arg ( & repository. to_string ( ) )
210251 . arg ( "issue" )
211252 . arg ( "lock" )
212253 . arg ( number. to_string ( ) )
@@ -225,7 +266,7 @@ pub fn lock_issue(repository: &str, number: u64) -> anyhow::Result<()> {
225266 // Leave a comment explaining what is going on.
226267 let output = Command :: new ( "gh" )
227268 . arg ( "-R" )
228- . arg ( repository)
269+ . arg ( & repository. to_string ( ) )
229270 . arg ( "issue" )
230271 . arg ( "comment" )
231272 . arg ( number. to_string ( ) )
0 commit comments