Created
February 16, 2021 16:58
-
-
Save groupsky/e67b5d2d6cf4ff9f7835cec8ff9bd824 to your computer and use it in GitHub Desktop.
Fetch travis builds info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SET PROPER VALUES | |
let authToken = 'token zxcvbnmsdfhjkqwrt' | |
let end = '2021-00-00T00:00:00Z' | |
let repo = 123456 | |
// runtime variables | |
let finished = false | |
let data = [] | |
let offset = 0 | |
let limit = 50 | |
// the main cycle | |
while (!finished) { | |
const response = await fetch('https://api.travis-ci.com/repo/'+repo+'/builds?event_type=pull_request%2Cpush&limit='+limit+'&offset='+offset+'&skip_count=true&include=build.request%2Cjob.started_at%2Cbuild.created_by', { | |
headers: { | |
'travis-api-version': 3, | |
authorization: authToken | |
} | |
}) | |
const json = await response.json() | |
json.builds.forEach(b => { | |
offset++ | |
data.push({ | |
id: b.id, | |
number: b.number, | |
event_type: b.event_type || b.request.event_type, | |
state: b.state, | |
duration: b.duration, | |
finished_at: b.finished_at, | |
created_at: b.created_at || b.request.created_at, | |
started_at: b.started_at, | |
created_by: b.created_by && b.created_by.login, | |
// restarted jobs update the build started time, so this finds the oldest started time from all jobs | |
// if the whole build was restarted this will not find the initial start time | |
// - i'm yet to find a way to get the initial start time, or at least mark which builds were restarted | |
min_started_at: b.jobs.reduce((min, j) => j.started_at < min ? j.started_at : min, b.started_at), | |
}) | |
if (b.request.created_at < end) { | |
finished = true | |
} | |
}) | |
// report some progress | |
console.log(data.length, data[data.length-1].created_at) | |
} | |
// print as csv | |
console.log(Object.keys(data[0]).join(';')+'\n'+data.map(r => Object.values(r).join(';')).join('\n')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment