-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit acbce3b
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
.vercel | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const axios = require("axios"); | ||
|
||
module.exports = (req, res) => { | ||
const { owner, repo } = req.query; | ||
|
||
axios | ||
.get(`https://api.github.com/repos/${owner}/${repo}/deployments`) | ||
.then((response) => { | ||
if (response.data.length <= 0) | ||
return res.status(404).json({ | ||
error: { | ||
code: "not_found", | ||
message: "The requested repository does not have any deployments.", | ||
}, | ||
}); | ||
|
||
const vercelDeployments = response.data.filter( | ||
(deployment) => | ||
deployment.creator.login === "vercel[bot]" && | ||
deployment.creator.html_url === "https://github.com/apps/vercel" && | ||
deployment.creator.type === "Bot" | ||
); | ||
|
||
if (vercelDeployments.length <= 0) | ||
return res.status(404).json({ | ||
error: { | ||
code: "not_found", | ||
message: | ||
"The requested repository does not have any Vercel deployments.", | ||
}, | ||
}); | ||
|
||
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", | ||
}); | ||
}); | ||
}) | ||
.catch((error) => { | ||
return res.status(error.response.status).json({ | ||
error: { | ||
code: error.response.statusText.toLowerCase().replace(/ /gi, "_"), | ||
message: "The requested repository does not have any deployments.", | ||
}, | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = (req, res) => { | ||
res.json({ | ||
message: "Hello World!", | ||
}); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "vercel-badge", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^0.21.0" | ||
} | ||
} |
acbce3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: