Skip to content

Commit

Permalink
Add github oauth app authorization for increased ratelimits
Browse files Browse the repository at this point in the history
  • Loading branch information
datejer committed Nov 22, 2020
1 parent acbce3b commit e2b7bb9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
44 changes: 29 additions & 15 deletions api/[owner]/[repo].js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ module.exports = (req, res) => {
const { owner, repo } = req.query;

axios
.get(`https://api.github.com/repos/${owner}/${repo}/deployments`)
.get(`https://api.github.com/repos/${owner}/${repo}/deployments`, {
headers: {
Authorization: `Basic ${Buffer.from(
`${process.env.ID}:${process.env.SECRET}`
).toString("base64")}`,
},
})
.then((response) => {
if (response.data.length <= 0)
return res.status(404).json({
Expand Down Expand Up @@ -32,20 +38,28 @@ module.exports = (req, res) => {

const latest = vercelDeployments[0];

axios.get(latest.statuses_url).then((response) => {
if (response.data[0].state === "success")
return res.status(200).json({
url: "https://img.shields.io/badge/vercel-passing-success",
});
else if (response.data[0].state === "failure")
return res.status(200).json({
url: "https://img.shields.io/badge/vercel-failed-critical",
});
else if (response.data[0].state === "pending")
return res.status(200).json({
url: "https://img.shields.io/badge/vercel-pending-yellow",
});
});
axios
.get(latest.statuses_url, {
headers: {
Authorization: `Basic ${Buffer.from(
`${process.env.ID}:${process.env.SECRET}`
).toString("base64")}`,
},
})
.then((response) => {
if (response.data[0].state === "success")
return res.status(200).json({
url: "https://img.shields.io/badge/vercel-passing-success",
});
else if (response.data[0].state === "failure")
return res.status(200).json({
url: "https://img.shields.io/badge/vercel-failed-critical",
});
else if (response.data[0].state === "pending")
return res.status(200).json({
url: "https://img.shields.io/badge/vercel-pending-yellow",
});
});
})
.catch((error) => {
return res.status(error.response.status).json({
Expand Down
18 changes: 18 additions & 0 deletions api/ratelimit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const axios = require("axios");

module.exports = (req, res) => {
axios
.get(`https://api.github.com/rate_limit`, {
headers: {
Authorization: `Basic ${Buffer.from(
`${process.env.ID}:${process.env.SECRET}`
).toString("base64")}`,
},
})
.then((response) => {
return res.status(200).json(response.data);
})
.catch((error) => {
return res.status(400).json(error.response.data);
});
};

1 comment on commit e2b7bb9

@vercel
Copy link

@vercel vercel bot commented on e2b7bb9 Nov 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.