Changed spawn to exec
This commit is contained in:
21
src/index.ts
21
src/index.ts
@@ -1,8 +1,9 @@
|
||||
import express, {Application, ErrorRequestHandler, Request, Response} from 'express'
|
||||
import 'dotenv/config'
|
||||
import * as env from 'env-var'
|
||||
import {PushWebhook} from "./PushWebhook";
|
||||
import {spawn} from "child_process";
|
||||
import { PushWebhook } from "./PushWebhook";
|
||||
import { exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
|
||||
const app: Application = express()
|
||||
|
||||
@@ -23,19 +24,17 @@ async function parsePushHook(webhook: PushWebhook) {
|
||||
clearTimeout(timeouts[repository])
|
||||
timeouts[repository] = setTimeout(async () => {
|
||||
delete timeouts[repository]
|
||||
const filename = repository
|
||||
const safeFilename = repository
|
||||
.replace(/[^\w\s/]/gi, '-')
|
||||
.replace(/\//gi, '_')
|
||||
const safeTag = tag
|
||||
.replace(/[^a-z0-9-]/gi, '')
|
||||
const safeResourceUri = tag
|
||||
.replace(/[^a-z0-9-./:]/gi, '')
|
||||
try {
|
||||
const cp = spawn(`./${filename}.sh`, [tag, resource_url], {
|
||||
cwd: rootDir,
|
||||
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
|
||||
await promisify(exec)(`./${safeFilename}.sh ${safeTag} ${safeResourceUri}`, {
|
||||
cwd: rootDir
|
||||
});
|
||||
cp.on('message', data => console.log(data))
|
||||
await new Promise((resolve, reject) => {
|
||||
cp.on('close', resolve)
|
||||
cp.on('error', reject)
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user