-
Notifications
You must be signed in to change notification settings - Fork 2
SonarQube issues plugin #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
4c4eaf6
to
80a8988
Compare
…ex-plugins into sonarqube-issues
…'s launching of prettier and the branch-wide prettier
…ex-plugins into sonarqube-issues
`${context.apiBaseUrl}/catalog/sonarqube-plugin-config/openapi` | ||
); | ||
const data = await response.json(); | ||
newBaseUrl = data.info["x-cortex-definition"]["sonarqube-url"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is slightly bugged, we should be pulling newBaseUrl as an optional value before attempting the fetch. I am running SonarQube locally and exposing a URL with ngrok, and I noticed that when I use a custom URL (check out my config in the justinreock-sandbox tenant), the service never actually gets hit. That's because if the endpoint isn't sonarcloud.io and since you are using await, the exception will trigger on the event loop before newBaseUrl has a chance to populate. I tested by adding some console logging:
newBaseUrl = data.info["x-cortex-definition"]["sonarqube-url"]; console.log("Switching to updated URL" + newBaseUrl); } catch (e) {} setBaseUrl(newBaseUrl); console.error("Trying new base URL" + newBaseUrl);
And you can see in the console that the variable is undefined:

Despite the plugin configured as:

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the key in your entity is named wrong; it should be sonarqube-url
not sonarqube-api-url
so in this case your service should not get hit and the plugin should try to use https://sonarcloud.io.
That said, we should not be trying to set baseUrl to undefined ever... I'll fix that, let me know if there is another bug here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am thinking to do like this
useEffect(() => {
if (!context?.apiBaseUrl) {
return;
}
const fetchPluginConfig = async (): Promise<void> => {
console.log("Fetching plugin config");
let newBaseUrl = "https://sonarcloud.io";
try {
const response = await fetch(
`${context.apiBaseUrl}/catalog/sonarqube-plugin-config/openapi`
);
const data = await response.json();
const baseUrlFromEntity = data.info["x-cortex-definition"]["sonarqube-url"];
console.log("baseUrlFromEntity is ", baseUrlFromEntity);
if (baseUrlFromEntity) {
newBaseUrl = baseUrlFromEntity;
}
} catch (e) {
console.log("Failed to fetch plugin config", e);
}
console.log("Setting base url to ", newBaseUrl);
setBaseUrl(newBaseUrl);
};
void fetchPluginConfig();
}, [context?.apiBaseUrl]);
so that if the plugin-config can't be fetched, I get
if the plugin-config exists but doesn't have the key (your situation) I get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Testing this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugins/sonarqube-issues/README.md
Outdated
x-cortex-tag: sonarqube-plugin-config | ||
x-cortex-type: plugin-configuration | ||
x-cortex-definition: | ||
sonarqube-api-url: https://sonarqube.martindstone.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more tweak and then I'm good to sign off! At the beginning, the README specifies:
If the cortex.yaml has a SonarQube Project defined in its x-cortex-static-analysis configuration, it will query for issues pertaining to that project. For example:
And the example shows:
openapi: 3.0.1 info: title: Funrepo description: it is a fun repo x-cortex-git: github: alias: cortex repository: martindstone-org/funrepo x-cortex-tag: funrepo x-cortex-type: service x-cortex-static-analysis: sonarqube: **project: martindstone-org_funrepo
**
I think we need to call out specifically that the value in x-cortex-static-analysis.sonarqube.project needs to specifically match the project key in SonarQube and not the project name. That tripped me up once I got the authentication working, I started using the project name and it just wasn't retrieving issues, switched to project key and it works like a charm!!


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the quick turnaround on all the changes @martindstone !!
Background
This is a simple plugin to show SonarQube issues in Cortex
This PR
This PR adds the SonarQube issues plugin
Checklists
Security