40
40
"doesn't exist please create it and run this command again :) Happy change-logging!"
41
41
)
42
42
43
-
44
43
CONFIG = load_toml_config ()
45
44
SECTIONS = [_type for _type , _ in CONFIG .get ("types" ).items ()]
46
45
47
46
48
47
def save_news_fragment (ctx : click .Context , gh_pr : int , nonce : str , news_entry : str , news_type : str ) -> None :
49
48
"""Save received changelog data to a news file."""
50
49
date = datetime .now (timezone .utc ).strftime ("%Y-%m-%d" )
51
- path = Path (
52
- Path .cwd (),
53
- f"news/next/{ news_type } /{ date } .pr-{ str (gh_pr )} .{ nonce } .md" ,
54
- )
50
+ path = Path (Path .cwd (), f"news/next/{ news_type } /{ date } .pr-{ gh_pr } .{ nonce } .md" )
55
51
if not path .parents [1 ].exists ():
56
52
err (NO_NEWS_PATH_ERROR , fg = "blue" )
57
53
ctx .exit (1 )
@@ -158,11 +154,11 @@ def cli_add_news(ctx: click.Context, message: str, editor: str, type: str, pr_nu
158
154
)
159
155
160
156
if not content :
161
- message_notes = "# ERROR: No content found previously"
157
+ message_notes = [ "# ERROR: No content found previously" ]
162
158
continue
163
159
164
160
message = "\n " .join (
165
- [ line .rstrip () for line in content .split ("\n " ) if not line .lstrip ().startswith ("#" )]
161
+ line .rstrip () for line in content .split ("\n " ) if not line .lstrip ().startswith ("#" )
166
162
)
167
163
168
164
if message is None :
@@ -175,8 +171,14 @@ def cli_add_news(ctx: click.Context, message: str, editor: str, type: str, pr_nu
175
171
176
172
177
173
@cli_main .command ("build" )
174
+ @click .option (
175
+ "--edit/--no-edit" ,
176
+ default = None ,
177
+ help = "Open the changelog file in your text editor." ,
178
+ )
179
+ @click .option ("--keep" , is_flag = True , help = "Keep the fragment files that are collected." )
178
180
@click .pass_context
179
- def cli_build_news (ctx : click .Context ) -> None :
181
+ def cli_build_news (ctx : click .Context , edit : Optional [ bool ], keep : bool ) -> None :
180
182
"""Build a combined news file 📜 from news fragments."""
181
183
filenames = glob_fragments ("next" , SECTIONS )
182
184
_file_metadata = {}
@@ -222,16 +224,19 @@ def cli_build_news(ctx: click.Context) -> None:
222
224
)
223
225
news_path = Path (Path .cwd (), f"news/{ version } .md" )
224
226
225
- with open (news_path , mode = "w" ) as filename :
226
- filename .write (version_news )
227
+ with open (news_path , mode = "w" ) as file :
228
+ file .write (version_news )
227
229
228
230
out (f"All done! ✨ 🍰 ✨ Created { name } -v{ version } news at { news_path } " )
229
231
230
- files = Path (Path .cwd (), "scripts/news/next" )
231
- for news_fragment in files .glob ("*.md" ):
232
- os .remove (news_fragment )
232
+ if edit :
233
+ click .edit (filename = str (news_path ))
233
234
234
- out ("🍰 Cleared existing `scripts/news/next` news fragments!" )
235
+ if not keep :
236
+ files = Path (Path .cwd (), "scripts/news/next" )
237
+ for news_fragment in files .glob ("*.md" ):
238
+ os .remove (news_fragment )
239
+ out ("🍰 Cleared existing `scripts/news/next` news fragments!" )
235
240
236
241
237
242
if __name__ == "__main__" :
0 commit comments