-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/devtools/cmd/labelhist: show label history
Add a CLI tool for displaying the the labels added to and removed from an issue. This will be useful to evaluate labels added by gaby. Example: > go run ./internal/devtools/cmd/labelhist 69000 69000: 2024-08-21T19:56:28Z cherrymui +NeedsInvestigation 2024-08-22T19:03:13Z dmitshur -NeedsInvestigation 2024-08-22T19:03:13Z dmitshur +NeedsFix 2024-08-22T19:03:30Z dmitshur +Testing For #64. Change-Id: Ide5f429df92bfebd7978a8dfbb46b93708a6ab3d Reviewed-on: https://go-review.googlesource.com/c/oscar/+/635876 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Tatiana Bradley <[email protected]>
- Loading branch information
Showing
2 changed files
with
109 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
/* | ||
Labelhist displays the events of a GitHub issue that affect its labels. | ||
Usage: | ||
labelhist issues... | ||
Each argument can be a single issue number or a range of numbers "from-to". | ||
*/ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"log/slog" | ||
"os" | ||
"strconv" | ||
"strings" | ||
|
||
"golang.org/x/oscar/internal/gcp/firestore" | ||
"golang.org/x/oscar/internal/github" | ||
) | ||
|
||
var project = flag.String("project", "golang/go", "GitHub project") | ||
|
||
func usage() { | ||
fmt.Fprintf(os.Stderr, "usage: labelhist issues...\n") | ||
flag.PrintDefaults() | ||
os.Exit(2) | ||
} | ||
|
||
func main() { | ||
log.SetFlags(0) | ||
log.SetPrefix("labelhist: ") | ||
flag.Usage = usage | ||
flag.Parse() | ||
if err := run(context.Background()); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func run(ctx context.Context) error { | ||
var ranges []Range | ||
for _, arg := range flag.Args() { | ||
r, err := parseIssueArg(arg) | ||
if err != nil { | ||
return err | ||
} | ||
ranges = append(ranges, r) | ||
} | ||
lg := slog.New(slog.NewTextHandler(os.Stderr, nil)) | ||
db, err := firestore.NewDB(ctx, lg, "oscar-go-1", "prod") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, r := range ranges { | ||
for ev := range github.Events(db, *project, r.min, r.max) { | ||
switch ev.API { | ||
case "/issues": | ||
fmt.Printf("%d:\n", ev.Issue) | ||
case "/issues/events": | ||
ie := ev.Typed.(*github.IssueEvent) | ||
if ie.Event == "labeled" || ie.Event == "unlabeled" { | ||
c := '+' | ||
if ie.Event == "unlabeled" { | ||
c = '-' | ||
} | ||
fmt.Printf(" %s %-10s %c%s\n", ie.CreatedAt, ie.Actor.Login, c, ie.Label.Name) | ||
} | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
type Range struct { | ||
min, max int64 | ||
} | ||
|
||
func parseIssueArg(s string) (Range, error) { | ||
sfrom, sto, found := strings.Cut(s, "-") | ||
from, err := strconv.ParseInt(sfrom, 10, 64) | ||
if err != nil { | ||
return Range{}, err | ||
} | ||
if !found { | ||
return Range{from, from}, nil | ||
} | ||
to, err := strconv.ParseInt(sto, 10, 64) | ||
if err != nil { | ||
return Range{}, err | ||
} | ||
return Range{from, to}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters