Skip to content

Commit 56333c8

Browse files
committed
Improve client
- Add json annotations - Add release ListLatestReleases
1 parent d3922e5 commit 56333c8

File tree

2 files changed

+76
-46
lines changed

2 files changed

+76
-46
lines changed

azure-devops-client/release.go

Lines changed: 71 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,42 @@ type ReleaseList struct {
1414

1515
type 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

4849
type 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

8182
type 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

103104
type 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

127128
type 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

146147
func (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+
150178
func (c *AzureDevopsClient) ListReleases(project string, releaseDefinitionId int64) (list ReleaseList, error error) {
151179
defer c.concurrencyUnlock()
152180
c.concurrencyLock()

azure-devops-client/release_definition.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ type ReleaseDefinition struct {
1515
Id int64 `json:"id"`
1616
Name string
1717
Path string
18-
ReleaseNameFormat string
18+
ReleaseNameFormat string `json:"releaseNameFormat"`
1919

2020
Environments []ReleaseDefinitionEnvironment
2121

22+
LastRelease Release `json:"lastRelease"`
23+
2224
Links Links `json:"_links"`
2325
}
2426

@@ -31,9 +33,9 @@ type ReleaseDefinitionEnvironment struct {
3133
CurrentRelease struct {
3234
Id int64
3335
Url string
34-
}
36+
} `json:"currentRelease"`
3537

36-
BadgeUrl string
38+
BadgeUrl string `json:"badgeUrl"`
3739
}
3840

3941
func (c *AzureDevopsClient) ListReleaseDefinitions(project string) (list ReleaseDefinitionList, error error) {

0 commit comments

Comments
 (0)