-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISS-1378 Make pixee/upload-tool-results-action Sonar Host URL Consist…
…ent With Sonar Actions (#26) **Updated** * The input name was changed from sonar-api-url to sonar-host-url to be consistent with Sonar tools. * The action was updated to tolerate trailing slashes in the host URL. * Documentation and examples were updated. **Evidence** * https://github.com/JesusCotlamee/test-sonar-integration-with-app/actions/runs/9419565450/job/25949593733
- Loading branch information
1 parent
157c02a
commit c0d4409
Showing
8 changed files
with
245 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import * as github from "../src/github"; | ||
import { buildSonarUrl, SonarInputs } from "../src/sonar"; | ||
import { GitHubContext } from "../src/github"; | ||
|
||
let getGitHubContextMock: jest.SpiedFunction<typeof github.getGitHubContext>; | ||
|
||
describe("sonar", () => { | ||
const sonarHostUrl = "https://sonar.io/api"; | ||
const path = "api/issues/search"; | ||
const componentKey = "myComponent"; | ||
|
||
const sonarInputs = { | ||
token: "", | ||
sonarHostUrl, | ||
componentKey, | ||
} as SonarInputs; | ||
|
||
const githubContext = { | ||
owner: "owner", | ||
repo: "repo", | ||
sha: "sha", | ||
prNumber: 123, | ||
} as GitHubContext; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
getGitHubContextMock = jest | ||
.spyOn(github, "getGitHubContext") | ||
.mockImplementation(); | ||
}); | ||
|
||
it("should build the URL with pullRequest parameter if prNumber exists", async () => { | ||
getGitHubContextMock.mockReturnValue(githubContext); | ||
|
||
const result = buildSonarUrl({ | ||
sonarInputs, | ||
path, | ||
queryParamKey: "componentKeys", | ||
}); | ||
|
||
expect(result).toBe( | ||
"https://sonar.io/api/issues/search?componentKeys=myComponent&resolved=false&ps=500&pullRequest=123", | ||
); | ||
}); | ||
|
||
it("should build the URL without pullRequest parameter if prNumber does not exist", async () => { | ||
getGitHubContextMock.mockReturnValue({ | ||
owner: "owner", | ||
repo: "repo", | ||
sha: "sha", | ||
prNumber: undefined, | ||
}); | ||
|
||
const result = buildSonarUrl({ | ||
sonarInputs, | ||
path, | ||
queryParamKey: "componentKeys", | ||
}); | ||
|
||
expect(result).toBe( | ||
"https://sonar.io/api/issues/search?componentKeys=myComponent&resolved=false&ps=500", | ||
); | ||
}); | ||
|
||
it("should build the URL correctly with queryParamKey projectKey", async () => { | ||
getGitHubContextMock.mockReturnValue(githubContext); | ||
|
||
const result = buildSonarUrl({ | ||
sonarInputs, | ||
path, | ||
queryParamKey: "projectKey", | ||
}); | ||
|
||
expect(result).toBe( | ||
"https://sonar.io/api/issues/search?projectKey=myComponent&resolved=false&ps=500&pullRequest=123", | ||
); | ||
}); | ||
|
||
it("should encode the componentKey properly", async () => { | ||
const specialComponentKey = "myComponent with spaces"; | ||
getGitHubContextMock.mockReturnValue(githubContext); | ||
|
||
const sonarInputs = { | ||
token: "", | ||
sonarHostUrl, | ||
componentKey: specialComponentKey, | ||
} as SonarInputs; | ||
|
||
const result = buildSonarUrl({ | ||
sonarInputs, | ||
path, | ||
queryParamKey: "componentKeys", | ||
}); | ||
|
||
expect(result).toBe( | ||
"https://sonar.io/api/issues/search?componentKeys=myComponent+with+spaces&resolved=false&ps=500&pullRequest=123", | ||
); | ||
}); | ||
|
||
it("should handle sonarHost with trailing slash correctly", async () => { | ||
const sonarHostWithSlash = "https://sonar.io/"; | ||
getGitHubContextMock.mockReturnValue(githubContext); | ||
|
||
const sonarInputs = { | ||
token: "", | ||
sonarHostUrl: sonarHostWithSlash, | ||
componentKey, | ||
} as SonarInputs; | ||
|
||
const result = buildSonarUrl({ | ||
sonarInputs, | ||
path, | ||
queryParamKey: "componentKeys", | ||
}); | ||
|
||
expect(result).toBe( | ||
"https://sonar.io/api/issues/search?componentKeys=myComponent&resolved=false&ps=500&pullRequest=123", | ||
); | ||
}); | ||
|
||
it("should build the URL correctly with append the path correctly beyond /context/", async () => { | ||
const sonarHostWithContext = "https://sonar.io/context/"; | ||
|
||
getGitHubContextMock.mockReturnValue(githubContext); | ||
|
||
const sonarInputs = { | ||
token: "", | ||
sonarHostUrl: sonarHostWithContext, | ||
componentKey, | ||
} as SonarInputs; | ||
|
||
const result = buildSonarUrl({ | ||
sonarInputs, | ||
path, | ||
queryParamKey: "projectKey", | ||
}); | ||
|
||
expect(result).toBe( | ||
"https://sonar.io/context/api/issues/search?projectKey=myComponent&resolved=false&ps=500&pullRequest=123", | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.