This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Sphere/app/api/CircleCI.js

39 lines
1,010 B
JavaScript

import endpoints from './endpoints';
import request from './request';
import token from './token';
function JSONify(response) {
return response.json();
}
const [GET] = ['GET'];
export function checkToken(possibleToken) {
const url = endpoints.get('USER_INFO');
return request(url, GET, {}, possibleToken).then(function (response) {
return response.ok;
});
}
export async function getUserDetails() {
const CIToken = await token.get();
const url = endpoints.get('USER_INFO');
return await request(url, GET, {}, CIToken).then(JSONify);
}
export async function getProjects() {
const CIToken = await token.get();
const url = endpoints.get('ALL_PROJECTS');
return await request(url, GET, {}, CIToken).then(JSONify);
}
export async function getProjectRecentBuilds(user, repo) {
const CIToken = await token.get();
const url = endpoints.get('PROJECT_RECENTS').param({ user, repo }).query({ limit: 1});
return await request(
url,
GET,
{},
CIToken)
.then(JSONify);
}