mirror of
https://github.com/aljazceru/gitpear.git
synced 2025-12-17 14:14:22 +01:00
32
src/rpc.js
32
src/rpc.js
@@ -23,7 +23,7 @@ module.exports = class RPC {
|
|||||||
rpc.respond('get-refs', async req => await this.getRefsHandler(req))
|
rpc.respond('get-refs', async req => await this.getRefsHandler(req))
|
||||||
|
|
||||||
/* -- PUSH HANDLERS -- */
|
/* -- PUSH HANDLERS -- */
|
||||||
rpc.respond('push-to-repo', async req => this.pushHandler(req))
|
rpc.respond('push-to-repo', async req => await this.pushHandler(req))
|
||||||
rpc.respond('force-push-to-repo', req => this.forcePushHandler(req))
|
rpc.respond('force-push-to-repo', req => this.forcePushHandler(req))
|
||||||
rpc.respond('delete-branch-from-repo', req => this.deleteBranchHandler(req))
|
rpc.respond('delete-branch-from-repo', req => this.deleteBranchHandler(req))
|
||||||
|
|
||||||
@@ -44,24 +44,26 @@ module.exports = class RPC {
|
|||||||
return Buffer.from(JSON.stringify(res))
|
return Buffer.from(JSON.stringify(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
pushHandler (req) {
|
async pushHandler (req) {
|
||||||
const { url, repo, key, branch } = this.parsePushCommand(req)
|
const { url, repo, key, branch } = this.parsePushCommand(req)
|
||||||
// TODO: check ACL
|
// TODO: check ACL
|
||||||
// collect stdout to buffer and return it
|
// collect stdout to buffer and return it
|
||||||
const process = spawn('git', ['fetch', url, `${branch}:${branch}`], { env: { GIT_DIR: home.getCodePath(repo) } })
|
return await new Promise((resolve, reject) => {
|
||||||
let outBuffer = Buffer.from('')
|
const process = spawn('git', ['fetch', url, `${branch}:${branch}`], { env: { GIT_DIR: home.getCodePath(repo) } })
|
||||||
let errBuffer = Buffer.from('')
|
//let outBuffer = Buffer.from('')
|
||||||
process.stdout.on('data', data => {
|
// process.stdout.on('data', data => {
|
||||||
console.error('data:', JSON.stringify(data.toString()))
|
// console.error('data:', JSON.stringify(data.toString()))
|
||||||
outBuffer = Buffer.concat([outBuffer, data])
|
// outBuffer = Buffer.concat([outBuffer, data])
|
||||||
})
|
// })
|
||||||
process.stderr.on('data', data => {
|
let errBuffer = Buffer.from('')
|
||||||
console.error('error:', JSON.stringify(data.toString()))
|
process.stderr.on('data', data => {
|
||||||
errBuffer = Buffer.concat([errBuffer, data])
|
errBuffer = Buffer.concat([errBuffer, data])
|
||||||
})
|
})
|
||||||
|
|
||||||
process.on('close', code => {
|
process.on('close', code => {
|
||||||
console.error(`child process exited with code ${code}`)
|
console.error(`child process exited with code ${code}`)
|
||||||
|
return code === 0 ? resolve(errBuffer) : reject(errBuffer)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user