add tea times command #54

Merged
lunny merged 20 commits from noerw/tea:50-cmd-times into master 2020-03-06 03:43:34 +00:00
3 changed files with 28 additions and 0 deletions
Showing only changes of commit 4340f117ac - Show all commits

View File

@ -23,6 +23,7 @@ import (
go_git "gopkg.in/src-d/go-git.v4"
"github.com/go-gitea/yaml"
"github.com/hashicorp/go-version"
)
// Login represents a login to a gitea server, you even could add multiple logins for one gitea server
@ -35,6 +36,28 @@ type Login struct {
Insecure bool `yaml:"insecure"`
}
// Checks the logins server against a version constraint such as ">= 1.11.0+dev"

Build is failing due to this comment, it should start with CheckServerVersionConstraint

Build is failing due to this comment, it should start with `CheckServerVersionConstraint`
func (l *Login) CheckServerVersionConstraint (constraint string) error {
c, err := version.NewConstraint(constraint)
if err != nil {
return err
}
serverVersionRaw, err := l.Client().ServerVersion()
if err != nil {
return err
}
serverVersion, err := version.NewVersion(serverVersionRaw)
if err != nil {
return err
}
if !c.Check(serverVersion) {
return fmt.Errorf("gitea server at %s does not satisfy version constraint %s", l.URL, constraint)
}
return nil
}
// Client returns a client to operate Gitea API
func (l *Login) Client() *gitea.Client {
client := gitea.NewClient(l.URL, l.Token)

View File

@ -49,6 +49,10 @@ var CmdTrackedTimes = cli.Command{
func runTrackedTimes(ctx *cli.Context) error {
login, owner, repo := initCommand()
if err := login.CheckServerVersionConstraint(">= 1.11"); err != nil {
return err
}
var times []*gitea.TrackedTime
var err error

1
go.mod
View File

@ -7,6 +7,7 @@ require (
github.com/araddon/dateparse v0.0.0-20190622164848-0fb0a474d195
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/go-gitea/yaml v0.0.0-20170812160011-eb3733d160e7
github.com/hashicorp/go-version v1.2.0
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/olekukonko/tablewriter v0.0.1
github.com/stretchr/testify v1.4.0