2020-02-14 21:46:02 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-05-07 03:09:31 +02:00
|
|
|
"strconv"
|
|
|
|
|
2020-09-21 21:21:07 +02:00
|
|
|
"go.jolheiser.com/sip/flag"
|
|
|
|
"go.jolheiser.com/sip/sdk"
|
2020-05-07 03:09:31 +02:00
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
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
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-09-17 18:25:09 +02:00
|
|
|
func doRepo(_ *cli.Context) error {
|
|
|
|
client, err := getClient(false)
|
2020-04-17 05:59:12 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-14 21:46:02 +01:00
|
|
|
|
2020-09-17 18:25:09 +02:00
|
|
|
repo, _, err := client.GetRepo(flag.Owner, flag.Repo)
|
2020-09-16 05:54:48 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-17 18:25:09 +02:00
|
|
|
issues, err := sdk.GetIssues(client, flag.Owner, flag.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
|
|
|
yellow := color.New(color.FgYellow)
|
2020-09-16 05:54:48 +02:00
|
|
|
beaver.Infof("Repository: %s", yellow.Format(repo.FullName))
|
|
|
|
beaver.Infof("URL: %s", yellow.Format(repo.HTMLURL))
|
2020-02-18 06:27:52 +01:00
|
|
|
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-09-16 05:54:48 +02:00
|
|
|
beaver.Infof("Forks: %s", yellow.Format(strconv.Itoa(repo.Forks)))
|
|
|
|
beaver.Infof("Stars: %s", yellow.Format(strconv.Itoa(repo.Stars)))
|
|
|
|
beaver.Infof("Watchers: %s", yellow.Format(strconv.Itoa(repo.Watchers)))
|
2020-02-14 21:46:02 +01:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|