2020-02-14 21:46:02 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-02-16 06:51:14 +01:00
|
|
|
"code.gitea.io/sdk/gitea"
|
2020-02-17 21:50:02 +01:00
|
|
|
"gitea.com/jolheiser/sip/modules/sdk"
|
2020-02-14 21:46:02 +01:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-02-27 03:53:11 +01:00
|
|
|
"go.jolheiser.com/beaver"
|
|
|
|
"go.jolheiser.com/beaver/color"
|
2020-02-14 21:46:02 +01:00
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Repo = cli.Command{
|
|
|
|
Name: "repo",
|
|
|
|
Usage: "Commands for interacting with a Gitea repository",
|
|
|
|
Action: doRepo,
|
2020-03-06 05:21:56 +01:00
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
&RepoCreate,
|
|
|
|
},
|
2020-02-14 21:46:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func doRepo(ctx *cli.Context) error {
|
2020-04-17 05:59:12 +02:00
|
|
|
client, err := getClient(ctx, false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-14 21:46:02 +01:00
|
|
|
|
2020-02-16 06:51:14 +01:00
|
|
|
issues, err := sdk.GetIssues(client, ctx.String("owner"), ctx.String("repo"), gitea.ListIssueOption{State: "open"})
|
2020-02-14 21:46:02 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-16 06:51:14 +01:00
|
|
|
var issueCount, pullCount int
|
|
|
|
for _, issue := range issues {
|
|
|
|
if issue.PullRequest != nil {
|
|
|
|
pullCount++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
issueCount++
|
2020-02-14 21:46:02 +01:00
|
|
|
}
|
|
|
|
|
2020-02-18 06:27:52 +01:00
|
|
|
forks, err := sdk.GetForks(client, ctx.String("owner"), ctx.String("repo"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
yellow := color.New(color.FgYellow)
|
|
|
|
beaver.Infof("Repository: %s", yellow.Format(ctx.String("owner")+"/"+ctx.String("repo")))
|
|
|
|
beaver.Infof("URL: %s", yellow.Format(ctx.String("url")+"/"+ctx.String("owner")+"/"+ctx.String("repo")))
|
|
|
|
beaver.Info()
|
|
|
|
beaver.Infof("Open Issues: %s", yellow.Format(strconv.Itoa(issueCount)))
|
|
|
|
beaver.Infof("Open Pulls: %s", yellow.Format(strconv.Itoa(pullCount)))
|
2020-02-14 21:46:02 +01:00
|
|
|
beaver.Info()
|
2020-02-18 06:27:52 +01:00
|
|
|
beaver.Infof("Forks: %s", yellow.Format(strconv.Itoa(len(forks))))
|
2020-02-14 21:46:02 +01:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|