use token auth for https remotes #275
|
@ -22,6 +22,7 @@ var CmdOrgs = cli.Command{
|
|||
Action: runOrganizations,
|
||||
Subcommands: []*cli.Command{
|
||||
&organizations.CmdOrganizationList,
|
||||
&organizations.CmdOrganizationDelete,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
44
cmd/organizations/delete.go
Normal file
44
cmd/organizations/delete.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package organizations
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// CmdOrganizationDelete represents a sub command of organizations to delete a given user organization
|
||||
var CmdOrganizationDelete = cli.Command{
|
||||
Name: "delete",
|
||||
Aliases: []string{"rm"},
|
||||
Usage: "Delete users Organizations",
|
||||
Description: "Delete users organizations",
|
||||
ArgsUsage: "<organization name>",
|
||||
Action: RunOrganizationDelete,
|
||||
}
|
||||
|
||||
// RunOrganizationDelete delete user organization
|
||||
func RunOrganizationDelete(ctx *cli.Context) error {
|
||||
//TODO: Reconsider the usage InitCommandLoginOnly related to #200
|
||||
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
|
||||
|
||||
client := login.Client()
|
||||
|
||||
if ctx.Args().Len() < 1 {
|
||||
log.Fatal("You have to specify the organization name you want to delete.")
|
||||
return nil
|
||||
}
|
||||
|
||||
response, err := client.DeleteOrg(ctx.Args().First())
|
||||
if response != nil && response.StatusCode == 404 {
|
||||
log.Fatal("The given organization does not exist.")
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
77
cmd/times.go
77
cmd/times.go
|
@ -5,18 +5,7 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/cmd/times"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
@ -34,72 +23,10 @@ var CmdTrackedTimes = cli.Command{
|
|||
×.CmdTrackedTimesAdd,
|
||||
×.CmdTrackedTimesDelete,
|
||||
×.CmdTrackedTimesReset,
|
||||
×.CmdTrackedTimesList,
|
||||
},
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "from",
|
||||
Aliases: []string{"f"},
|
||||
Usage: "Show only times tracked after this date",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "until",
|
||||
Aliases: []string{"u"},
|
||||
Usage: "Show only times tracked before this date",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "total",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "Print the total duration at the end",
|
||||
},
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runTrackedTimes(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
|
||||
if err := client.CheckServerVersionConstraint(">= 1.11"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var times []*gitea.TrackedTime
|
||||
var err error
|
||||
|
||||
user := ctx.Args().First()
|
||||
fmt.Println(ctx.Command.ArgsUsage)
|
||||
if user == "" {
|
||||
// get all tracked times on the repo
|
||||
times, _, err = client.GetRepoTrackedTimes(owner, repo)
|
||||
} else if strings.HasPrefix(user, "#") {
|
||||
// get all tracked times on the specified issue
|
||||
issue, err := utils.ArgToIndex(user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
times, _, err = client.ListTrackedTimes(owner, repo, issue, gitea.ListTrackedTimesOptions{})
|
||||
} else {
|
||||
// get all tracked times by the specified user
|
||||
times, _, err = client.GetUserTrackedTimes(owner, repo, user)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var from, until time.Time
|
||||
if ctx.String("from") != "" {
|
||||
from, err = dateparse.ParseLocal(ctx.String("from"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if ctx.String("until") != "" {
|
||||
until, err = dateparse.ParseLocal(ctx.String("until"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
print.TrackedTimesList(times, flags.GlobalOutputValue, from, until, ctx.Bool("total"))
|
||||
return nil
|
||||
return times.RunTimesList(ctx)
|
||||
}
|
||||
|
|
97
cmd/times/list.go
Normal file
97
cmd/times/list.go
Normal file
|
@ -0,0 +1,97 @@
|
|||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package times
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// CmdTrackedTimesList represents a sub command of times to list them
|
||||
var CmdTrackedTimesList = cli.Command{
|
||||
Name: "ls",
|
||||
Aliases: []string{"list"},
|
||||
Action: RunTimesList,
|
||||
Usage: "Operate on tracked times of a repository's issues & pulls",
|
||||
Description: `Operate on tracked times of a repository's issues & pulls.
|
||||
Depending on your permissions on the repository, only your own tracked
|
||||
times might be listed.`,
|
||||
ArgsUsage: "[username | #issue]",
|
||||
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "from",
|
||||
Aliases: []string{"f"},
|
||||
Usage: "Show only times tracked after this date",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "until",
|
||||
Aliases: []string{"u"},
|
||||
Usage: "Show only times tracked before this date",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "total",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "Print the total duration at the end",
|
||||
},
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
// RunTimesList list repositories
|
||||
func RunTimesList(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
|
||||
var times []*gitea.TrackedTime
|
||||
var err error
|
||||
|
||||
user := ctx.Args().First()
|
||||
fmt.Println(ctx.Command.ArgsUsage)
|
||||
if user == "" {
|
||||
// get all tracked times on the repo
|
||||
times, _, err = client.GetRepoTrackedTimes(owner, repo)
|
||||
} else if strings.HasPrefix(user, "#") {
|
||||
// get all tracked times on the specified issue
|
||||
issue, err := utils.ArgToIndex(user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
times, _, err = client.ListTrackedTimes(owner, repo, issue, gitea.ListTrackedTimesOptions{})
|
||||
} else {
|
||||
// get all tracked times by the specified user
|
||||
times, _, err = client.GetUserTrackedTimes(owner, repo, user)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var from, until time.Time
|
||||
if ctx.String("from") != "" {
|
||||
from, err = dateparse.ParseLocal(ctx.String("from"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if ctx.String("until") != "" {
|
||||
until, err = dateparse.ParseLocal(ctx.String("until"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
print.TrackedTimesList(times, flags.GlobalOutputValue, from, until, ctx.Bool("total"))
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user