Skip to content

Commit

Permalink
fix(core): prevent GitHub API validation error by not sending empty a…
Browse files Browse the repository at this point in the history
…nnotation arrays
  • Loading branch information
error418 committed Oct 1, 2019
1 parent 0f672f9 commit 702ec02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/core/github/commit-status-sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CommitStatusSender {
}

private convertToCheckAnnotations(annotations: Swingletree.Annotation[]): ChecksCreateParamsOutputAnnotations[] {
return annotations.filter(i => i instanceof Swingletree.FileAnnotation)
const converted = annotations.filter(i => i instanceof Swingletree.FileAnnotation)
.map(annotation => {
const item = annotation as Swingletree.FileAnnotation;
return {
Expand All @@ -65,8 +65,14 @@ class CommitStatusSender {
annotation_level: this.convertSwingletreeSeverity(item.severity)
} as ChecksCreateParamsOutputAnnotations;
});

if (converted.length == 0) {
return undefined;
}

return converted;
}

public async sendAnalysisStatus(event: NotificationEvent) {

if (!(event.payload.source instanceof Swingletree.GithubSource)) {
Expand Down
11 changes: 10 additions & 1 deletion test/core/commit-status-sender.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ describe("Commit Status Sender", () => {
markdown: "123",
sender: "testSender",
source: source,
title: "test title"
title: "test title",
annotations: []
});
});

Expand All @@ -92,4 +93,12 @@ describe("Commit Status Sender", () => {
sinon.assert.calledOnce(githubClientMock.createCheckStatus);
});

it("should not set an empty annotation array in the CheckRun request", async () => {
githubClientMock.createCheckStatus.resolves();

const result = await uut.sendAnalysisStatus(mockEvent);

expect(result.output.annotations).to.be.undefined;
});

});

0 comments on commit 702ec02

Please sign in to comment.