-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (35 loc) · 1.07 KB
/
index.js
File metadata and controls
39 lines (35 loc) · 1.07 KB
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
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit();
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
octokit.repos
.getContents({
owner: "tedneward",
repo: "ArchKatas",
path: ""
})
.then( (response) => {
let jsons = response.data.filter(
(item) => (item.type === 'file') &&
(item.name.endsWith('.json')));
// Pick one at random
let choice = getRandomInt(jsons.length);
console.log("Your Kata is #" + choice + " at " + jsons[choice].url);
octokit.repos.getContents({
owner: "tedneward",
repo: "ArchKatas",
path: jsons[choice].path,
mediaType: {
format: "raw",
},
})
.then((response) => {
const kataJSON = JSON.parse(response.data)
console.log(kataJSON.title);
console.log('\t' + kataJSON.description.join('\n\t'));
})
})
.catch ( (error) => {
console.log(error);
});