2022-06-22 01:27:24 +00:00
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
2020-01-24 16:30:16 +00:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
2020-02-02 22:45:12 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2022-06-22 01:27:24 +00:00
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
2020-02-02 22:45:12 +00:00
|
|
|
)
|
|
|
|
|
2020-01-24 16:30:16 +00:00
|
|
|
var (
|
2022-06-22 01:27:24 +00:00
|
|
|
// Version of changelog
|
|
|
|
Version = "development"
|
|
|
|
milestoneFlag string
|
|
|
|
tagFlag string
|
|
|
|
configPathFlag string
|
|
|
|
tokenFlag string
|
|
|
|
detailsFlag bool
|
|
|
|
afterFlag int64
|
|
|
|
issuesFlag bool
|
2020-01-24 16:30:16 +00:00
|
|
|
)
|
2020-02-02 22:45:12 +00:00
|
|
|
|
2022-06-22 01:27:24 +00:00
|
|
|
// New returns a new changelog App
|
|
|
|
func New() *cli.App {
|
|
|
|
app := &cli.App{
|
|
|
|
Name: "changelog",
|
|
|
|
Usage: "Changelog tools for Gitea",
|
|
|
|
Version: Version,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "milestone",
|
|
|
|
Aliases: []string{"m"},
|
|
|
|
Usage: "Targeted milestone",
|
|
|
|
Destination: &milestoneFlag,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "tag",
|
|
|
|
Aliases: []string{"T"},
|
|
|
|
Usage: "Git tag for milestone url, if not set milestone is used",
|
|
|
|
Destination: &tagFlag,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "config",
|
|
|
|
Aliases: []string{"c"},
|
|
|
|
Usage: "Specify a config file",
|
|
|
|
Value: getDefaultConfigFile(),
|
|
|
|
Destination: &configPathFlag,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "token",
|
|
|
|
Aliases: []string{"t"},
|
|
|
|
Usage: "Access token for private repositories/instances",
|
|
|
|
Destination: &tokenFlag,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "details",
|
|
|
|
Aliases: []string{"d"},
|
|
|
|
Usage: "Generate detail lists instead of long lists",
|
|
|
|
Destination: &detailsFlag,
|
|
|
|
},
|
|
|
|
&cli.Int64Flag{
|
|
|
|
Name: "after",
|
|
|
|
Aliases: []string{"a"},
|
|
|
|
Usage: "Only select PRs after a given index (continuing a previous changelog)",
|
|
|
|
Destination: &afterFlag,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "issues",
|
|
|
|
Aliases: []string{"i"},
|
|
|
|
Usage: "Generate changelog from issues (otherwise from pulls)",
|
|
|
|
Destination: &issuesFlag,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Commands: []*cli.Command{
|
|
|
|
Generate,
|
|
|
|
Contributors,
|
|
|
|
Init,
|
|
|
|
},
|
|
|
|
}
|
2022-09-16 09:31:37 +00:00
|
|
|
copyGlobalFlags(app)
|
2022-06-22 01:27:24 +00:00
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
2020-02-02 22:45:12 +00:00
|
|
|
func getDefaultConfigFile() string {
|
|
|
|
pwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
config := filepath.Join(pwd, ".changelog.yml")
|
|
|
|
info, err := os.Stat(config)
|
|
|
|
if err == nil && !info.IsDir() {
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
2022-09-16 09:31:37 +00:00
|
|
|
|
|
|
|
func copyGlobalFlags(app *cli.App) {
|
|
|
|
for _, command := range app.Commands {
|
|
|
|
originalFlagNames := make([]string, 0, len(command.Flags))
|
|
|
|
for _, flag := range command.Flags {
|
|
|
|
originalFlagNames = append(originalFlagNames, flag.Names()...)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, flag := range app.Flags {
|
|
|
|
found := false
|
|
|
|
flagNameLoop:
|
|
|
|
for _, name := range flag.Names() {
|
|
|
|
for _, originalName := range originalFlagNames {
|
|
|
|
if name == originalName {
|
|
|
|
found = true
|
|
|
|
break flagNameLoop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
command.Flags = append(command.Flags, flag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|