Skip to content

Commit

Permalink
Paging to retrieve older builds on TeamCity
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgmer committed Apr 17, 2016
1 parent 127c792 commit def0b43
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 17 additions & 5 deletions src/buildviz/teamcity/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@
(get :buildTypes)
(get :buildType))))

(defn get-builds [teamcity-url job-id]

(def ^:private builds-paging-count 100)

(defn- get-builds-from [teamcity-url job-id offset]
(let [response (get-json teamcity-url
"/httpAuth/app/rest/buildTypes/id:%s/builds/?fields=build(id,number,status,startDate,finishDate,state,revisions(revision(version,vcs-root-instance)))"
job-id)]
(get response :build)))
"/httpAuth/app/rest/buildTypes/id:%s/builds/?locator=count:%s,start:%s&fields=build(id,number,status,startDate,finishDate,state,revisions(revision(version,vcs-root-instance)))"
job-id builds-paging-count offset)
builds (get response :build)]
(if (< (count builds) builds-paging-count)
builds
(let [next-offset (+ offset builds-paging-count)]
(concat builds
(get-builds-from teamcity-url job-id next-offset))))))

(defn get-builds [teamcity-url job-id]
(get-builds-from teamcity-url job-id 0))


(def ^:private test-occurrence-paging-count 100)

(defn get-test-report-from [teamcity-url build-id offset]
(defn- get-test-report-from [teamcity-url build-id offset]
(let [response (get-json teamcity-url
"/httpAuth/app/rest/testOccurrences?locator=count:%s,start:%s,build:(id:%s)"
test-occurrence-paging-count offset build-id)
Expand Down
6 changes: 1 addition & 5 deletions test/buildviz/teamcity/sync_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(successful-json-response {:buildTypes {:buildType jobs}})]])

(defn- a-job-with-builds [job-id & builds]
(let [job-builds [(format "http://teamcity:8000/httpAuth/app/rest/buildTypes/id:%s/builds/?fields=build(id,number,status,startDate,finishDate,state,revisions(revision(version,vcs-root-instance)))"
(let [job-builds [(format "http://teamcity:8000/httpAuth/app/rest/buildTypes/id:%s/builds/?locator=count:100,start:0&fields=build(id,number,status,startDate,finishDate,state,revisions(revision(version,vcs-root-instance)))"
job-id)
(successful-json-response {:build (map #(merge {:revisions []
:status "SUCCESS"
Expand Down Expand Up @@ -152,7 +152,6 @@
(a-job-with-builds "jobId1"
{:id 10
:number 10
:state "finished"
:startDate "20160410T000000+0000"
:finishDate "20160410T000100+0000"})
(provide-buildviz-and-capture-puts latest-build-start stored))
Expand All @@ -168,17 +167,14 @@
(a-job-with-builds "jobId1"
{:id 12
:number 12
:state "finished"
:startDate "20160410T000400+0000"
:finishDate "20160410T000500+0000"}
{:id 11
:number 11
:state "finished"
:startDate "20160410T000200+0000"
:finishDate "20160410T000300+0000"}
{:id 10
:number 10
:state "finished"
:startDate "20160410T000000+0000"
:finishDate "20160410T000100+0000"})
(provide-buildviz-and-capture-puts beginning-of-2016 stored))
Expand Down

0 comments on commit def0b43

Please sign in to comment.