Skip to content

Commit 6e44b03

Browse files
committed
Add "changelog release:path" command
This command can be used when you want to release a changelog for a repository that is not part of a graylog-project setup.
1 parent 7eb37f4 commit 6e44b03

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

cmd/changelog.go

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package cmd
33
import (
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

4345
var 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
4950
Example:
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

5670
var changelogNewCmd = &cobra.Command{
@@ -90,6 +104,7 @@ var changelogEntryInteractive bool
90104
func 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

111127
func 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+
172189
func 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+
188231
func 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

Comments
 (0)