Add GitLab

This commit is contained in:
Taevas 2023-05-09 15:23:28 +02:00
parent 1bf1832c2a
commit ea8db8cda3
4 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,30 @@
import { Handler } from '@netlify/functions'
import fetch from "node-fetch"
const handler: Handler = async (event, context) => {
let gitlab = await fetch("https://gitlab.com/api/v4/events?action=pushed", {
method: "GET",
headers: {
"PRIVATE-TOKEN": process.env.API_GITLAB!,
"Content-Type": "application/json",
"Accept": "application/json"
}
})
if (gitlab.status !== 200) {
return {
statusCode: 404,
body: ""
}
}
let json = await gitlab.json() as {[key: string]: any}
let date = json[0].created_at.substring(0, json[0].created_at.indexOf("T"))
return {
statusCode: 200,
body: JSON.stringify({date})
}
}
export { handler }