@@ -6,8 +6,8 @@ use crate::auth::{AuthService, LoginRequest, LoginTokenSource};
66use crate :: command:: { CommandError , CommandOutcome , EXIT_OK , OutputFormat } ;
77use crate :: gitee_api:: PullRequestListFilters ;
88use crate :: issue:: {
9- IssueCommentBodySource , IssueCommentRequest , IssueListRequest , IssueService , IssueStateFilter ,
10- IssueViewRequest ,
9+ IssueBodySource , IssueCommentRequest , IssueCreateRequest , IssueListRequest , IssueService ,
10+ IssueStateFilter , IssueViewRequest ,
1111} ;
1212use crate :: pr:: {
1313 PrCheckoutRequest , PrCommentRequest , PrCreateRequest , PrListRequest , PrService ,
@@ -73,6 +73,9 @@ fn run_issue(args: &[String]) -> Result<CommandOutcome, CommandError> {
7373 let issue = IssueService :: from_env ( ) ;
7474
7575 match subcommand. as_str ( ) {
76+ "create" => execute_parsed ( parse_issue_create_args ( rest) , |request| {
77+ issue. create ( request)
78+ } ) ,
7679 "comment" => execute_parsed ( parse_issue_comment_args ( rest) , |request| {
7780 issue. comment ( request)
7881 } ) ,
@@ -265,11 +268,11 @@ fn parse_issue_comment_args(
265268
266269 let Some ( body) = body_values
267270 . last ( )
268- . map ( |value| IssueCommentBodySource :: Flag ( value. clone ( ) ) )
271+ . map ( |value| IssueBodySource :: Inline ( value. clone ( ) ) )
269272 . or_else ( || {
270273 body_file_values
271274 . last ( )
272- . map ( |value| IssueCommentBodySource :: File ( PathBuf :: from ( value) ) )
275+ . map ( |value| IssueBodySource :: File ( PathBuf :: from ( value) ) )
273276 } )
274277 else {
275278 return Err ( CommandError :: usage (
@@ -286,6 +289,44 @@ fn parse_issue_comment_args(
286289 } )
287290}
288291
292+ fn parse_issue_create_args (
293+ args : & [ String ] ,
294+ ) -> Result < ParseOutcome < IssueCreateRequest > , CommandError > {
295+ map_parsed ( parse_matches ( issue_create_command ( ) , args) , |matches| {
296+ let output = output_format ( & matches) ;
297+ let repo = last_value ( & matches, "repo" ) ;
298+ let title = last_value ( & matches, "title" ) ;
299+ let body_values = values ( & matches, "body" ) ;
300+ let body_file_values = values ( & matches, "body_file" ) ;
301+
302+ if body_values. len ( ) + body_file_values. len ( ) > 1 {
303+ return Err ( CommandError :: usage (
304+ "provide only one of --body or --body-file" ,
305+ ) ) ;
306+ }
307+
308+ let Some ( title) = title else {
309+ return Err ( CommandError :: usage ( "issue create requires --title" ) ) ;
310+ } ;
311+
312+ let body = body_values
313+ . last ( )
314+ . map ( |value| IssueBodySource :: Inline ( value. clone ( ) ) )
315+ . or_else ( || {
316+ body_file_values
317+ . last ( )
318+ . map ( |value| IssueBodySource :: File ( PathBuf :: from ( value) ) )
319+ } ) ;
320+
321+ Ok ( IssueCreateRequest {
322+ output,
323+ repo,
324+ title,
325+ body,
326+ } )
327+ } )
328+ }
329+
289330fn parse_pr_view_args ( args : & [ String ] ) -> Result < ParseOutcome < PrViewRequest > , CommandError > {
290331 map_parsed ( parse_matches ( pr_view_command ( ) , args) , |matches| {
291332 let output = output_format ( & matches) ;
@@ -661,6 +702,7 @@ fn auth_help_command() -> Command {
661702
662703fn issue_help_command ( ) -> Command {
663704 base_command ( "issue" )
705+ . subcommand ( issue_create_command ( ) )
664706 . subcommand ( issue_comment_command ( ) )
665707 . subcommand ( issue_list_command ( ) )
666708 . subcommand ( issue_view_command ( ) )
@@ -726,6 +768,15 @@ fn issue_comment_command() -> Command {
726768 . arg ( positionals_arg ( ) )
727769}
728770
771+ fn issue_create_command ( ) -> Command {
772+ base_command ( "create" )
773+ . arg ( json_flag ( ) )
774+ . arg ( string_option ( "repo" , "repo" , "REPO" ) )
775+ . arg ( string_option ( "title" , "title" , "TITLE" ) )
776+ . arg ( string_option ( "body" , "body" , "BODY" ) )
777+ . arg ( string_option ( "body_file" , "body-file" , "PATH" ) )
778+ }
779+
729780fn pr_view_command ( ) -> Command {
730781 base_command ( "view" )
731782 . arg ( json_flag ( ) )
0 commit comments