Compare commits

...

2 Commits

Author SHA1 Message Date
Annie Sun 7f0ad68ea2 add reviewers function 2023-03-30 16:19:50 -04:00
Annie Sun 33d7f6a50f remove comments 2023-03-30 16:19:20 -04:00
2 changed files with 35 additions and 5 deletions

View File

@ -4,9 +4,8 @@ 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) => {
export const makePullRequest = async (owner: string, repoName: string, title: string, body:string, branchName: string, reviewers: Array<string>, assignee: string = "") => {
const PULL_URL = `${GITEA_API_URL}/${owner}/${repoName}/pulls`
console.log(PULL_URL)
const response = await fetch(PULL_URL, {
method: 'POST',
@ -24,5 +23,38 @@ export const makePullRequest = async (owner: string, repoName: string, title: st
})
});
const content = await response.json();
return content
if (response.status != 201) {
console.log(content);
throw Error("Error from Gitea when making PR: " + content.errors);
}
addReviewers(reviewers, owner, repoName, content.number);
return content.url
}
async function addReviewers(
reviewers: Array<string>,
owner: string,
repoName: string,
prNumber: number
) {
const PULL_URL = `${GITEA_API_URL}/${owner}/${repoName}/pulls/${prNumber}/requested_reviewers`;
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({
reviewers: reviewers,
}),
});
const content = await response.json();
if (response.status != 201) {
throw Error("Error from Gitea when adding reviewers " + content.errors);
}
return
}

View File

@ -81,8 +81,6 @@ let upload = multer({
// Routes
app.get("/", async (req, res) => {
res.sendFile(path.join(publicDirname, "index.html"));
// TODO: Implement this for www
// makePullRequest();
});