Skip to content

Commit 3082212

Browse files
committed
internal/github: fix parsing of times
The format for parsing times differed from the one used by the GitHub API. The error was silently lost. Instead, a zero time was returned, meaning all issues and comments appeared to be before the commentfix.Fixer's cutoff and were not processed. This CL should fix the problem for subsequent issues, but we still have to go back and manually fix the ones that were missed somehow. Besides using the right format, and testing it against actual values from GH, also panic on error so gaby fails fast. It was only because Cherry was observant that this was noticed at all. For #54. Change-Id: Ib639dd68cae950ccba1af8e798ea6ae2c9ba5e19 Reviewed-on: https://go-review.googlesource.com/c/oscar/+/629797 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 5b878db commit 3082212

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

internal/github/data.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ func (x *IssueComment) CommentID() int64 {
297297
func (x *IssueComment) ID() string { return x.URL }
298298
func (x *IssueComment) Title_() string { return "" }
299299
func (x *IssueComment) Body_() string { return x.Body }
300-
func (x *IssueComment) CreatedAt_() time.Time { return parseTimeOrZero(x.CreatedAt) }
301-
func (x *IssueComment) UpdatedAt_() time.Time { return parseTimeOrZero(x.UpdatedAt) }
300+
func (x *IssueComment) CreatedAt_() time.Time { return mustParseTime(x.CreatedAt) }
301+
func (x *IssueComment) UpdatedAt_() time.Time { return mustParseTime(x.UpdatedAt) }
302302
func (x *IssueComment) Author() *model.Identity { panic("TODO: convert User to Identity") }
303303
func (x *IssueComment) CanEdit() bool { return true }
304304
func (x *IssueComment) CanHaveChildren() bool { return false }
@@ -346,8 +346,8 @@ func (i *Issue) DocID() string {
346346
func (x *Issue) ID() string { return x.URL }
347347
func (x *Issue) Title_() string { return x.Title }
348348
func (x *Issue) Body_() string { return x.Body }
349-
func (x *Issue) CreatedAt_() time.Time { return parseTimeOrZero(x.CreatedAt) }
350-
func (x *Issue) UpdatedAt_() time.Time { return parseTimeOrZero(x.UpdatedAt) }
349+
func (x *Issue) CreatedAt_() time.Time { return mustParseTime(x.CreatedAt) }
350+
func (x *Issue) UpdatedAt_() time.Time { return mustParseTime(x.UpdatedAt) }
351351
func (x *Issue) Author() *model.Identity { panic("TODO: convert User to Identity") }
352352
func (x *Issue) CanEdit() bool { return true }
353353
func (x *Issue) CanHaveChildren() bool { return false }
@@ -358,7 +358,13 @@ func (x *Issue) Updates() model.PostUpdates { return &IssueChanges{} }
358358

359359
var _ model.Post = (*Issue)(nil)
360360

361-
func parseTimeOrZero(s string) time.Time {
362-
t, _ := time.Parse("2006-01-02 15:04:05", s)
361+
func mustParseTime(s string) time.Time {
362+
if s == "" {
363+
return time.Time{}
364+
}
365+
t, err := time.Parse(time.RFC3339, s)
366+
if err != nil {
367+
storage.Panic("bad time: %v", err)
368+
}
363369
return t
364370
}

internal/github/data_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package github
6+
7+
import (
8+
"testing"
9+
"time"
10+
)
11+
12+
func TestMustParseTime(t *testing.T) {
13+
for _, tc := range []struct {
14+
in string
15+
want time.Time
16+
}{
17+
{"", time.Time{}},
18+
{"2015-08-05T01:55:29Z", time.Date(2015, 8, 5, 1, 55, 29, 0, time.UTC)},
19+
{"2024-11-11T18:41:58Z", time.Date(2024, 11, 11, 18, 41, 58, 0, time.UTC)},
20+
} {
21+
got := mustParseTime(tc.in)
22+
if !got.Equal(tc.want) {
23+
t.Errorf("%q: got %s, want %s", tc.in, got, tc.want)
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)