1
0
mirror of https://gitea.com/jolheiser/sip synced 2024-11-26 07:33:48 +01:00
sip/cmd/release.go
John Olheiser 894a641ef8 Refactor (#29)
Clean up docs

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Add generated docs

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Update go.sum

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Fix remote parsing

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Refactor and clean up

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: https://gitea.com/jolheiser/sip/pulls/29
2020-09-17 16:25:09 +00:00

85 lines
1.8 KiB
Go

package cmd
import (
"fmt"
"os"
"gitea.com/jolheiser/sip/csv"
"gitea.com/jolheiser/sip/markdown"
"gitea.com/jolheiser/sip/sdk"
"code.gitea.io/sdk/gitea"
"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,
&ReleaseAttach,
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "csv",
Usage: "Output results to a CSV file at `PATH`",
},
},
}
func doRelease(ctx *cli.Context) error {
client, err := getClient(false)
if err != nil {
return err
}
owner, repo, err := askOwnerRepo()
if err != nil {
return err
}
releases, err := sdk.GetReleases(client, owner, repo, gitea.ListReleasesOptions{})
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
}