summaryrefslogtreecommitdiffhomepage
path: root/tools/issue_reviver/github/github.go
diff options
context:
space:
mode:
authorIan Lewis <ianlewis@google.com>2020-08-14 16:21:29 -0700
committergVisor bot <gvisor-bot@google.com>2020-08-14 16:23:34 -0700
commit3f523b3bbcf5ef7f37bb247bd4c5727711c70ba9 (patch)
tree0908ef59b37ed7d25a08f4a1810a91739da84332 /tools/issue_reviver/github/github.go
parentaf433e159dbf07b084c0f05e65ec646c056033a7 (diff)
Handle URLs better in issue reviver
- Handle urls ending in / - Add some url parsing tests PiperOrigin-RevId: 326750183
Diffstat (limited to 'tools/issue_reviver/github/github.go')
-rw-r--r--tools/issue_reviver/github/github.go32
1 files changed, 22 insertions, 10 deletions
diff --git a/tools/issue_reviver/github/github.go b/tools/issue_reviver/github/github.go
index e07949c8f..8ffd7e606 100644
--- a/tools/issue_reviver/github/github.go
+++ b/tools/issue_reviver/github/github.go
@@ -85,18 +85,13 @@ func (b *Bugger) load(token string) error {
// Activate implements reviver.Bugger.
func (b *Bugger) Activate(todo *reviver.Todo) (bool, error) {
- const prefix = "gvisor.dev/issue/"
-
- // First check if I can handle the TODO.
- idStr := strings.TrimPrefix(todo.Issue, prefix)
- if len(todo.Issue) == len(idStr) {
- return false, nil
- }
-
- id, err := strconv.Atoi(idStr)
+ id, err := parseIssueNo(todo.Issue)
if err != nil {
return true, err
}
+ if id <= 0 {
+ return false, nil
+ }
// Check against active issues cache.
if _, ok := b.issues[id]; ok {
@@ -115,7 +110,7 @@ func (b *Bugger) Activate(todo *reviver.Todo) (bool, error) {
l.File, l.Line, b.owner, b.repo, l.File, l.Line, l.Comment)
}
fmt.Fprintf(&comment,
- "\n\nSearch [TODO](https://github.com/%s/%s/search?q=%%22%s%d%%22)", b.owner, b.repo, prefix, id)
+ "\n\nSearch [TODO](https://github.com/%s/%s/search?q=%%22%s%%22)", b.owner, b.repo, todo.Issue)
if b.dryRun {
fmt.Printf("[dry-run: skipping change to issue %d]\n%s\n=======================\n", id, comment.String())
@@ -140,6 +135,23 @@ func (b *Bugger) Activate(todo *reviver.Todo) (bool, error) {
return true, nil
}
+// parseIssueNo parses the issue number out of the issue url.
+func parseIssueNo(url string) (int, error) {
+ const prefix = "gvisor.dev/issue/"
+
+ // First check if I can handle the TODO.
+ idStr := strings.TrimPrefix(url, prefix)
+ if len(url) == len(idStr) {
+ return 0, nil
+ }
+
+ id, err := strconv.ParseInt(strings.TrimRight(idStr, "/"), 10, 64)
+ if err != nil {
+ return 0, err
+ }
+ return int(id), nil
+}
+
func processAllPages(fn func(github.ListOptions) (*github.Response, error)) error {
opts := github.ListOptions{PerPage: 1000}
for {