Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jfilipe/9809048a9fc6c292c1573b8fac198c3c to your computer and use it in GitHub Desktop.
Save jfilipe/9809048a9fc6c292c1573b8fac198c3c to your computer and use it in GitHub Desktop.
Loops through all projects and returns project name, release stage and event totals for a given number of days
// A rate limit may be hit - if so you will need to add some sleeps
const fetch = require('node-fetch');
const url = 'https://api.bugsnag.com/'
const auth_token = 'YOUR PERSONAL AUTH TOKEN'
const last_number_of_days = '100' // eg. 7 would return totals from the last week
let headers = {
headers: {
'Authorization': `token ${auth_token}`,
'Content-Type': 'application/json',
'X-Version': '2',
}
}
const get_events_by_release_stage = async () => {
const org_id = await get_organization_id();
const projects = await get_projects(org_id);
for(const project of projects) {
console.log("PROJECT - " + project.name)
const pivot = await get_release_stage_pivot(project.id)
}
}
const get_organization_id = async () => {
let path = "user/organizations/";
let response = await fetch(url + path, Object.assign({ method: "GET" }, headers));
if (response.ok) {
let org_data = await response.json();
return org_data[0]['id']
} else {
console.error("HTTP-Error: " + response.status);
}
}
const get_projects = async (org_id) => {
let path = "/organizations/"+ org_id + "/projects";
let response = await fetch(url + path, Object.assign({ method: "GET" }, headers));
if (response.ok) {
let project_data = await response.json();
return project_data
} else {
console.error("HTTP-Error: " + response.status);
}
}
const get_release_stage_pivot = async (project_id) => {
let filters = "?filters[event.since][][value]="+ last_number_of_days + "d"
let path = "projects/"+ project_id + "/pivots" + filters;
let response = await fetch(url + path, Object.assign({ method: "GET" }, headers));
if (response.ok) {
let pivot_data = await response.json();
let release_stage_pivot= pivot_data[3].summary.list;
// loop through the list of release stages to fetch # of events
for(const release_stage of release_stage_pivot) {
console.log("stage: " + release_stage['value'] + ", num_of_events: " + release_stage['events'])
}
return true
} else {
console.error("HTTP-Error: " + response.status);
}
}
get_events_by_release_stage();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment