@@ -340,7 +340,7 @@ func TestBitbucketServer_GetLatestCommit(t *testing.T) {
340
340
AuthorName : "charlie" ,
341
341
CommitterName : "mark" ,
342
342
Url : expectedUrl ,
343
- Timestamp : 1548720847610 ,
343
+ Timestamp : 1548720847 ,
344
344
Message : "More work on feature 1" ,
345
345
ParentHashes : []string {"abcdef0123abcdef4567abcdef8987abcdef6543" , "qwerty0123abcdef4567abcdef8987abcdef6543" },
346
346
@@ -371,7 +371,7 @@ func TestBitbucketServer_GetCommits(t *testing.T) {
371
371
AuthorName : "charlie" ,
372
372
CommitterName : "mark" ,
373
373
Url : expectedUrl ,
374
- Timestamp : 1548720847610 ,
374
+ Timestamp : 1548720847 ,
375
375
Message : "More work on feature 1" ,
376
376
ParentHashes : []string {"abcdef0123abcdef4567abcdef8987abcdef6543" , "qwerty0123abcdef4567abcdef8987abcdef6543" },
377
377
@@ -381,7 +381,7 @@ func TestBitbucketServer_GetCommits(t *testing.T) {
381
381
AuthorName : "marly" ,
382
382
CommitterName : "marly" ,
383
383
Url : expectedUrl ,
384
- Timestamp : 1548720847610 ,
384
+ Timestamp : 1548720847 ,
385
385
Message : "More work on feature 2" ,
386
386
ParentHashes : []string {"abcdef0123abcdef4567abcdef8987abcdef6543" , "qwerty0123abcdef4567abcdef8987abcdef6543" },
387
387
@@ -391,6 +391,54 @@ func TestBitbucketServer_GetCommits(t *testing.T) {
391
391
assert .Error (t , err )
392
392
}
393
393
394
+ func TestBitbucketServer_GetCommitsWithQueryOptions (t * testing.T ) {
395
+ ctx := context .Background ()
396
+ response , err := os .ReadFile (filepath .Join ("testdata" , "bitbucketserver" , "commit_list_response.json" ))
397
+ assert .NoError (t , err )
398
+ client , serverUrl , cleanUp := createServerWithUrlAndClientReturningStatus (t , vcsutils .BitbucketServer , false ,
399
+ response ,
400
+ fmt .Sprintf ("/rest/api/1.0/projects/%s/repos/%s/commits?limit=30&limit=30&start=0" , owner , repo1 ),
401
+ http .StatusOK , createBitbucketServerHandler )
402
+ defer cleanUp ()
403
+
404
+ options := GitCommitsQueryOptions {
405
+ Since : time .Date (2017 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
406
+ ListOptions : ListOptions {
407
+ Page : 1 ,
408
+ PerPage : 30 ,
409
+ },
410
+ }
411
+
412
+ result , err := client .GetCommitsWithQueryOptions (ctx , owner , repo1 , options )
413
+
414
+ assert .NoError (t , err )
415
+ expectedUrl := fmt .Sprintf ("%s/projects/jfrog/repos/repo-1" +
416
+ "/commits/def0123abcdef4567abcdef8987abcdef6543abc" , serverUrl )
417
+ assert .Equal (t , CommitInfo {
418
+ Hash : "def0123abcdef4567abcdef8987abcdef6543abc" ,
419
+ AuthorName : "charlie" ,
420
+ CommitterName : "mark" ,
421
+ Url : expectedUrl ,
422
+ Timestamp : 1548720847 ,
423
+ Message : "More work on feature 1" ,
424
+ ParentHashes : []string {"abcdef0123abcdef4567abcdef8987abcdef6543" , "qwerty0123abcdef4567abcdef8987abcdef6543" },
425
+
426
+ }, result [0 ])
427
+ assert .Equal (t , CommitInfo {
428
+ Hash : "def0123abcdef4567abcdef8987abcdef6543abc" ,
429
+ AuthorName : "marly" ,
430
+ CommitterName : "marly" ,
431
+ Url : expectedUrl ,
432
+ Timestamp : 1548720847 ,
433
+ Message : "More work on feature 2" ,
434
+ ParentHashes : []string {"abcdef0123abcdef4567abcdef8987abcdef6543" , "qwerty0123abcdef4567abcdef8987abcdef6543" },
435
+
436
+ }, result [1 ])
437
+
438
+ _ , err = createBadBitbucketServerClient (t ).GetCommitsWithQueryOptions (ctx , owner , repo1 , options )
439
+ assert .Error (t , err )
440
+ }
441
+
394
442
func TestBitbucketServer_GetLatestCommitNotFound (t * testing.T ) {
395
443
ctx := context .Background ()
396
444
response := []byte (`{
@@ -603,7 +651,7 @@ func TestBitbucketServer_GetCommitBySha(t *testing.T) {
603
651
AuthorName : "charlie" ,
604
652
CommitterName : "mark" ,
605
653
Url : expectedUrl ,
606
- Timestamp : 1636089306104 ,
654
+ Timestamp : 1636089306 ,
607
655
Message : "WIP on feature 1" ,
608
656
ParentHashes : []string {"bbcdef0123abcdef4567abcdef8987abcdef6543" },
609
657
@@ -882,3 +930,78 @@ func createBadBitbucketServerClient(t *testing.T) VcsClient {
882
930
assert .NoError (t , err )
883
931
return client
884
932
}
933
+
934
+ func TestGetCommitsInDateRate (t * testing.T ) {
935
+ tests := []struct {
936
+ name string
937
+ commits []CommitInfo
938
+ options GitCommitsQueryOptions
939
+ expected []CommitInfo
940
+ }{
941
+ {
942
+ name : "All commits within range" ,
943
+ commits : []CommitInfo {
944
+ {Timestamp : 1717396600 }, // Mon, 03 Jun 2024 09:56:40 GMT (Within range)
945
+ {Timestamp : 1717396500 }, // Mon, 03 Jun 2024 09:55:00 GMT (Within range)
946
+ {Timestamp : 1717396400 }, // Mon, 03 Jun 2024 09:53:20 GMT (Within range)
947
+ },
948
+ options : GitCommitsQueryOptions {
949
+ Since : time .Unix (1717396300 , 0 ), // Mon, 03 Jun 2024 09:51:40 GMT (Set since timestamp in seconds)
950
+ },
951
+ expected : []CommitInfo {
952
+ {Timestamp : 1717396600 },
953
+ {Timestamp : 1717396500 },
954
+ {Timestamp : 1717396400 },
955
+ },
956
+ },
957
+ {
958
+ name : "All commits within range or equal" ,
959
+ commits : []CommitInfo {
960
+ {Timestamp : 1717396600 }, // Mon, 03 Jun 2024 09:56:40 GMT (Within range)
961
+ {Timestamp : 1717396500 }, // Mon, 03 Jun 2024 09:55:00 GMT (Within range)
962
+ {Timestamp : 1717396400 }, // Mon, 03 Jun 2024 09:53:20 GMT (Within range)
963
+ },
964
+ options : GitCommitsQueryOptions {
965
+ Since : time .Unix (1717396400 , 0 ), // Mon, 03 Jun 2024 09:53:20 GMT (Set since timestamp in seconds)
966
+ },
967
+ expected : []CommitInfo {
968
+ {Timestamp : 1717396600 },
969
+ {Timestamp : 1717396500 },
970
+ {Timestamp : 1717396400 },
971
+ },
972
+ },
973
+ {
974
+ name : "No commits within range" ,
975
+ commits : []CommitInfo {
976
+ {Timestamp : 1717396500 }, // Mon, 03 Jun 2024 09:55:00 GMT (Older than range)
977
+ {Timestamp : 1717396400 }, // Mon, 03 Jun 2024 09:53:20 GMT (Older than range)
978
+ },
979
+ options : GitCommitsQueryOptions {
980
+ Since : time .Unix (1717396600 , 0 ), // Mon, 03 Jun 2024 09:56:40 GMT (Set since timestamp in seconds)
981
+ },
982
+ expected : []CommitInfo {},
983
+ },
984
+ {
985
+ name : "Partial commits within range" ,
986
+ commits : []CommitInfo {
987
+ {Timestamp : 1717396600 }, // Mon, 03 Jun 2024 09:56:40 GMT (Within range)
988
+ {Timestamp : 1717396500 }, // Mon, 03 Jun 2024 09:55:00 GMT (Within range)
989
+ {Timestamp : 1717396400 }, // Mon, 03 Jun 2024 09:53:20 GMT (Older than range)
990
+ },
991
+ options : GitCommitsQueryOptions {
992
+ Since : time .Unix (1717396500 , 0 ), // Mon, 03 Jun 2024 09:55:00 GMT (Set since timestamp in seconds)
993
+ },
994
+ expected : []CommitInfo {
995
+ {Timestamp : 1717396600 },
996
+ {Timestamp : 1717396500 },
997
+ },
998
+ },
999
+ }
1000
+
1001
+ for _ , tt := range tests {
1002
+ t .Run (tt .name , func (t * testing.T ) {
1003
+ result := getCommitsInDateRate (tt .commits , tt .options )
1004
+ assert .ElementsMatch (t , result , tt .expected )
1005
+ })
1006
+ }
1007
+ }
0 commit comments