@@ -14,41 +14,42 @@ type ReleaseList struct {
1414
1515type Release struct {
1616 Id int64 `json:"id"`
17- Name string
17+ Name string `json:"name"`
1818
1919 Definition struct {
20- Id int64
21- Name string
20+ Id int64 `json:"id"`
21+ Name string `json:"name"`
2222 Links Links `json:"_links"`
2323 } `json:"releaseDefinition"`
2424
2525 Project Project `json:"projectReference"`
2626
27- Queue AgentPoolQueue
27+ Queue AgentPoolQueue `json:"queue"`
2828
29- Reason string
30- Result bool
31- Status string
32- QueueTime time.Time
33- QueuePosition string
34- StartTime time.Time
35- FinishTime time.Time
36- Uri string
37- Url string
29+ Reason string `json:"reason"`
30+ Result bool `json:"result"`
31+ Status string `json:"status"`
32+ CreatedOn time.Time `json:"createdOn"`
33+ QueueTime time.Time `json:"queueTime"`
34+ QueuePosition string `json:"queuePosition"`
35+ StartTime time.Time `json:"startTime"`
36+ FinishTime time.Time `json:"finishTime"`
37+ Uri string `json:"uri"`
38+ Url string `json:"url"`
3839
39- Artifacts []ReleaseArtifact
40- Environments []ReleaseEnvironment
40+ Artifacts []ReleaseArtifact `json:"artifacts"`
41+ Environments []ReleaseEnvironment `json:"environments"`
4142
42- RequestedBy IdentifyRef
43- RequestedFor IdentifyRef
43+ RequestedBy IdentifyRef `json:"requestedBy"`
44+ RequestedFor IdentifyRef `json:"requestedFor"`
4445
4546 Links Links `json:"_links"`
4647}
4748
4849type ReleaseArtifact struct {
49- SourceId string
50- Type string
51- Alias string
50+ SourceId string `json:"sourceId"`
51+ Type string `json:"type"`
52+ Alias string `json:"alias"`
5253
5354 DefinitionReference struct {
5455 Definition struct {
@@ -75,29 +76,29 @@ type ReleaseArtifact struct {
7576 Id string
7677 Name string
7778 }
78- }
79+ } `json:"definitionReference"`
7980}
8081
8182type ReleaseEnvironment struct {
82- Id int64
83- ReleaseId int64
84- DefinitionEnvironmentId int64
85- Name string
86- Status string
87- Rank int64
83+ Id int64 `json:"id"`
84+ ReleaseId int64 `json:"releaseId"`
85+ DefinitionEnvironmentId int64 `json:"definitionEnvironmentId"`
86+ Name string `json:"name"`
87+ Status string `json:"status"`
88+ Rank int64 `json:"rank"`
8889
89- TriggerReason string
90+ TriggerReason string `json:"triggerReason"`
9091
91- DeploySteps []ReleaseEnvironmentDeployStep
92+ DeploySteps []ReleaseEnvironmentDeployStep `json:"deploySteps"`
9293
93- PreDeployApprovals []ReleaseEnvironmentApproval
94- PostDeployApprovals []ReleaseEnvironmentApproval
94+ PreDeployApprovals []ReleaseEnvironmentApproval `json:"preDeployApprovals"`
95+ PostDeployApprovals []ReleaseEnvironmentApproval `json:"postDeployApprovals"`
9596
96- CreatedOn time.Time
97- QueuedOn time.Time
98- LastModifiedOn time.Time
97+ CreatedOn time.Time `json:"createdOn"`
98+ QueuedOn time.Time `json:"queuedOn"`
99+ LastModifiedOn time.Time `json:"lastModifiedOn"`
99100
100- TimeToDeploy float64
101+ TimeToDeploy float64 `json:"timeToDeploy"`
101102}
102103
103104type ReleaseEnvironmentDeployStep struct {
@@ -121,7 +122,7 @@ type ReleaseEnvironmentDeployStepPhase struct {
121122 Rank int64
122123 PhaseType string
123124 Status string
124- StartedOn time.Time
125+ StartedOn time.Time `json:"startedOn"`
125126}
126127
127128type ReleaseEnvironmentApproval struct {
@@ -132,21 +133,48 @@ type ReleaseEnvironmentApproval struct {
132133 Comments string
133134 IsAutomated bool
134135 IsNotificationOn bool
135- TrialNumber int64
136- Attempt int64
137- Rank int64
136+ TrialNumber int64 `json:"trialNumber"`
137+ Attempt int64 `json:"attempt"`
138+ Rank int64 `json:"rank"`
138139
139- Approver IdentifyRef
140- ApprovedBy IdentifyRef
140+ Approver IdentifyRef `json:"approver"`
141+ ApprovedBy IdentifyRef `json:"approvedBy"`
141142
142- CreatedOn time.Time
143- ModifiedOn time.Time
143+ CreatedOn time.Time `json:"createdOn"`
144+ ModifiedOn time.Time `json:"modifiedOn"`
144145}
145146
146147func (r * Release ) QueueDuration () time.Duration {
147148 return r .StartTime .Sub (r .QueueTime )
148149}
149150
151+ func (c * AzureDevopsClient ) ListLatestReleases (project string , duration time.Duration ) (list ReleaseList , error error ) {
152+ defer c .concurrencyUnlock ()
153+ c .concurrencyLock ()
154+
155+ minTime := time .Now ().Add (- duration )
156+
157+ url := fmt .Sprintf (
158+ "%v/_apis/release/releases?api-version=%v&isDeleted=false&$expand=94&minCreatedTime=%s" ,
159+ url .QueryEscape (project ),
160+ url .QueryEscape (c .ApiVersion ),
161+ url .QueryEscape (minTime .Format (time .RFC3339 )),
162+ )
163+ response , err := c .restVsrm ().R ().Get (url )
164+ if err := c .checkResponse (response , err ); err != nil {
165+ error = err
166+ return
167+ }
168+
169+ err = json .Unmarshal (response .Body (), & list )
170+ if err != nil {
171+ error = err
172+ return
173+ }
174+
175+ return
176+ }
177+
150178func (c * AzureDevopsClient ) ListReleases (project string , releaseDefinitionId int64 ) (list ReleaseList , error error ) {
151179 defer c .concurrencyUnlock ()
152180 c .concurrencyLock ()
0 commit comments