add pull request function

This commit is contained in:
Annie Sun 2023-03-21 20:25:58 -04:00
parent 2961bc4418
commit 4a9a986935
1 changed files with 27 additions and 7 deletions

View File

@ -1,8 +1,28 @@
// Sample function only, actual functions needed may be different
function makePullRequest() {
console.log("TODO: Make pull request");
// TODO: Remove this, for demo purposes only!
console.log(`API KEY: ${process.env.GITEA_API_KEY}`);
}
import fetch from 'node-fetch';
import 'dotenv/config'
export { makePullRequest };
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
}