Skip to content

Commit

Permalink
Updating sonar github action to also retrieve and upload hotspots (#11)
Browse files Browse the repository at this point in the history
Related issue:
#7 and
#10

![Screenshot 2024-05-07 at 11 45 09 a
m](https://github.com/pixee/upload-tool-results-action/assets/14047435/d6b5d103-9967-4c32-a39f-3ab20c8cb8d2)

---------

Co-authored-by: Daniel D'Avella <dan.davella@pixee.ai>
  • Loading branch information
carlosu7 and drdavella committed May 10, 2024
1 parent 20825a3 commit 244efe4
Show file tree
Hide file tree
Showing 7 changed files with 39,382 additions and 49 deletions.
32 changes: 24 additions & 8 deletions __tests__/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ let getInputMock: jest.SpiedFunction<typeof core.getInput>;
let getGitHubContextMock: jest.SpiedFunction<typeof github.getGitHubContext>;
let getTempDir: jest.SpiedFunction<typeof github.getTempDir>;
let uploadInputFileMock: jest.SpiedFunction<typeof pixee.uploadInputFile>;
let retrieveSonarCloudResultsMock: jest.SpiedFunction<
typeof sonar.retrieveSonarCloudResults
let retrieveSonarCloudIssuesMock: jest.SpiedFunction<
typeof sonar.retrieveSonarCloudIssues
>;
let retrieveSonarCloudHotspotsMock: jest.SpiedFunction<
typeof sonar.retrieveSonarCloudHotspots
>;
let triggerPrAnalysisMock: jest.SpiedFunction<typeof pixee.triggerPrAnalysis>;
let getRepositoryInfoMock: jest.SpiedFunction<typeof github.getRepositoryInfo>;
Expand All @@ -32,13 +35,17 @@ describe("action", () => {
triggerPrAnalysisMock = jest
.spyOn(pixee, "triggerPrAnalysis")
.mockImplementation();
retrieveSonarCloudResultsMock = jest
.spyOn(sonar, "retrieveSonarCloudResults")
retrieveSonarCloudIssuesMock = jest
.spyOn(sonar, "retrieveSonarCloudIssues")
.mockImplementation();
retrieveSonarCloudHotspotsMock = jest
.spyOn(sonar, "retrieveSonarCloudHotspots")
.mockImplementation();
getRepositoryInfoMock = jest
.spyOn(github, "getRepositoryInfo")
.mockImplementation();
retrieveSonarCloudResultsMock.mockResolvedValue({ total: 1 });
retrieveSonarCloudIssuesMock.mockResolvedValue({ total: 1 });
retrieveSonarCloudHotspotsMock.mockResolvedValue({ paging: {total: 1} });
});

it("triggers PR analysis when the PR number is available", async () => {
Expand All @@ -58,6 +65,10 @@ describe("action", () => {
return "";
}
});
getRepositoryInfoMock.mockReturnValue({
owner: "owner",
repo: "repo"
});
triggerPrAnalysisMock.mockResolvedValue(undefined);

await run();
Expand All @@ -82,10 +93,14 @@ describe("action", () => {
repo: "repo",
sha: "sha",
});
getRepositoryInfoMock.mockReturnValue({
owner: "owner",
repo: "repo"
});

await run();

expect(uploadInputFileMock).toHaveBeenCalledWith("sonar", "file.json");
expect(uploadInputFileMock).toHaveBeenCalledWith("sonar_issues", "file.json");
});
});

Expand Down Expand Up @@ -131,9 +146,10 @@ describe("action", () => {

await run();

expect(retrieveSonarCloudResultsMock).toHaveBeenCalled();
expect(retrieveSonarCloudIssuesMock).toHaveBeenCalled();
expect(retrieveSonarCloudHotspotsMock).toHaveBeenCalled();
expect(uploadInputFileMock).toHaveBeenCalledWith(
"sonar",
"sonar_issues",
expect.stringMatching(/sonar-issues.json$/)
);
});
Expand Down
4 changes: 2 additions & 2 deletions __tests__/pixee-platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe("pixee-platform", () => {
// mock axios.put to avoid making a real HTTP request
jest.spyOn(axios, "put").mockResolvedValue(undefined);

await uploadInputFile("sonar", file.name);
await uploadInputFile("sonar_issues", file.name);

expect(axios.put).toHaveBeenCalledWith(
"https://api.pixee.ai/analysis-input/owner/repo/sha/sonar",
"https://api.pixee.ai/analysis-input/owner/repo/sha/sonar_issues",
expect.anything(), // cannot assert the form content
{
headers: {
Expand Down
Loading

0 comments on commit 244efe4

Please sign in to comment.