log

package
v0.0.0-...-2b89969 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2021 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Command = &cli.Command{
		Name:      "log",
		Usage:     "Output updates about a changeset",
		UsageText: "log [options] <changeID>",
		Flags:     flagset.Extract(config),
		Action: func(ctx *cli.Context) error {
			gerritAPI := common.GerritAPI(ctx.Context)

			changeID := ctx.Args().Get(0)

			accountInfo := make(map[int64]gerrit.AccountInfo)
			getAccountInfo := func(accountID int64) (*gerrit.AccountInfo, error) {
				info, ok := accountInfo[accountID]
				if !ok {
					info, err := gerritAPI.Client.GetAccountInfo(ctx.Context, strconv.FormatInt(accountID, 10))
					if err != nil {
						return nil, err
					}
					accountInfo[accountID] = info
				}

				return &info, nil
			}

			changeInfo, err := gerritAPI.Client.GetChangeDetail(ctx.Context, changeID)
			if err != nil {
				return err
			}

			sort.Slice(changeInfo.Messages, func(i, j int) bool {
				a := changeInfo.Messages[i].Time.Time()
				b := changeInfo.Messages[j].Time.Time()
				return b.Before(a)
			})

			for _, message := range changeInfo.Messages {
				message.Author, _ = getAccountInfo(message.Author.NumericID)
			}

			template, err := template.New("log").
				Funcs(map[string]interface{}{
					"baseURL": func() string {
						return gerritAPI.BaseURL
					},
					"getAccountInfo": getAccountInfo,
					"formatTimeStamp": func(t gerrit.TimeStamp) string {
						return t.Time().Local().Format(time.RFC1123Z)
					},
				}).
				Parse(log)

			if err != nil {
				return err
			}

			return template.Execute(ctx.App.Writer, changeInfo)
		},
		HideHelpCommand: true,
	}
)

Functions

This section is empty.

Types

type Config

type Config struct {
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL