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

40 lines
1 KiB
JavaScript
Raw Normal View History

2016-02-06 12:42:19 +00:00
import endpoints from './endpoints';
import request from './request';
2016-02-10 22:42:45 +00:00
import token from './token';
2016-02-06 12:42:19 +00:00
2016-02-21 11:59:53 +00:00
function JSONify(response) {
return response.json();
}
2016-02-23 23:12:32 +00:00
const [GET] = ['GET'];
2016-02-10 22:42:45 +00:00
export function checkToken(possibleToken) {
2016-02-06 12:42:19 +00:00
const url = endpoints.get('USER_INFO');
2016-02-23 23:12:32 +00:00
return request(url, GET, {}, possibleToken).then(function (response) {
2016-02-06 12:42:19 +00:00
return response.ok;
});
}
2016-02-10 22:42:45 +00:00
2016-02-23 23:12:32 +00:00
export async function getUserDetails() {
const CIToken = await token.get();
const url = endpoints.get('USER_INFO');
return await request(url, GET, {}, CIToken).then(JSONify);
}
2016-02-21 11:59:53 +00:00
export async function getProjects() {
const CIToken = await token.get();
2016-02-10 22:42:45 +00:00
const url = endpoints.get('ALL_PROJECTS');
2016-02-23 23:12:32 +00:00
return await request(url, GET, {}, CIToken).then(JSONify);
}
2016-03-13 19:28:22 +00:00
export async function getProjectRecentBuilds(user, repo, limit = 1, offset = 0) {
2016-02-23 23:12:32 +00:00
const CIToken = await token.get();
2016-03-13 19:28:22 +00:00
const url = endpoints.get('PROJECT_RECENTS').param({ user, repo }).query({ limit, offset });
2016-02-23 23:12:32 +00:00
return await request(
url,
GET,
{},
CIToken)
.then(JSONify);
2016-02-10 22:42:45 +00:00
}