Skip to content

Commit

Permalink
feat: add ghe cloud check for parsing webhooks (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
pritamstyz4ever authored Sep 25, 2024
1 parent 48fd014 commit 720ac28
Show file tree
Hide file tree
Showing 3 changed files with 485 additions and 4 deletions.
20 changes: 16 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,7 @@ class GithubScm extends Scm {
const hookId = payloadHeaders['x-github-delivery'];
const checkoutUrl = hoek.reach(webhookPayload, 'repository.ssh_url');
const scmContexts = this._getScmContexts();
const scmContext = scmContexts[0];
const commitAuthors = [];
const commits = hoek.reach(webhookPayload, 'commits');
const deleted = hoek.reach(webhookPayload, 'deleted');
Expand All @@ -1526,6 +1527,17 @@ class GithubScm extends Scm {
return null;
}

// additional check for github enterprise cloud hooks
if (this.config.gheCloud) {
const enterpriseSlug = hoek.reach(webhookPayload, 'enterprise.slug');

if (this.config.gheCloudSlug !== enterpriseSlug) {
logger.info(`Skipping incorrect scm context for hook parsing, ${checkoutUrl}, ${scmContext}`);

return null;
}
}

// eslint-disable-next-line no-underscore-dangle
if (!(await verify(this.config.secret, JSON.stringify(webhookPayload), signature))) {
throwError('Invalid x-hub-signature');
Expand Down Expand Up @@ -1565,7 +1577,7 @@ class GithubScm extends Scm {
type: 'pr',
username: hoek.reach(webhookPayload, 'sender.login'),
hookId,
scmContext: scmContexts[0]
scmContext
};
}
case 'push': {
Expand Down Expand Up @@ -1596,7 +1608,7 @@ class GithubScm extends Scm {
commitAuthors,
lastCommitMessage: hoek.reach(webhookPayload, 'head_commit.message') || '',
hookId,
scmContext: scmContexts[0],
scmContext,
ref: hoek.reach(webhookPayload, 'ref'),
addedFiles: hoek.reach(webhookPayload, 'head_commit.added', { default: [] }),
modifiedFiles: hoek.reach(webhookPayload, 'head_commit.modified', { default: [] }),
Expand All @@ -1617,7 +1629,7 @@ class GithubScm extends Scm {
type: 'repo',
username: hoek.reach(webhookPayload, 'sender.login'),
hookId,
scmContext: scmContexts[0],
scmContext,
ref: hoek.reach(webhookPayload, 'release.tag_name'),
releaseId: hoek.reach(webhookPayload, 'release.id').toString(),
releaseName: hoek.reach(webhookPayload, 'release.name') || '',
Expand All @@ -1640,7 +1652,7 @@ class GithubScm extends Scm {
type: 'repo',
username: hoek.reach(webhookPayload, 'sender.login'),
hookId,
scmContext: scmContexts[0],
scmContext,
ref: hoek.reach(webhookPayload, 'ref')
};
}
Expand Down
Loading

0 comments on commit 720ac28

Please sign in to comment.