2020-04-17 05:59:12 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-05-07 03:09:31 +02:00
|
|
|
"os"
|
|
|
|
|
2020-09-17 18:25:09 +02:00
|
|
|
"gitea.com/jolheiser/sip/csv"
|
|
|
|
"gitea.com/jolheiser/sip/markdown"
|
|
|
|
"gitea.com/jolheiser/sip/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,
|
2020-09-16 20:07:30 +02:00
|
|
|
&ReleaseAttach,
|
2020-04-17 05:59:12 +02:00
|
|
|
},
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "csv",
|
2020-09-17 18:25:09 +02:00
|
|
|
Usage: "Output results to a CSV file at `PATH`",
|
2020-04-17 05:59:12 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func doRelease(ctx *cli.Context) error {
|
2020-09-17 18:25:09 +02:00
|
|
|
client, err := getClient(false)
|
2020-04-17 05:59:12 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-17 18:25:09 +02:00
|
|
|
owner, repo, err := askOwnerRepo()
|
2020-04-17 05:59:12 +02:00
|
|
|
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
|
|
|
|
}
|