diff --git a/src/giteaClient.ts b/src/giteaClient.ts index 7971b6d..7b3d7fa 100644 --- a/src/giteaClient.ts +++ b/src/giteaClient.ts @@ -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 +} \ No newline at end of file