@@ -4,12 +4,16 @@ use anstream::println;
4
4
use clap:: Args ;
5
5
use crossterm:: style:: Stylize ;
6
6
use eyre:: Result ;
7
+ use fig_diagnostic:: Diagnostics ;
7
8
use fig_util:: system_info:: is_remote;
8
9
use fig_util:: {
9
10
CLI_BINARY_NAME ,
11
+ GITHUB_REPO_NAME ,
10
12
PRODUCT_NAME ,
11
13
} ;
12
14
15
+ const TEMPLATE_NAME : & str = "1_bug_report_template.yml" ;
16
+
13
17
#[ derive( Debug , Args , PartialEq , Eq ) ]
14
18
pub struct IssueArgs {
15
19
/// Force issue creation
@@ -41,8 +45,87 @@ impl IssueArgs {
41
45
_ => joined_description,
42
46
} ;
43
47
44
- todo ! ( ) ;
48
+ let _ = IssueCreator {
49
+ title : Some ( issue_title) ,
50
+ expected_behavior : None ,
51
+ actual_behavior : None ,
52
+ steps_to_reproduce : None ,
53
+ additional_environment : None ,
54
+ }
55
+ . create_url ( )
56
+ . await ;
45
57
46
58
Ok ( ExitCode :: SUCCESS )
47
59
}
48
60
}
61
+
62
+ pub struct IssueCreator {
63
+ /// Issue title
64
+ pub title : Option < String > ,
65
+ /// Issue description
66
+ pub expected_behavior : Option < String > ,
67
+ /// Issue description
68
+ pub actual_behavior : Option < String > ,
69
+ /// Issue description
70
+ pub steps_to_reproduce : Option < String > ,
71
+ /// Issue description
72
+ pub additional_environment : Option < String > ,
73
+ }
74
+
75
+ impl IssueCreator {
76
+ pub async fn create_url ( & self ) -> Result < url:: Url > {
77
+ println ! ( "Heading over to GitHub..." ) ;
78
+
79
+ let warning = |text : & String | {
80
+ format ! ( "<This will be visible to anyone. Do not include personal or sensitive information>\n \n {text}" )
81
+ } ;
82
+ let diagnostics = Diagnostics :: new ( ) . await ;
83
+
84
+ let os = match & diagnostics. system_info . os {
85
+ Some ( os) => os. to_string ( ) ,
86
+ None => "None" . to_owned ( ) ,
87
+ } ;
88
+
89
+ let diagnostic_info = match diagnostics. user_readable ( ) {
90
+ Ok ( diagnostics) => diagnostics,
91
+ Err ( err) => {
92
+ eprintln ! ( "Error getting diagnostics: {err}" ) ;
93
+ "Error occurred while generating diagnostics" . to_owned ( )
94
+ } ,
95
+ } ;
96
+
97
+ let environment = match & self . additional_environment {
98
+ Some ( ctx) => format ! ( "{diagnostic_info}\n {ctx}" ) ,
99
+ None => diagnostic_info,
100
+ } ;
101
+
102
+ let mut params = Vec :: new ( ) ;
103
+ params. push ( ( "template" , TEMPLATE_NAME . to_string ( ) ) ) ;
104
+ params. push ( ( "os" , os) ) ;
105
+ params. push ( ( "environment" , warning ( & environment) ) ) ;
106
+
107
+ if let Some ( t) = self . title . clone ( ) {
108
+ params. push ( ( "title" , t) ) ;
109
+ }
110
+ if let Some ( t) = self . expected_behavior . as_ref ( ) {
111
+ params. push ( ( "expected" , warning ( t) ) ) ;
112
+ }
113
+ if let Some ( t) = self . actual_behavior . as_ref ( ) {
114
+ params. push ( ( "actual" , warning ( t) ) ) ;
115
+ }
116
+ if let Some ( t) = self . steps_to_reproduce . as_ref ( ) {
117
+ params. push ( ( "reproduce" , warning ( t) ) ) ;
118
+ }
119
+
120
+ let url = url:: Url :: parse_with_params (
121
+ & format ! ( "https://github.com/{GITHUB_REPO_NAME}/issues/new" ) ,
122
+ params. iter ( ) ,
123
+ ) ?;
124
+
125
+ if is_remote ( ) || fig_util:: open_url_async ( url. as_str ( ) ) . await . is_err ( ) {
126
+ println ! ( "Issue Url: {}" , url. as_str( ) . underlined( ) ) ;
127
+ }
128
+
129
+ Ok ( url)
130
+ }
131
+ }
0 commit comments