gatsby-source-circleci
Version:
Source plugin for [CircleCI's API](https://circleci.com/docs/api/#circleci-api-reference-guide).
36 lines (35 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sourceNodes = exports.pluginOptionsSchema = void 0;
const circleci_api_1 = require("circleci-api");
const pluginOptionsSchema = ({ Joi, }) => {
return Joi.object({
apiKey: Joi.string().required().description("Your CircleCI access token"),
});
};
exports.pluginOptionsSchema = pluginOptionsSchema;
const sourceNodes = async ({ actions, createNodeId, createContentDigest, reporter }, pluginOptions) => {
const { createNode } = actions;
const options = {
token: pluginOptions.apiKey,
};
const api = new circleci_api_1.CircleCI(options);
const nodeHelper = (input, name) => {
const node = Object.assign(Object.assign({}, input), { id: createNodeId(`gatsby-source-circleci-${input.reponame}`), parent: null, children: [], internal: {
type: `CircleCI${name}`,
} });
node.internal.content = JSON.stringify(node);
node.internal.contentDigest = createContentDigest(node);
createNode(node);
};
try {
const me = await api.me();
const projects = await api.projects();
nodeHelper(me, "Me");
projects.forEach((project) => nodeHelper(project, "Projects"));
}
catch (e) {
reporter.panicOnBuild("Error creating nodes from gatsby-source-circleci", e);
}
};
exports.sourceNodes = sourceNodes;