-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
40 lines (31 loc) · 967 Bytes
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const { Gitlab } = require('@gitbeaker/node');
exports.onPreInit = () => console.log("Loaded gatsby-source-gitlab-api")
const GITLAB_NODE_TYPE = `Gitlab`
exports.sourceNodes = async ({
actions,
createContentDigest,
createNodeId,
}, configOptions) => {
if (!configOptions.accessToken) {
console.error('You need to enter an accessToken');
}
const { createNode } = actions;
const api = new Gitlab({
token: configOptions.accessToken || 'x',
});
const projects = await api.Projects.all();
projects.forEach(project =>
createNode({
...project,
id: createNodeId(`${GITLAB_NODE_TYPE}-${project.id}`),
parent: null,
children: [],
internal: {
type: GITLAB_NODE_TYPE,
content: JSON.stringify(project),
contentDigest: createContentDigest(project),
},
})
)
return;
};