Eventer/src/giteaClient.ts

28 lines
835 B
TypeScript

import fetch from 'node-fetch';
import 'dotenv/config'
export const MAIN_BRANCH = "main"
export const GITEA_API_URL = "https://git.csclub.uwaterloo.ca/api/v1/repos"
export const makePullRequest = async (owner: string, repoName: string, title: string, body:string, branchName: string, assignee: string) => {
const PULL_URL = `${GITEA_API_URL}/${owner}/${repoName}/pulls`
console.log(PULL_URL)
const response = await fetch(PULL_URL, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.GITEA_API_KEY}`
},
body: JSON.stringify({
assignee: assignee,
base: MAIN_BRANCH,
title: title,
body: body,
head: branchName,
})
});
const content = await response.json();
return content
}