@@ -26,6 +26,9 @@ type Options struct {
26
26
// The default should be to generate a GitHub style "CODEOWNERS" file.
27
27
ownersStyleFile bool
28
28
29
+ // where the output file will go
30
+ outputPath string
31
+
29
32
// the number of days to look back
30
33
previousDays int
31
34
@@ -74,6 +77,9 @@ pizza generate codeowners . --owners-style-file
74
77
75
78
# Specify a custom location for the .sauced.yaml file
76
79
pizza generate codeowners . --config /path/to/.sauced.yaml
80
+
81
+ # Specify a custom output location for the CODEOWNERS file
82
+ pizza generate codeowners . --output-path /path/to/directory
77
83
` ,
78
84
Args : func (_ * cobra.Command , args []string ) error {
79
85
if len (args ) != 1 {
@@ -113,6 +119,13 @@ pizza generate codeowners . --config /path/to/.sauced.yaml
113
119
}
114
120
115
121
opts .ownersStyleFile , _ = cmd .Flags ().GetBool ("owners-style-file" )
122
+ opts .outputPath , _ = cmd .Flags ().GetString ("output-path" )
123
+
124
+ // Default the outputPath to the base path if no flag value is given
125
+ if opts .outputPath == "" {
126
+ opts .outputPath = opts .path
127
+ }
128
+
116
129
opts .previousDays , _ = cmd .Flags ().GetInt ("range" )
117
130
opts .tty , _ = cmd .Flags ().GetBool ("tty-disable" )
118
131
@@ -139,6 +152,7 @@ pizza generate codeowners . --config /path/to/.sauced.yaml
139
152
140
153
cmd .PersistentFlags ().IntP ("range" , "r" , 90 , "The number of days to analyze commit history (default 90)" )
141
154
cmd .PersistentFlags ().Bool ("owners-style-file" , false , "Generate an agnostic OWNERS style file instead of CODEOWNERS." )
155
+ cmd .PersistentFlags ().StringP ("output-path" , "o" , "" , "Directory to create the output file." )
142
156
143
157
return cmd
144
158
}
@@ -176,21 +190,23 @@ func run(opts *Options, cmd *cobra.Command) error {
176
190
return fmt .Errorf ("error traversing git log: %w" , err )
177
191
}
178
192
179
- // Bootstrap codeowners
180
- var outputPath string
193
+ // Define which file to generate based on a flag
194
+ var fileType string
181
195
if opts .ownersStyleFile {
182
- outputPath = filepath . Join ( opts . path , "OWNERS" )
196
+ fileType = "OWNERS"
183
197
} else {
184
- outputPath = filepath . Join ( opts . path , "CODEOWNERS" )
198
+ fileType = "CODEOWNERS"
185
199
}
186
200
187
- opts .logger .V (logging .LogDebug ).Style (0 , colors .FgBlue ).Infof ("Processing codeowners file at: %s\n " , outputPath )
188
- err = generateOutputFile (codeowners , outputPath , opts , cmd )
201
+ opts .logger .V (logging .LogDebug ).Style (0 , colors .FgBlue ).Infof ("Processing codeowners file at: %s\n " , opts .outputPath )
202
+
203
+ err = generateOutputFile (codeowners , filepath .Join (opts .outputPath , fileType ), opts , cmd )
189
204
if err != nil {
190
205
_ = opts .telemetry .CaptureFailedCodeownersGenerate ()
191
206
return fmt .Errorf ("error generating github style codeowners file: %w" , err )
192
207
}
193
- opts .logger .V (logging .LogInfo ).Style (0 , colors .FgGreen ).Infof ("Finished generating file: %s\n " , outputPath )
208
+
209
+ opts .logger .V (logging .LogInfo ).Style (0 , colors .FgGreen ).Infof ("Finished generating file: %s\n " , filepath .Join (opts .outputPath , fileType ))
194
210
_ = opts .telemetry .CaptureCodeownersGenerate ()
195
211
196
212
opts .logger .V (logging .LogInfo ).Style (0 , colors .FgCyan ).Infof ("\n Create an OpenSauced Contributor Insight to get metrics and insights on these codeowners:\n " )
0 commit comments