Skip to content

Commit

Permalink
Merge pull request #890 from zirreal/robonomics-wiki-test
Browse files Browse the repository at this point in the history
github api
  • Loading branch information
zirreal authored Sep 23, 2024
2 parents 37b1932 + d75e721 commit 8af9508
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions src/_data/github.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
const eleventyFetch = require("@11ty/eleventy-fetch");

// const getDocs = async () => {
// let url = 'https://api.github.com/repos/airalab/robonomics-wiki/src/docs';

// try {
// let json = await eleventyFetch(url, {
// duration: "5d",
// type: "json",
// fetchOptions: {
// headers: {
// Accept: "application/vnd.github+jso",
// "X-GitHub-Api-Version": "2022-11-28",
// Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
// },
// },
// });

// return json;
// } catch (error) {
// console.error(`Fetch failed in github.js. ${error}`);
// }
// };

// module.exports = async function () {
// let user = "airalab";
// let repo = "robonomics-wiki"
// let url = `https://api.github.com/repos/${user}/${repo}/commits`;

// const arr = await getDocs();
// const result = [];

// arr.forEach(async d => {
// if(d.name.includes('md')) {
// try {
// let json = await eleventyFetch(url + `?path=src/docs/${d.name}`, {
// duration: "3d",
// type: "json",
// fetchOptions: {
// headers: {
// Accept: "application/vnd.github+jso",
// "X-GitHub-Api-Version": "2022-11-28",
// Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
// },
// },
// });
// result.push({name: d.name, author: json[0].commit.author.name, date: json[0].commit.author.date, url: json[0].html_url});
// } catch (error) {
// console.error(`Fetch failed in github.js. ${error}`);
// }
// }
// })

// return result

// };
const getDocs = async () => {
let url = 'https://api.github.com/repos/airalab/robonomics-wiki/contents/src/docs';

try {
let json = await eleventyFetch(url, {
duration: "5d",
type: "json",
fetchOptions: {
headers: {
Accept: "application/vnd.github+jso",
"X-GitHub-Api-Version": "2022-11-28",
Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
},
},
});

return json;
} catch (error) {
console.error(`Fetch failed in github.js. ${error}`);
}
};

module.exports = async function () {
let user = "airalab";
let repo = "robonomics-wiki"
let url = `https://api.github.com/repos/${user}/${repo}/commits`;

const arr = await getDocs();
const result = [];

arr.forEach(async d => {
if(d.name.includes('md')) {
try {
let json = await eleventyFetch(url + `?path=src/docs/${d.name}`, {
duration: "3d",
type: "json",
fetchOptions: {
headers: {
Accept: "application/vnd.github+jso",
"X-GitHub-Api-Version": "2022-11-28",
Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
},
},
});
result.push({name: d.name, author: json[0].commit.author.name, date: json[0].commit.author.date, url: json[0].html_url});
} catch (error) {
console.error(`Fetch failed in github.js. ${error}`);
}
}
})

return result

};

0 comments on commit 8af9508

Please sign in to comment.