tools: Simplify gerrit-stats and snippets

Automatically try to infer 'user' from git config.
Default to 'dawn' repo over tint.

Usage:

tools/run snippets
tools/run gerrit-stats

Change-Id: I8c4617101447ac635e753b0a2a0b655ba6c64b54
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86300
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Ben Clayton
2022-04-11 10:49:50 +00:00
committed by Dawn LUCI CQ
parent db911a24de
commit 4127abfd41
3 changed files with 64 additions and 3 deletions

View File

@@ -306,6 +306,33 @@ func (r Repository) Log(opt *LogOptions) ([]CommitInfo, error) {
return parseLog(out)
}
// Optional settings for Repository.ConfigOptions
type ConfigOptions struct {
// Timeout for the operation
Timeout time.Duration
}
// Config returns the git configuration values for the repo
func (r Repository) Config(opt *ConfigOptions) (map[string]string, error) {
if opt == nil {
opt = &ConfigOptions{}
}
text, err := r.run(opt.Timeout, "config", "-l")
if err != nil {
return nil, err
}
lines := strings.Split(text, "\n")
out := make(map[string]string, len(lines))
for _, line := range lines {
idx := strings.Index(line, "=")
if idx > 0 {
key, value := line[:idx], line[idx+1:]
out[key] = value
}
}
return out, nil
}
func (r Repository) run(timeout time.Duration, args ...string) (string, error) {
return r.Git.run(r.Path, timeout, args...)
}