9
9
*/
10
10
'use strict' ;
11
11
const crypto = require ( 'crypto' ) ;
12
+ const _ = require ( 'lodash' ) ;
12
13
const logger = require ( '../../utils/logger' ) ;
13
14
const Project = require ( '../../models' ) . Project ;
14
15
const dbHelper = require ( '../../utils/db-helper' ) ;
@@ -17,17 +18,24 @@ module.exports = (provider) => async (req, res, next) => {
17
18
let isValid = false ;
18
19
const params = req . body ;
19
20
if ( provider === 'github' ) {
20
- const projectDetail = await dbHelper . scanOne ( Project , {
21
+ const projectDetails = await dbHelper . scan ( Project , {
21
22
repoUrl : params . repository . html_url
22
23
} ) ;
23
-
24
- const hash = crypto . createHmac ( 'sha1' , projectDetail . secretWebhookKey ) . update ( req . rawBody ) . digest ( 'hex' ) ;
25
- isValid = `sha1=${ hash } ` === req . header ( 'X-Hub-Signature' ) ;
24
+ _ . forEach ( projectDetails , ( projectDetail ) => {
25
+ const hash = crypto . createHmac ( 'sha1' , projectDetail . secretWebhookKey ) . update ( req . rawBody ) . digest ( 'hex' ) ;
26
+ if ( `sha1=${ hash } ` === req . header ( 'X-Hub-Signature' ) ) {
27
+ isValid = true ;
28
+ }
29
+ } ) ;
26
30
} else if ( provider === 'gitlab' ) {
27
- const projectDetail = await dbHelper . scanOne ( Project , {
31
+ const projectDetails = await dbHelper . scan ( Project , {
28
32
repoUrl : params . project . web_url
29
33
} ) ;
30
- isValid = projectDetail . secretWebhookKey === req . header ( 'X-Gitlab-Token' ) ;
34
+ _ . forEach ( projectDetails , ( projectDetail ) => { // eslint-disable-line lodash/prefer-filter
35
+ if ( projectDetail . secretWebhookKey === req . header ( 'X-Gitlab-Token' ) ) {
36
+ isValid = true ;
37
+ }
38
+ } ) ;
31
39
} else {
32
40
// unknown provider
33
41
return next ( ) ;
0 commit comments