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

Commit

Permalink
Revert "Use check suite API to check if all checks passed (#84)" (#85)
Browse files Browse the repository at this point in the history
This reverts commit 4d1d6d3.
  • Loading branch information
Puneeth-n authored May 26, 2021
1 parent 4d1d6d3 commit 38ea1be
Show file tree
Hide file tree
Showing 12 changed files with 574 additions and 3,841 deletions.

This file was deleted.

719 changes: 137 additions & 582 deletions __tests__/fixtures/list_check_runs_for_ref_complete.json

Large diffs are not rendered by default.

818 changes: 0 additions & 818 deletions __tests__/fixtures/list_check_runs_for_ref_failed.json

This file was deleted.

818 changes: 0 additions & 818 deletions __tests__/fixtures/list_check_runs_for_ref_in_progress.json

This file was deleted.

1,185 changes: 370 additions & 815 deletions __tests__/fixtures/list_check_runs_for_ref_skipped.json

Large diffs are not rendered by default.

65 changes: 17 additions & 48 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import * as apiGatewayEvent from './fixtures/api_gateway_event.json'
import * as apiGatewayEventActionNotComplete from './fixtures/api_gateway_event_action_not_complete.json'
import * as apiGatewayEventCheckSuiteCancelledEvent from './fixtures/api_gateway_event_check_suite_cancelled.json'
import * as apiGatewayEventCheckSuiteCompletedEvent from './fixtures/api_gateway_event_complete.json'
import * as listCheckSuitesForRefResponse from './fixtures/list_check_runs_for_ref_complete.json'
import * as listCheckSuitesForRefSkippedResponse from './fixtures/list_check_runs_for_ref_skipped.json'
import * as listCheckSuitesForRefInProgressResponse from './fixtures/list_check_runs_for_ref_in_progress.json'
import * as listCheckSuitesForRefFailedResponse from './fixtures/list_check_runs_for_ref_failed.json'
import * as listCheckSuitesForRefAllChecksIgnoredResponse from './fixtures/list_check_runs_for_ref_all_check_suites_ignored.json'
import * as listCheckRunsForRefResponse from './fixtures/list_check_runs_for_ref_complete.json'
import * as listCheckRunsForRefSkippedResponse from './fixtures/list_check_runs_for_ref_skipped.json'

describe('Handler', () => {
let sandbox: sinon.SinonSandbox
Expand All @@ -26,16 +23,14 @@ describe('Handler', () => {
beforeEach(() => {
process.env.AWS_REGION = 'eu-west-1'
process.env.AWS_DEFAULT_REGION = 'eu-west-1'
process.env.IGNORE_CHECKS =
"SonarCloud,Comtravo Jenkins App,Comtravo's New Jenkins,Dependabot"
sandbox = sinon.createSandbox()

sandbox.stub(AWS, 'SSM')

createCommitStatusStub = sandbox.stub()
octokitStub = sandbox.stub(octokit, 'Octokit').returns({
checks: {
listSuitesForRef: () => listCheckSuitesForRefResponse
listForRef: () => listCheckRunsForRefResponse
},
repos: {
createCommitStatus: createCommitStatusStub
Expand Down Expand Up @@ -157,15 +152,6 @@ describe('Handler', () => {
})

test('should handle the webhook event gracefully when some checks have failed', async () => {
octokitStub.returns({
checks: {
listSuitesForRef: () => listCheckSuitesForRefFailedResponse
},
repos: {
createCommitStatus: createCommitStatusStub
}
})

await expect(
index.handler(apiGatewayEventCheckSuiteCompletedEvent)
).resolves.toEqual(
Expand All @@ -188,6 +174,8 @@ describe('Handler', () => {
})

test('should handle the webhook event gracefully when checks have passed excluding ignored checks', async () => {
process.env.IGNORE_CHECKS =
'SonarCloud Code Analysis,SOME other test_ignore'
await expect(
index.handler(apiGatewayEventCheckSuiteCompletedEvent)
).resolves.toEqual(
Expand All @@ -210,9 +198,12 @@ describe('Handler', () => {
})

test('should handle the webhook event gracefully when some checks have passed and some skipped', async () => {
process.env.IGNORE_CHECKS =
'SonarCloud Code Analysis,SOME other test_ignore'

octokitStub.returns({
checks: {
listSuitesForRef: () => listCheckSuitesForRefSkippedResponse
listForRef: () => listCheckRunsForRefSkippedResponse
},
repos: {
createCommitStatus: createCommitStatusStub
Expand Down Expand Up @@ -240,41 +231,19 @@ describe('Handler', () => {
).toEqual(true)
})

test('should handle the webhook event gracefully when all check suites have been ignored', async () => {
octokitStub.returns({
checks: {
listSuitesForRef: () => listCheckSuitesForRefAllChecksIgnoredResponse
},
repos: {
createCommitStatus: createCommitStatusStub
}
})
test('should handle the webhook event gracefully when some checks are pending excluding ignored checks', async () => {
process.env.IGNORE_CHECKS =
'SonarCloud Code Analysis,SOME other test_ignore'

await expect(
index.handler(apiGatewayEventCheckSuiteCompletedEvent)
).resolves.toEqual(
expect.objectContaining({
statusCode: 201,
body: expect.stringMatching(/Event handled successfully/)
})
const listCheckRunsForRefChecksPendingResponse = cloneDeep(
listCheckRunsForRefResponse
)
listCheckRunsForRefChecksPendingResponse.data.check_runs[1].status =
'in_progress'

expect(createCommitStatusStub.callCount).toEqual(1)
expect(
createCommitStatusStub.calledOnceWith({
owner: 'comtravo',
repo: 'ct-backend',
sha: 'aae3c1283d8b21ccd0a04a9ad0b384b77fa9bc7e',
state: 'success',
context: 'all-checks-passed'
})
).toEqual(true)
})

test('should handle the webhook event gracefully when some checks are in_progress excluding ignored checks', async () => {
octokitStub.returns({
checks: {
listSuitesForRef: () => listCheckSuitesForRefInProgressResponse
listForRef: () => listCheckRunsForRefChecksPendingResponse
},
repos: {
createCommitStatus: createCommitStatusStub
Expand Down
109 changes: 20 additions & 89 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"@octokit/core": "^3.3.1",
"@octokit/rest": "^18.5.3",
"@octokit/rest": "^18.3.5",
"@octokit/webhooks": "^8.5.3",
"aws-sdk": "^2.873.0",
"crypto": "^1.0.1",
"pino": "^6.11.2",
"ssm-parameter-store": "^2.1.2"
},
"devDependencies": {
"@octokit/types": "^6.14.2",
"@octokit/types": "^6.12.2",
"@types/aws-lambda": "^8.10.72",
"@types/jest": "^26.0.21",
"@types/lodash": "^4.14.168",
Expand Down
Loading

0 comments on commit 38ea1be

Please sign in to comment.