2020-04-17 05:59:12 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-05-07 03:09:31 +02:00
|
|
|
"os"
|
|
|
|
|
2020-04-17 05:59:12 +02:00
|
|
|
"gitea.com/jolheiser/sip/modules/csv"
|
|
|
|
"gitea.com/jolheiser/sip/modules/markdown"
|
2020-07-15 20:15:46 +02:00
|
|
|
"gitea.com/jolheiser/sip/modules/sdk"
|
2020-05-07 03:09:31 +02:00
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
2020-04-17 05:59:12 +02:00
|
|
|
"github.com/AlecAivazis/survey/v2"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"go.jolheiser.com/beaver/color"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Release = cli.Command{
|
|
|
|
Name: "releases",
|
|
|
|
Aliases: []string{"release"},
|
|
|
|
Usage: "Commands for interacting with releases",
|
|
|
|
Action: doRelease,
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
&ReleaseCreate,
|
|
|
|
},
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "csv",
|
|
|
|
Usage: "Output results to a CSV file",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func doRelease(ctx *cli.Context) error {
|
|
|
|
client, err := getClient(ctx, false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
owner, repo, err := askOwnerRepo(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-15 20:15:46 +02:00
|
|
|
releases, err := sdk.GetReleases(client, owner, repo, gitea.ListReleasesOptions{})
|
2020-04-17 05:59:12 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.String("csv") != "" {
|
|
|
|
fi, err := os.Create(ctx.String("csv"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := fi.WriteString(csv.Releases(releases)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(color.FgCyan.Format("Releases were exported to"), color.Info.Format(ctx.String("csv")))
|
|
|
|
return fi.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
releaseMap := make(map[string]*gitea.Release)
|
|
|
|
releaseList := make([]string, len(releases))
|
|
|
|
for idx, release := range releases {
|
|
|
|
key := fmt.Sprintf("%s (%s)", release.Title, release.TagName)
|
|
|
|
releaseMap[key] = release
|
|
|
|
releaseList[idx] = key
|
|
|
|
}
|
|
|
|
|
|
|
|
sel := &survey.Select{Options: releaseList, Message: "Releases"}
|
|
|
|
var selection string
|
|
|
|
if err := survey.AskOne(sel, &selection); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
note, err := markdown.Render(releaseMap[selection].Note)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(note)
|
|
|
|
fmt.Printf("Release Date: %s\n", releaseMap[selection].PublishedAt.Format(csv.TimeFormat))
|
|
|
|
return nil
|
|
|
|
}
|