4040 "doesn't exist please create it and run this command again :) Happy change-logging!"
4141)
4242
43-
4443CONFIG = load_toml_config ()
4544SECTIONS = [_type for _type , _ in CONFIG .get ("types" ).items ()]
4645
4746
4847def save_news_fragment (ctx : click .Context , gh_pr : int , nonce : str , news_entry : str , news_type : str ) -> None :
4948 """Save received changelog data to a news file."""
5049 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" )
5551 if not path .parents [1 ].exists ():
5652 err (NO_NEWS_PATH_ERROR , fg = "blue" )
5753 ctx .exit (1 )
@@ -158,11 +154,11 @@ def cli_add_news(ctx: click.Context, message: str, editor: str, type: str, pr_nu
158154 )
159155
160156 if not content :
161- message_notes = "# ERROR: No content found previously"
157+ message_notes = [ "# ERROR: No content found previously" ]
162158 continue
163159
164160 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 ("#" )
166162 )
167163
168164 if message is None :
@@ -175,8 +171,14 @@ def cli_add_news(ctx: click.Context, message: str, editor: str, type: str, pr_nu
175171
176172
177173@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." )
178180@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 :
180182 """Build a combined news file 📜 from news fragments."""
181183 filenames = glob_fragments ("next" , SECTIONS )
182184 _file_metadata = {}
@@ -222,16 +224,19 @@ def cli_build_news(ctx: click.Context) -> None:
222224 )
223225 news_path = Path (Path .cwd (), f"news/{ version } .md" )
224226
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 )
227229
228230 out (f"All done! ✨ 🍰 ✨ Created { name } -v{ version } news at { news_path } " )
229231
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 ))
233234
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!" )
235240
236241
237242if __name__ == "__main__" :
0 commit comments