From f3fe2a0532843d47b3d8d01249c20723620da84a Mon Sep 17 00:00:00 2001 From: Nithin Philips Date: Wed, 8 Jan 2025 05:00:21 +0000 Subject: [PATCH] release create: Add --note-file flag to read release notes from a file (#678) Add a `--note-file` argument to pass a file with multi-line release notes instead of trying to pass as an argument using `--note`. Co-authored-by: Lunny Xiao Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/tea/pulls/678 Reviewed-by: Lunny Xiao Co-authored-by: Nithin Philips Co-committed-by: Nithin Philips --- cmd/releases/create.go | 18 ++++++++++++++++-- docs/CLI.md | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/releases/create.go b/cmd/releases/create.go index 9ba9ebc..cb0f777 100644 --- a/cmd/releases/create.go +++ b/cmd/releases/create.go @@ -43,6 +43,11 @@ var CmdReleaseCreate = cli.Command{ Aliases: []string{"n"}, Usage: "Release notes", }, + &cli.StringFlag{ + Name: "note-file", + Aliases: []string{"f"}, + Usage: "Release notes file name. If set, --note is ignored.", + }, &cli.BoolFlag{ Name: "draft", Aliases: []string{"d"}, @@ -73,15 +78,24 @@ func runReleaseCreate(cmd *cli.Context) error { tag = cmd.Args().First() } + notestring := ctx.String("note") + notefile := ctx.String("note-file") + if notefile != "" { + notebytes, err := os.ReadFile(notefile) + if err != nil { + return fmt.Errorf("unable to read the note file") + } + notestring = string(notebytes) + } + release, resp, err := ctx.Login.Client().CreateRelease(ctx.Owner, ctx.Repo, gitea.CreateReleaseOption{ TagName: tag, Target: ctx.String("target"), Title: ctx.String("title"), - Note: ctx.String("note"), + Note: notestring, IsDraft: ctx.Bool("draft"), IsPrerelease: ctx.Bool("prerelease"), }) - if err != nil { if resp != nil && resp.StatusCode == http.StatusConflict { return fmt.Errorf("There already is a release for this tag") diff --git a/docs/CLI.md b/docs/CLI.md index c0c4251..e26b10c 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -737,6 +737,8 @@ Create a release **--note, -n**="": Release notes +**--note-file, -f**="": Release notes file name. If set, --note is ignored. + **--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json) **--prerelease, -p**: Is a pre-release