Fix: moved the bootstrapping of webhook first and better logging statements
This commit is contained in:
Родитель
401798add3
Коммит
142a3b2c72
|
@ -41,7 +41,9 @@ app.use((req, res, next) => {
|
|||
});
|
||||
|
||||
app.use(require('x-frame-options')());
|
||||
app.use(require('body-parser').json({ limit: '5mb' }));
|
||||
app.use(require('body-parser').json({
|
||||
limit: '5mb'
|
||||
}));
|
||||
app.use(require('cookie-parser')());
|
||||
app.use(noSniff());
|
||||
app.enable('trust proxy');
|
||||
|
@ -168,11 +170,13 @@ async.series([
|
|||
|
||||
global.models = {}
|
||||
},
|
||||
(callback) => {
|
||||
bootstrap('webhooks', callback)
|
||||
},
|
||||
|
||||
(callback) => {
|
||||
bootstrap('passport', callback)
|
||||
},
|
||||
|
||||
(callback) => {
|
||||
bootstrap('graphQueries', callback)
|
||||
},
|
||||
|
@ -181,10 +185,6 @@ async.series([
|
|||
bootstrap('api', callback)
|
||||
},
|
||||
|
||||
(callback) => {
|
||||
bootstrap('webhooks', callback)
|
||||
},
|
||||
|
||||
(callback) => {
|
||||
bootstrap('controller', callback)
|
||||
}
|
||||
|
@ -238,6 +238,7 @@ app.all('/api/:obj/:fun', async (req, res) => {
|
|||
app.all('/github/webhook/:repo', (req, res) => {
|
||||
let event = req.headers['x-github-event']
|
||||
try {
|
||||
|
||||
if (!webhooks[event]) {
|
||||
return res.status(400).send('Unsupported event')
|
||||
}
|
||||
|
|
|
@ -400,7 +400,7 @@ class ClaService {
|
|||
})
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG: checkPullRequestSignatures-->getGistObject')
|
||||
console.log('DEBUG: checkPullRequestSignatures-->getGistObject for the repo' + JSON.stringify(args.repo))
|
||||
const gist = await this._getGistObject(args.gist, item.token)
|
||||
if (!gist) {
|
||||
throw new Error('No gist found for item')
|
||||
|
@ -408,7 +408,7 @@ class ClaService {
|
|||
args.gist_version = gist.data.history[0].version
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG: checkPullRequestSignatures-->getPR')
|
||||
console.log('DEBUG: checkPullRequestSignatures-->getPR for the repo' + JSON.stringify(args.repo))
|
||||
const pullRequest = (await this._getPR(args.owner, args.repo, args.number, item.token)).data
|
||||
//console.log(pullRequest)
|
||||
if (!pullRequest) {
|
||||
|
@ -488,7 +488,7 @@ class ClaService {
|
|||
|
||||
if (committerSignatureRequired) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG: checkPullRequestSignatures-->getPRCommitters')
|
||||
console.log('DEBUG: checkPullRequestSignatures-->getPRCommitters for the repo ' + JSON.stringify(args.repo))
|
||||
const committers = await repoService.getPRCommitters(args)
|
||||
signees = _.uniqWith([...signees, ...committers], (object, other) => object.id == other.id)
|
||||
}
|
||||
|
@ -497,7 +497,7 @@ class ClaService {
|
|||
signee && !(item.isUserWhitelisted !== undefined && item.isUserWhitelisted(signee.name))
|
||||
)
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG: checkPullRequestSignatures-->return _checkAll')
|
||||
console.log('DEBUG: checkPullRequestSignatures-->return _checkAll for the repo ' + JSON.stringify(args.repo))
|
||||
return this._checkAll(
|
||||
signees,
|
||||
item.repoId,
|
||||
|
|
|
@ -61,16 +61,16 @@ function storeRequest(committers, repo, owner, number) {
|
|||
async function updateStatusAndComment(args, item) {
|
||||
try {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG: reposService.gerPRCommitters')
|
||||
//console.log('DEBUG: reposService.gerPRCommitters')
|
||||
const committers = await repoService.getPRCommitters(args)
|
||||
if (committers && committers.length > 0) {
|
||||
let checkResult
|
||||
try {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG: check cla')
|
||||
//console.log('DEBUG: check cla')
|
||||
checkResult = await cla.check(args, item)
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG: updateStatusAndComment ')
|
||||
console.log('DEBUG: updateStatusAndComment for the repo ' + JSON.stringify(args.repo))
|
||||
} catch (error) {
|
||||
logger.warn(new Error(error).stack)
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ async function handleWebHook(args, item) {
|
|||
const claRequired = await cla.isClaRequired(args, item)
|
||||
if (claRequired) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log("DEBUG: handleWebHook ")
|
||||
console.log("DEBUG: handleWebHook for the repo" + JSON.stringify(args.repo))
|
||||
return updateStatusAndComment(args, item)
|
||||
}
|
||||
|
||||
|
@ -132,10 +132,6 @@ async function handleWebHook(args, item) {
|
|||
module.exports = async function (req, res) {
|
||||
|
||||
if (['opened', 'reopened', 'synchronize'].indexOf(req.args.action) > -1 && (req.args.repository && req.args.repository.private == false)) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.time('webhook')
|
||||
|
||||
|
||||
if (req.args.pull_request && req.args.pull_request.html_url) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`pull request ${req.args.action} ${req.args.pull_request.html_url}`)
|
||||
|
@ -163,15 +159,11 @@ module.exports = async function (req, res) {
|
|||
args.orgId = undefined
|
||||
}
|
||||
|
||||
await handleWebHook(args, item)
|
||||
// eslint-disable-next-line no-console
|
||||
console.timeEnd('webhook')
|
||||
handleWebHook(args, item)
|
||||
} catch (e) {
|
||||
logger.warn(e)
|
||||
|
||||
}
|
||||
// }, config.server.github.enforceDelay)
|
||||
|
||||
}
|
||||
res.status(200).send('OK')
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче