-
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
Showing
8 changed files
with
375 additions
and
124 deletions.
There are no files selected for viewing
This file was deleted.
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,104 @@ | ||
import axios from "axios"; | ||
import path from "path"; | ||
import fs from "fs"; | ||
|
||
import type { VercelRequest, VercelResponse } from "@vercel/node"; | ||
|
||
export default (req: VercelRequest, res: VercelResponse) => { | ||
const { owner, repo } = req.query; | ||
|
||
if (!owner || typeof owner !== "string") { | ||
res.statusCode = 400; | ||
return res.json({ message: "Please input the repository owner!" }); | ||
} | ||
|
||
if (!repo || typeof repo !== "string") { | ||
res.statusCode = 400; | ||
return res.json({ message: "Please input the repository name!" }); | ||
} | ||
|
||
let style; | ||
if (!req.query.style) style = "flat"; | ||
else if ( | ||
req.query.style === "flat" || | ||
req.query.style === "flat-square" || | ||
req.query.style === "for-the-badge" || | ||
req.query.style === "plastic" | ||
) | ||
style = req.query.style; | ||
|
||
axios | ||
.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) { | ||
res.setHeader("Content-Type", "image/svg+xml"); | ||
return fs | ||
.createReadStream( | ||
path.join(__dirname, `../../assets/${style}/none.svg`) | ||
) | ||
.pipe(res); | ||
} | ||
|
||
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) { | ||
res.setHeader("Content-Type", "image/svg+xml"); | ||
return fs | ||
.createReadStream( | ||
path.join(__dirname, `../../assets/${style}/none.svg`) | ||
) | ||
.pipe(res); | ||
} | ||
|
||
const latest = vercelDeployments[0]; | ||
|
||
axios | ||
.get(latest.statuses_url, { | ||
headers: { | ||
Authorization: `Basic ${Buffer.from( | ||
`${process.env.ID}:${process.env.SECRET}` | ||
).toString("base64")}`, | ||
}, | ||
}) | ||
.then((response) => { | ||
res.setHeader("Content-Type", "image/svg+xml"); | ||
if (response.data[0].state === "success") | ||
return fs | ||
.createReadStream( | ||
path.join(__dirname, `../../assets/${style}/passing.svg`) | ||
) | ||
.pipe(res); | ||
else if (response.data[0].state === "failure") | ||
return fs | ||
.createReadStream( | ||
path.join(__dirname, `../../assets/${style}/failed.svg`) | ||
) | ||
.pipe(res); | ||
else if (response.data[0].state === "pending") | ||
return fs | ||
.createReadStream( | ||
path.join(__dirname, `../../assets/${style}/pending.svg`) | ||
) | ||
.pipe(res); | ||
}); | ||
}) | ||
.catch((error) => { | ||
res.setHeader("Content-Type", "image/svg+xml"); | ||
return fs | ||
.createReadStream( | ||
path.join(__dirname, `../../assets/${style}/error.svg`) | ||
) | ||
.pipe(res); | ||
}); | ||
}; |
This file was deleted.
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,8 @@ | ||
import { VercelRequest, VercelResponse } from "@vercel/node"; | ||
|
||
export default (req: VercelRequest, res: VercelResponse) => { | ||
res.json({ | ||
message: | ||
"Use /[owner]/[repo] to get a Vercel deployment badge for your github repository!", | ||
}); | ||
}; |
This file was deleted.
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,20 @@ | ||
import axios from "axios"; | ||
|
||
import { VercelRequest, VercelResponse } from "@vercel/node"; | ||
|
||
export default (req: VercelRequest, res: VercelResponse) => { | ||
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); | ||
}); | ||
}; |
Oops, something went wrong.