Skip to content

Commit d7d5fa6

Browse files
vincio71Vincenzo Baldi
andauthored
fix(bitbucket): handle microsecond precision timestamps in PR extractor (#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 #8708 Co-authored-by: Vincenzo Baldi <vincenzobaldi@a-m-j-v-baldi.fritz.box>
1 parent 9ae723f commit d7d5fa6

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
@@ -145,6 +145,18 @@ func TestConvertStringToTime(t *testing.T) {
145145
output: time.Date(2023, 3, 1, 0, 0, 0, 0, time.UTC),
146146
err: nil,
147147
},
148+
{
149+
name: "Valid time string with milliseconds",
150+
input: "2025-09-15T08:53:36.337+00:00",
151+
output: time.Date(2025, 9, 15, 8, 53, 36, 337000000, time.UTC),
152+
err: nil,
153+
},
154+
{
155+
name: "Valid time string with microseconds (Bitbucket Cloud format)",
156+
input: "2025-09-15T08:53:36.337932+00:00",
157+
output: time.Date(2025, 9, 15, 8, 53, 36, 337932000, time.UTC),
158+
err: nil,
159+
},
148160
{
149161
name: "Invalid time string",
150162
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)