Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
feat: Support webhook url config key
Browse files Browse the repository at this point in the history
  • Loading branch information
startnow65 committed Apr 8, 2019
1 parent eeada26 commit cb13bab
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
5 changes: 5 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ VALID_PR_TEMPLATE_PATHS:
- "/PULL_REQUEST_TEMPLATE"
- "/PULL_REQUEST_TEMPLATE.txt"
- "/PULL_REQUEST_TEMPLATE.md"

# Explicit webhook url to use for receiving webhooks from Github
# If this is commented out, Zappr uses "<HOST_ADDR config value>/api/hook' as the webhook url
# HOOK_URL: http://mywebhookdomain/zappr/api/hook

ZAPPR_DEFAULT_CONFIG:
autobranch:
pattern: "{number}-{title}"
Expand Down
3 changes: 2 additions & 1 deletion server/service/GithubService.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ export class GithubService {
async updateWebhookFor(user, repo, events, accessToken) {
debug(`${user}/${repo}: updating webhook with events: ${events.join(", ")}`)
let path = API_URL_TEMPLATES.HOOK.replace('${owner}', user).replace('${repo}', repo)
let hook_url = nconf.get('HOST_ADDR') + '/api/hook'
const HOOK_URL = nconf.get('HOOK_URL')
let hook_url = HOOK_URL ? HOOK_URL : nconf.get('HOST_ADDR') + '/api/hook'
// payload for hook
let payload = {
name: 'web',
Expand Down
71 changes: 71 additions & 0 deletions test/server/github.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,75 @@ describe('The Github service', () => {
}
})
})

describe('#updateWebhookFor', () => {
it('should build webhook url from host address', async(done) => {
try {
const USER = 'user'
const REPO = 'repo'
const TOKEN = 'token'

github.fetchPath.returns([])
nconf.set('HOOK_URL', null)

await github.updateWebhookFor(USER, REPO, [], TOKEN)
expect(github.fetchPath.args).to.deep.equal([
['GET', `/repos/${USER}/${REPO}/hooks`,
null,
TOKEN],
['POST', `/repos/${USER}/${REPO}/hooks`,
{
name: 'web',
active: true,
events: [],
config: {
url: nconf.get('HOST_ADDR') + '/api/hook',
content_type: 'json',
secret: nconf.get('GITHUB_HOOK_SECRET')
}
},
TOKEN]
])

done()
} catch (e) {
done(e)
}
})

it('should use provided webhook url', async(done) => {
try {
const USER = 'user'
const REPO = 'repo'
const TOKEN = 'token'
const HOOK_URL = 'hookurl'

github.fetchPath.returns([])
nconf.set('HOOK_URL', HOOK_URL)

await github.updateWebhookFor(USER, REPO, [], TOKEN)
expect(github.fetchPath.args).to.deep.equal([
['GET', `/repos/${USER}/${REPO}/hooks`,
null,
TOKEN],
['POST', `/repos/${USER}/${REPO}/hooks`,
{
name: 'web',
active: true,
events: [],
config: {
url: HOOK_URL,
content_type: 'json',
secret: nconf.get('GITHUB_HOOK_SECRET')
}
},
TOKEN]
])

done()
} catch (e) {
done(e)
}
})
})
})

0 comments on commit cb13bab

Please sign in to comment.