rpc: cleanup

Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
dzdidi
2024-01-29 09:46:39 +00:00
parent 3ed49d3d04
commit 2b59f64e33

View File

@@ -65,18 +65,12 @@ module.exports = class RPC {
const { url, repoName, branch, userId } = await this.parseReq(publicKey, req) const { url, repoName, branch, userId } = await this.parseReq(publicKey, req)
const isContributor = acl.getContributors(repoName).includes(userId) const isContributor = acl.getContributors(repoName).includes(userId)
console.error('pushHandler', { url, repoName, branch, userId, isContributor }) if (!isContributor) throw new Error('You are not allowed to push to this repo')
if (!isContributor) {
throw new Error('You are not allowed to push to this repo')
}
const isProtectedBranch = acl.getACL(repoName).protectedBranches.includes(branch) const isProtectedBranch = acl.getACL(repoName).protectedBranches.includes(branch)
const isAdmin = acl.getAdmins(repoName).includes(userId) const isAdmin = acl.getAdmins(repoName).includes(userId)
if (isProtectedBranch && !isAdmin) { if (isProtectedBranch && !isAdmin) throw new Error('You are not allowed to push to this branch')
throw new Error('You are not allowed to push to this branch')
}
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
const env = { ...process.env, GIT_DIR: home.getCodePath(repoName) } const env = { ...process.env, GIT_DIR: home.getCodePath(repoName) }
@@ -96,16 +90,12 @@ module.exports = class RPC {
const { url, repoName, branch, userId } = await this.parseReq(publicKey, req) const { url, repoName, branch, userId } = await this.parseReq(publicKey, req)
const isContributor = acl.getContributors(repoName).includes(userId) const isContributor = acl.getContributors(repoName).includes(userId)
if (!isContributor) { if (!isContributor) throw new Error('You are not allowed to push to this repo')
throw new Error('You are not allowed to push to this repo')
}
const isProtectedBranch = acl.getACL(repoName).protectedBranches.includes(branch) const isProtectedBranch = acl.getACL(repoName).protectedBranches.includes(branch)
const isAdmin = acl.getAdmins(repoName).includes(userId) const isAdmin = acl.getAdmins(repoName).includes(userId)
if (isProtectedBranch && !isAdmin) { if (isProtectedBranch && !isAdmin) throw new Error('You are not allowed to push to this branch')
throw new Error('You are not allowed to push to this branch')
}
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
const env = { ...process.env, GIT_DIR: home.getCodePath(repoName) } const env = { ...process.env, GIT_DIR: home.getCodePath(repoName) }
@@ -125,16 +115,13 @@ module.exports = class RPC {
const { url, repoName, branch, userId } = await this.parseReq(publicKey, req) const { url, repoName, branch, userId } = await this.parseReq(publicKey, req)
const isContributor = acl.getContributors(repoName).includes(userId) const isContributor = acl.getContributors(repoName).includes(userId)
if (!isContributor) { if (!isContributor) throw new Error('You are not allowed to push to this repo')
throw new Error('You are not allowed to push to this repo')
}
const isProtectedBranch = acl.getACL(repoName).protectedBranches.includes(branch) const isProtectedBranch = acl.getACL(repoName).protectedBranches.includes(branch)
const isAdmin = acl.getAdmins(repoName).includes(userId) const isAdmin = acl.getAdmins(repoName).includes(userId)
if (isProtectedBranch && !isAdmin) { if (isProtectedBranch && !isAdmin) throw new Error('You are not allowed to push to this branch')
throw new Error('You are not allowed to push to this branch')
}
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
const env = { ...process.env, GIT_DIR: home.getCodePath(repoName) } const env = { ...process.env, GIT_DIR: home.getCodePath(repoName) }
const child = spawn('git', ['branch', '-D', branch], { env }) const child = spawn('git', ['branch', '-D', branch], { env })