Skip to content

Commit d1ca14b

Browse files
vincio71Vincenzo Baldi
authored andcommitted
fix(bitbucket): handle microsecond precision timestamps in PR extractor (apache#8828)
Bitbucket Cloud returns timestamps with 6-digit fractional seconds (e.g. 2025-09-15T08:53:36.337932+00:00). Changed BitbucketCreatedAt/ BitbucketUpdatedAt from time.Time to *common.Iso8601Time and added microsecond format to DateTimeFormats. Fixes apache#8708 Co-authored-by: Vincenzo Baldi <vincenzobaldi@a-m-j-v-baldi.fritz.box>
1 parent 0bcb68a commit d1ca14b

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

backend/core/models/common/iso8601time.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func init() {
5656
Matcher: regexp.MustCompile(`[+-][\d]{4}$`),
5757
Format: "2006-01-02T15:04:05-0700",
5858
},
59+
{
60+
Matcher: regexp.MustCompile(`[\d]{6}[+-][\d]{2}:[\d]{2}$`),
61+
Format: "2006-01-02T15:04:05.000000-07:00",
62+
},
5963
{
6064
Matcher: regexp.MustCompile(`[\d]{3}[+-][\d]{2}:[\d]{2}$`),
6165
Format: "2006-01-02T15:04:05.000-07:00",

backend/core/models/common/iso8601time_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ func TestConvertStringToTime(t *testing.T) {
144144
output: time.Date(2023, 3, 1, 0, 0, 0, 0, time.UTC),
145145
err: nil,
146146
},
147+
{
148+
name: "Valid time string with milliseconds",
149+
input: "2025-09-15T08:53:36.337+00:00",
150+
output: time.Date(2025, 9, 15, 8, 53, 36, 337000000, time.UTC),
151+
err: nil,
152+
},
153+
{
154+
name: "Valid time string with microseconds (Bitbucket Cloud format)",
155+
input: "2025-09-15T08:53:36.337932+00:00",
156+
output: time.Date(2025, 9, 15, 8, 53, 36, 337932000, time.UTC),
157+
err: nil,
158+
},
147159
{
148160
name: "Invalid time string",
149161
input: "invalid",

backend/plugins/bitbucket/tasks/pr_extractor.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package tasks
1919

2020
import (
2121
"encoding/json"
22-
"time"
2322

2423
"github.com/apache/incubator-devlake/core/errors"
2524
"github.com/apache/incubator-devlake/core/models/common"
@@ -57,8 +56,8 @@ type BitbucketApiPullRequest struct {
5756
} `json:"links"`
5857
ClosedBy *BitbucketAccountResponse `json:"closed_by"`
5958
Author *BitbucketAccountResponse `json:"author"`
60-
BitbucketCreatedAt time.Time `json:"created_on"`
61-
BitbucketUpdatedAt time.Time `json:"updated_on"`
59+
BitbucketCreatedAt *common.Iso8601Time `json:"created_on"`
60+
BitbucketUpdatedAt *common.Iso8601Time `json:"updated_on"`
6261
BaseRef *struct {
6362
Branch struct {
6463
Name string `json:"name"`
@@ -174,8 +173,8 @@ func convertBitbucketPullRequest(pull *BitbucketApiPullRequest, connId uint64, r
174173
Url: pull.Links.Html.Href,
175174
Type: pull.Type,
176175
CommentCount: pull.CommentCount,
177-
BitbucketCreatedAt: pull.BitbucketCreatedAt,
178-
BitbucketUpdatedAt: pull.BitbucketUpdatedAt,
176+
BitbucketCreatedAt: pull.BitbucketCreatedAt.ToTime(),
177+
BitbucketUpdatedAt: pull.BitbucketUpdatedAt.ToTime(),
179178
}
180179
if pull.BaseRef != nil {
181180
if pull.BaseRef.Repo != nil {

0 commit comments

Comments
 (0)