Skip to content

Commit

Permalink
Merge pull request #817 from bobvanderlinden/pr-no-config-error
Browse files Browse the repository at this point in the history
fix: avoid emitting errors when no configuration is available
  • Loading branch information
bobvanderlinden authored Aug 19, 2020
2 parents 3c5cba9 + afc6ffc commit d5f63fb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Context } from 'probot'
import getConfig from 'probot-config'
import { Decoder, object, string, optional, number, boolean, array, oneOf, constant } from '@mojotech/json-type-validation'

class ConfigNotFoundError extends Error {
export class ConfigNotFoundError extends Error {
constructor (
public readonly filePath: string
) {
Expand Down
16 changes: 14 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Application, Context } from 'probot'
import { loadConfig } from './config'
import { loadConfig, ConfigNotFoundError, ConfigValidationError } from './config'
import { WorkerContext } from './models'
import Raven from 'raven'
import { RepositoryWorkers } from './repository-workers'
Expand Down Expand Up @@ -33,7 +33,19 @@ async function useWorkerContext (options: {app: Application, context: Context, i
event: options.context.event
}
}, async () => {
const workerContext = await getWorkerContext(options)
let workerContext
try {
workerContext = await getWorkerContext(options)
} catch (err) {
if (err instanceof ConfigNotFoundError || err instanceof ConfigValidationError) {
// Skip worker callback as we cannot create a context. We also do not raise this error as this is part of
// normal behaviour.
return
} else {
throw err
}
}

await fn(workerContext)
})
}
Expand Down
21 changes: 11 additions & 10 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ it('not enough approval reviews', async () => {
})

it('no configuration should not schedule any pull request', async () => {
const schedulePullRequestTrigger = jest.fn()
jest.mock('../src/pull-request-handler', () => {
return {
schedulePullRequestTrigger: jest.fn()
schedulePullRequestTrigger
}
})

Expand All @@ -144,15 +145,15 @@ it('no configuration should not schedule any pull request', async () => {
github
})

expect(
app.receive(
createPullRequestOpenedEvent({
owner: 'bobvanderlinden',
repo: 'probot-auto-merge',
number: 1
})
)
).rejects.toHaveProperty('message', "Configuration file '.github/auto-merge.yml' not found")
app.receive(
createPullRequestOpenedEvent({
owner: 'bobvanderlinden',
repo: 'probot-auto-merge',
number: 1
})
)

expect(schedulePullRequestTrigger).toBeCalledTimes(0)
})

it('merges when receiving status event', async () => {
Expand Down

0 comments on commit d5f63fb

Please sign in to comment.