@@ -3,6 +3,7 @@ package bitbucket
33import (
44 "encoding/json"
55 "fmt"
6+ "net/url"
67)
78
89const (
@@ -41,26 +42,39 @@ func (c *Client) BuildStatusCreate(gitCommit string, payload BuildStatusCreatePa
4142 return nil
4243}
4344
44- type BuildStatusPage struct {
45- Size int `json:"size"`
46- Limit int `json:"limit"`
47- Islastpage bool `json:"isLastPage"`
48- BuildStatus []BuildStatus `json:"values"`
49- Start int `json:"start"`
50- }
5145type BuildStatus struct {
5246 State string `json:"state"`
5347 Key string `json:"key"`
5448 Name string `json:"name"`
5549 URL string `json:"url"`
5650 Description string `json:"description"`
57- Dateadded int64 `json:"dateAdded"`
51+ DateAdded int64 `json:"dateAdded"`
52+ }
53+
54+ type BuildStatusPage struct {
55+ Size int `json:"size"`
56+ Limit int `json:"limit"`
57+ IsLastPage bool `json:"isLastPage"`
58+ Values []BuildStatus `json:"values"`
59+ Start int `json:"start"`
60+ }
61+
62+ type BuildStatusListParams struct {
63+ // OrderBy determines how the results should be ordered.
64+ // Options are NEWEST, OLDEST, STATUS. Defaults to NEWEST if not provided.
65+ OrderBy string `json:"orderBy"`
5866}
5967
60- // BuildStatusGet gets the build statuses associated with a commit.
68+ // BuildStatusList gets the build statuses associated with a commit.
6169// https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-build-rest.html#idp8
62- func (c * Client ) BuildStatusGet (gitCommit string ) (* BuildStatus , error ) {
63- urlPath := fmt .Sprintf ("/rest/build-status/1.0/commits/%s" , gitCommit )
70+ func (c * Client ) BuildStatusList (gitCommit string , params BuildStatusListParams ) (* BuildStatusPage , error ) {
71+ q := url.Values {}
72+ q .Add ("orderBy" , params .OrderBy )
73+ urlPath := fmt .Sprintf (
74+ "/rest/build-status/1.0/commits/%s?%s" ,
75+ gitCommit ,
76+ q .Encode (),
77+ )
6478 statusCode , response , err := c .get (urlPath )
6579 if err != nil {
6680 return nil , fmt .Errorf ("request returned error: %w" , err )
@@ -75,7 +89,7 @@ func (c *Client) BuildStatusGet(gitCommit string) (*BuildStatus, error) {
7589 "could not unmarshal response: %w. status code: %d, body: %s" , err , statusCode , string (response ),
7690 )
7791 }
78- return & BuildStatusPage . BuildStatus [ 0 ] , nil // return the newest by default
92+ return & BuildStatusPage , nil
7993 case 401 :
8094 return nil , fmt .Errorf ("you are not permitted to get the build status of git commit %s" , gitCommit )
8195 default :
0 commit comments