mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-31 01:05:26 +01:00 
			
		
		
		
	Add times ls (#272)
				
					
				
			add `times ls` Fix #242 Move `list` code into times/list.go to make it more in line with the rest of the code. add `times ls` reformatted code. Signed-off-by: Karl Heinz Marbaise <kama@soebes.de> Removed version check as suggested through the review. Co-authored-by: Karl Heinz Marbaise <kama@soebes.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/272 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: khmarbaise <khmarbaise@noreply.gitea.io> Co-Committed-By: khmarbaise <khmarbaise@noreply.gitea.io>
This commit is contained in:
		
							
								
								
									
										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) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 khmarbaise
					khmarbaise