batches(gitlab) handle time with numeric timezone in webhook (#38250)

* handle time with numeric timezone

* update changelog

* add test case
This commit is contained in:
Bolaji Olajide 2022-07-06 13:06:31 +01:00 committed by GitHub
parent a020baefa8
commit 6a3ad4be2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -34,6 +34,7 @@ All notable changes to Sourcegraph are documented in this file.
- Code Insights: the commit indexer no longer errors when fetching commits from empty repositories and marks them as successfully indexed. [#39081](https://github.com/sourcegraph/sourcegraph/pull/38091)
- The file view does not jump to the first selected line anymore when selecting multiple lines and the first selected line was out of view. [#38175](https://github.com/sourcegraph/sourcegraph/pull/38175)
- Fixed an issue where multiple activations of the back button are required to navigate back to a previously selected line in a file [#38193](https://github.com/sourcegraph/sourcegraph/pull/38193)
- Support timestamps with numeric timezone format from Gitlab's Webhook payload [#38250](https://github.com/sourcegraph/sourcegraph/pull/38250)
### Removed

View File

@ -33,6 +33,14 @@ func (t *Time) UnmarshalJSON(data []byte) error {
dec, err := time.Parse("2006-01-02 15:04:05 MST", s)
if err == nil {
t.Time = dec
return nil
}
dec, err = time.Parse("2006-01-02 15:04:05 -0700", s)
if err == nil {
t.Time = dec
return nil
}
return err
}

View File

@ -8,6 +8,11 @@ import (
func TestTimeUnmarshal(t *testing.T) {
t.Run("valid", func(t *testing.T) {
loc, err := time.LoadLocation("Europe/Berlin")
if err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
input string
want time.Time
@ -24,6 +29,10 @@ func TestTimeUnmarshal(t *testing.T) {
input: "2020-06-24 00:05:18 UTC",
want: time.Date(2020, 6, 24, 0, 5, 18, 0, time.UTC),
},
{
input: "2022-07-05 20:52:49 +0200",
want: time.Date(2022, 7, 5, 20, 52, 49, 0, loc),
},
} {
t.Run(tc.input, func(t *testing.T) {
js, err := json.Marshal(tc.input)