@@ -3,9 +3,11 @@ package cmd
33import (
44 "github.com/Graylog2/graylog-project-cli/changelog"
55 c "github.com/Graylog2/graylog-project-cli/config"
6+ "github.com/Graylog2/graylog-project-cli/git"
67 "github.com/Graylog2/graylog-project-cli/logger"
78 "github.com/Graylog2/graylog-project-cli/manifest"
89 p "github.com/Graylog2/graylog-project-cli/project"
10+ "github.com/hashicorp/go-version"
911 "github.com/samber/lo"
1012 "github.com/spf13/cobra"
1113 "os"
@@ -41,16 +43,28 @@ Example:
4143}
4244
4345var changelogReleaseCmd = & cobra.Command {
44- Hidden : true , // TODO: Show command once it's fully implemented
45- Use : "release" ,
46- Short : "Prepare changelogs for release." ,
46+ Use : "release" ,
47+ Short : "Prepare changelogs for release." ,
4748 Long : `Move unreleased changelog entries to a release.
4849
4950Example:
5051 graylog-project changelog release path/to/unreleased/changelog
5152` ,
52- Run : changelogReleaseCommand ,
53- ValidArgs : changelog .AvailableFormatters ,
53+ Run : changelogReleaseCommand ,
54+ }
55+
56+ var changelogReleasePathCmd = & cobra.Command {
57+ Use : "release:path" ,
58+ Short : "Prepare changelogs for release outside a project setup." ,
59+ Long : `Move unreleased changelog entries to a release folder.
60+
61+ To be used when you need to move changelogs of a single repository outside a project setup.
62+
63+ Example:
64+ graylog-project changelog release:path path/to/unreleased/changelog
65+ ` ,
66+ Args : cobra .ExactArgs (1 ),
67+ Run : changelogReleasePathCommand ,
5468}
5569
5670var changelogNewCmd = & cobra.Command {
@@ -90,6 +104,7 @@ var changelogEntryInteractive bool
90104func init () {
91105 changelogCmd .AddCommand (changelogRenderCmd )
92106 changelogCmd .AddCommand (changelogReleaseCmd )
107+ changelogCmd .AddCommand (changelogReleasePathCmd )
93108 changelogCmd .AddCommand (changelogNewCmd )
94109 changelogCmd .AddCommand (changelogLintCmd )
95110 RootCmd .AddCommand (changelogCmd )
@@ -106,6 +121,7 @@ func init() {
106121 changelogNewCmd .Flags ().BoolVarP (& changelogEntryInteractive , "interactive" , "i" , false , "Fill template values interactively" )
107122
108123 changelogReleaseCmd .Flags ().StringVarP (& changelogReleaseVersionPattern , "version-pattern" , "P" , changelog .SemverVersionPattern .String (), "version number pattern" )
124+ changelogReleasePathCmd .Flags ().StringVarP (& changelogReleaseVersionPattern , "version-pattern" , "P" , changelog .SemverVersionPattern .String (), "version number pattern" )
109125}
110126
111127func changelogRenderCommand (cmd * cobra.Command , args []string ) {
@@ -169,6 +185,7 @@ func changelogRenderCommand(cmd *cobra.Command, args []string) {
169185 logger .Fatal (err .Error ())
170186 }
171187}
188+
172189func changelogReleaseCommand (cmd * cobra.Command , args []string ) {
173190 // TODO: We might have to take the manifest as argument
174191 config := c .Get ()
@@ -185,6 +202,32 @@ func changelogReleaseCommand(cmd *cobra.Command, args []string) {
185202 }
186203}
187204
205+ func changelogReleasePathCommand (cmd * cobra.Command , args []string ) {
206+ v := args [0 ]
207+ semver , err := version .NewSemver (v )
208+ if err != nil {
209+ logger .Fatal ("Invalid version: %s: %s" , v , err )
210+ }
211+
212+ if semver .Prerelease () != "" {
213+ logger .Fatal ("Not allowing changelog rotation for pre-releases!" )
214+ }
215+
216+ versionPattern , err := regexp .Compile (changelogReleaseVersionPattern )
217+ if err != nil {
218+ logger .Fatal ("Invalid version pattern: %s" , changelogReleaseVersionPattern )
219+ }
220+
221+ path , err := git .ToplevelPath ()
222+ if err != nil {
223+ logger .Fatal ("%s" , err )
224+ }
225+
226+ if err := changelog .ReleaseInPath (path , v , versionPattern ); err != nil {
227+ logger .Fatal (err .Error ())
228+ }
229+ }
230+
188231func changelogNewCommand (cmd * cobra.Command , args []string ) {
189232 if err := changelog .NewEntry (args [0 ], changelogEntryEdit , changelogEntryMinimalTemplate , changelogEntryInteractive ); err != nil {
190233 logger .Error (err .Error ())
0 commit comments