Skip to content

Commit

Permalink
Add Continuation Token Support For Releases (#113)
Browse files Browse the repository at this point in the history
* Added temp list for response values

* Generate continuation token url from header value

* Cycle through continuation tokens until none received

* Add counter variable to metric

* Unmarshal into  first time round

* Tidy up

* Remove counter

* Remove list len print cmd

* Removed extra length output

* Fixed casing on Dockerfile `as` statements

---------

Co-authored-by: Charlie B <[email protected]>
  • Loading branch information
cbat98 and Charlie B authored Feb 9, 2025
1 parent 00197b2 commit e01c946
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#############################################
# Build
#############################################
FROM --platform=$BUILDPLATFORM golang:1.23-alpine as build
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS build

RUN apk upgrade --no-cache --force
RUN apk add --update build-base make git
Expand All @@ -21,7 +21,7 @@ RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build
#############################################
# Test
#############################################
FROM gcr.io/distroless/static as test
FROM gcr.io/distroless/static AS test
USER 0:0
WORKDIR /app
COPY --from=build /go/src/github.com/webdevops/azure-devops-exporter/azure-devops-exporter .
Expand All @@ -30,7 +30,7 @@ RUN ["./azure-devops-exporter", "--help"]
#############################################
# Final-static
#############################################
FROM gcr.io/distroless/static as final-static
FROM gcr.io/distroless/static AS final-static
ENV LOG_JSON=1
WORKDIR /
COPY --from=test /app .
Expand Down
29 changes: 29 additions & 0 deletions azure-devops-client/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (c *AzureDevopsClient) ListReleaseHistory(project string, minTime time.Time
url.QueryEscape(minTime.Format(time.RFC3339)),
url.QueryEscape(int64ToString(c.LimitReleasesPerProject)),
)

response, err := c.restVsrm().R().Get(url)
if err := c.checkResponse(response, err); err != nil {
error = err
Expand All @@ -197,5 +198,33 @@ func (c *AzureDevopsClient) ListReleaseHistory(project string, minTime time.Time
return
}

continuationToken := response.Header().Get("x-ms-continuationtoken")

for continuationToken != "" {
continuationUrl := fmt.Sprintf(
"%v&continuationToken=%v",
url,
continuationToken,
)

response, err = c.restVsrm().R().Get(continuationUrl)
if err := c.checkResponse(response, err); err != nil {
error = err
return
}

var tmpList ReleaseList
err = json.Unmarshal(response.Body(), &tmpList)
if err != nil {
error = err
return
}

list.Count += tmpList.Count
list.List = append(list.List, tmpList.List...)

continuationToken = response.Header().Get("x-ms-continuationtoken")
}

return
}

0 comments on commit e01c946

Please sign in to comment.