Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ class Settings {
})
})

// A nop run triggered outside the webhook flow (e.g. the full-sync entrypoint)
// has no check run or repository in its payload, so there is nowhere to post
// the results other than the log.
Comment thread
tdabasinskas marked this conversation as resolved.
Outdated
if (!payload?.check_run) {
this.log.info(`Dry-run results:\n${JSON.stringify(this.results, null, 2)}`)
return
}
Comment thread
tdabasinskas marked this conversation as resolved.
Outdated
Comment thread
tdabasinskas marked this conversation as resolved.
Comment thread
tdabasinskas marked this conversation as resolved.

let error = false
// Different logic
const stats = {
Expand Down
44 changes: 44 additions & 0 deletions test/unit/lib/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,48 @@ repository:
expect(mockRepoSync).toHaveBeenCalledTimes(1)
})
}) // updateRepos - archived repo skipping

describe('handleResults', () => {
let settings

beforeEach(() => {
stubContext.octokit.rest.checks = { update: jest.fn().mockResolvedValue({}) }
stubContext.octokit.rest.issues = { createComment: jest.fn().mockResolvedValue({}) }
settings = new Settings(true, stubContext, mockRepo, {}, mockRef)
settings.results = [
{
type: 'INFO',
plugin: 'Branches',
repo: 'test/test-repo',
endpoint: '',
body: '',
action: { msg: 'Changes found', additions: {}, modifications: { branch: {} }, deletions: {} }
}
]
})

describe('in nop mode without a check run in the payload (full sync)', () => {
it('logs the results instead of updating a check run', async () => {
// stubContext.payload only contains `installation`, like a full-sync context
await settings.handleResults()

expect(stubContext.log.info).toHaveBeenCalledWith(expect.stringContaining('Changes found'))
expect(stubContext.octokit.rest.checks.update).not.toHaveBeenCalled()
})
})

describe('in nop mode with a check run in the payload (webhook flow)', () => {
it('completes the check run', async () => {
stubContext.payload.check_run = { id: 42, check_suite: { pull_requests: [{ number: 1 }] } }
stubContext.payload.repository = { owner: { login: 'test' }, name: 'test-repo' }

await settings.handleResults()

expect(stubContext.octokit.rest.checks.update).toHaveBeenCalledWith(expect.objectContaining({
check_run_id: 42,
status: 'completed'
}))
})
})
}) // handleResults
}) // Settings Tests