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

Fix for issue #2 (Widget throws the error "bad status 400" following upgrade to SonarQube 6.4) #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions jobs/qg-filter/qg-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ function fetchListOfProjects(config, dependencies) {
if (err) {
reject(err);
} else if (!response) {
reject(new Error('Bad response'));
reject(new Error('Bad response from %s', options.url));
} else if (response.statusCode !== 200) {
reject(new Error(util.format('Bad status %s', response.statusCode)));
reject(new Error(util.format('Bad status %s from %s', response.statusCode, options.url)));
} else {
try {
const bodyObj = JSON.parse(body);
Expand Down Expand Up @@ -116,23 +116,23 @@ function fetchProjectsMeasures(config, dependencies, projects) {
function queryOneProject(resolve, reject, projectIndex) {
if (projectIndex < projects.length) {
const path = util.format(
'/api/measures/component_tree?baseComponentKey=%s' +
'/api/measures/component?componentKey=%s' +
'&metricKeys=quality_gate_details,alert_status,last_commit_date',
projects[projectIndex].k);
const options = computeRequestOptionsForSQ(config, path);
dependencies.request(options, function (err, response, body) {
if (err) {
reject(err)
reject(err);
} else if (!response) {
reject(new Error('Bad response'));
reject(new Error('Bad response from %s', options.url));
} else if (response.statusCode !== 200) {
reject(new Error(util.format('Bad status %s', response.statusCode)));
reject(new Error(util.format('Bad status %s from %s', response.statusCode, options.url)));
} else {
try {
const bodyObj = JSON.parse(body);

// enrich existing project object
projects[projectIndex].measures = bodyObj.baseComponent.measures;
projects[projectIndex].measures = bodyObj.component.measures;

// recursion
queryOneProject(resolve, reject, projectIndex + 1);
Expand Down
8 changes: 4 additions & 4 deletions jobs/qg-filter/test/test.job.qg-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ describe('qg-filter', function () {

// org.sonarsource.scm.cvs:sonar-scm-cvs-plugin
dependencies.bodyResponses.push(
"{\n\n \"paging\": {\n \"pageIndex\": 1,\n \"pageSize\": 100,\n \"total\": 0\n },\n \"baseComponent\": {\n \"id\": \"1d9c31e0-1ab6-4be5-bbda-e4c4b1592c1c\",\n \"key\": \"org.sonarsource.scm.cvs:sonar-scm-cvs-plugin\",\n \"name\": \"SonarQube :: Plugins :: SCM :: CVS\",\n \"description\": \"CVS SCM Provider.\",\n \"qualifier\": \"TRK\",\n \"measures\": [\n {\n \"metric\": \"quality_gate_details\",\n \"value\": \"{\\n \\\"level\\\": \\\"ERROR\\\",\\n \\\"conditions\\\": [\\n {\\n \\\"metric\\\": \\\"new_sqale_debt_ratio\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"\\\",\\n \\\"error\\\": \\\"5\\\",\\n \\\"actual\\\": \\\"0.0\\\",\\n \\\"level\\\": \\\"OK\\\"\\n },\\n {\\n \\\"metric\\\": \\\"reopened_issues\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"0\\\",\\n \\\"error\\\": \\\"\\\",\\n \\\"actual\\\": \\\"0\\\",\\n \\\"level\\\": \\\"OK\\\"\\n },\\n {\\n \\\"metric\\\": \\\"open_issues\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"0\\\",\\n \\\"error\\\": \\\"\\\",\\n \\\"actual\\\": \\\"9\\\",\\n \\\"level\\\": \\\"WARN\\\"\\n },\\n {\\n \\\"metric\\\": \\\"skipped_tests\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"0\\\",\\n \\\"error\\\": \\\"\\\",\\n \\\"actual\\\": \\\"0\\\",\\n \\\"level\\\": \\\"OK\\\"\\n },\\n {\\n \\\"metric\\\": \\\"new_bugs\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"\\\",\\n \\\"error\\\": \\\"1\\\",\\n \\\"actual\\\": \\\"1\\\",\\n \\\"level\\\": \\\"ERROR\\\"\\n },\\n {\\n \\\"metric\\\": \\\"new_vulnerabilities\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"\\\",\\n \\\"error\\\": \\\"0\\\",\\n \\\"actual\\\": \\\"0\\\",\\n \\\"level\\\": \\\"OK\\\"\\n }\\n ]\\n}\"\n },\n {\n \"metric\": \"last_commit_date\",\n \"value\": \"1464600985000\",\n \"comment\": \"2016-05-30T09:36:25Z\"\n },\n {\n \"metric\": \"alert_status\",\n \"value\": \"ERROR\"\n }\n ]\n },\n \"components\": [ ]\n\n}"
"{\n\n \"paging\": {\n \"pageIndex\": 1,\n \"pageSize\": 100,\n \"total\": 0\n },\n \"component\": {\n \"id\": \"1d9c31e0-1ab6-4be5-bbda-e4c4b1592c1c\",\n \"key\": \"org.sonarsource.scm.cvs:sonar-scm-cvs-plugin\",\n \"name\": \"SonarQube :: Plugins :: SCM :: CVS\",\n \"description\": \"CVS SCM Provider.\",\n \"qualifier\": \"TRK\",\n \"measures\": [\n {\n \"metric\": \"quality_gate_details\",\n \"value\": \"{\\n \\\"level\\\": \\\"ERROR\\\",\\n \\\"conditions\\\": [\\n {\\n \\\"metric\\\": \\\"new_sqale_debt_ratio\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"\\\",\\n \\\"error\\\": \\\"5\\\",\\n \\\"actual\\\": \\\"0.0\\\",\\n \\\"level\\\": \\\"OK\\\"\\n },\\n {\\n \\\"metric\\\": \\\"reopened_issues\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"0\\\",\\n \\\"error\\\": \\\"\\\",\\n \\\"actual\\\": \\\"0\\\",\\n \\\"level\\\": \\\"OK\\\"\\n },\\n {\\n \\\"metric\\\": \\\"open_issues\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"0\\\",\\n \\\"error\\\": \\\"\\\",\\n \\\"actual\\\": \\\"9\\\",\\n \\\"level\\\": \\\"WARN\\\"\\n },\\n {\\n \\\"metric\\\": \\\"skipped_tests\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"0\\\",\\n \\\"error\\\": \\\"\\\",\\n \\\"actual\\\": \\\"0\\\",\\n \\\"level\\\": \\\"OK\\\"\\n },\\n {\\n \\\"metric\\\": \\\"new_bugs\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"\\\",\\n \\\"error\\\": \\\"1\\\",\\n \\\"actual\\\": \\\"1\\\",\\n \\\"level\\\": \\\"ERROR\\\"\\n },\\n {\\n \\\"metric\\\": \\\"new_vulnerabilities\\\",\\n \\\"op\\\": \\\"GT\\\",\\n \\\"period\\\": 1,\\n \\\"warning\\\": \\\"\\\",\\n \\\"error\\\": \\\"0\\\",\\n \\\"actual\\\": \\\"0\\\",\\n \\\"level\\\": \\\"OK\\\"\\n }\\n ]\\n}\"\n },\n {\n \"metric\": \"last_commit_date\",\n \"value\": \"1464600985000\",\n \"comment\": \"2016-05-30T09:36:25Z\"\n },\n {\n \"metric\": \"alert_status\",\n \"value\": \"ERROR\"\n }\n ]\n },\n \"components\": [ ]\n\n}"
);
//sonar-packaging-maven-plugin
dependencies.bodyResponses.push(
util.format(
"{\n\n \"paging\": {\n \"pageIndex\": 1,\n \"pageSize\": 100,\n \"total\": 0\n },\n \"baseComponent\": {\n \"id\": \"AVBLzFBb5VDW_Ub0IDJv\",\n \"key\": \"org.sonarsource.sonar-packaging-maven-plugin:sonar-packaging-maven-plugin\",\n \"name\": \"SonarQube :: Packaging Maven Plugin\",\n \"description\": \"Parent pom of SonarSource public projects\",\n \"qualifier\": \"TRK\",\n \"measures\": [\n {\n \"metric\": \"last_commit_date\",\n \"value\": \"%s\" },\n {\n \"metric\": \"quality_gate_details\",\n \"value\": \"{\\\"level\\\":\\\"ERROR\\\",\\\"conditions\\\":[{\\\"metric\\\":\\\"new_coverage\\\",\\\"op\\\":\\\"LT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"85\\\",\\\"actual\\\":\\\"0.0\\\",\\\"level\\\":\\\"ERROR\\\"},{\\\"metric\\\":\\\"new_sqale_debt_ratio\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"5\\\",\\\"actual\\\":\\\"2.380952380952381\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"reopened_issues\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"open_issues\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"skipped_tests\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"new_bugs\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"0\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"new_vulnerabilities\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"0\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"}]}\"\n },\n {\n \"metric\": \"alert_status\",\n \"value\": \"ERROR\"\n }\n ]\n },\n \"components\": [ ]\n\n}",
"{\n\n \"paging\": {\n \"pageIndex\": 1,\n \"pageSize\": 100,\n \"total\": 0\n },\n \"component\": {\n \"id\": \"AVBLzFBb5VDW_Ub0IDJv\",\n \"key\": \"org.sonarsource.sonar-packaging-maven-plugin:sonar-packaging-maven-plugin\",\n \"name\": \"SonarQube :: Packaging Maven Plugin\",\n \"description\": \"Parent pom of SonarSource public projects\",\n \"qualifier\": \"TRK\",\n \"measures\": [\n {\n \"metric\": \"last_commit_date\",\n \"value\": \"%s\" },\n {\n \"metric\": \"quality_gate_details\",\n \"value\": \"{\\\"level\\\":\\\"ERROR\\\",\\\"conditions\\\":[{\\\"metric\\\":\\\"new_coverage\\\",\\\"op\\\":\\\"LT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"85\\\",\\\"actual\\\":\\\"0.0\\\",\\\"level\\\":\\\"ERROR\\\"},{\\\"metric\\\":\\\"new_sqale_debt_ratio\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"5\\\",\\\"actual\\\":\\\"2.380952380952381\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"reopened_issues\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"open_issues\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"skipped_tests\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"new_bugs\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"0\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"new_vulnerabilities\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"0\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"}]}\"\n },\n {\n \"metric\": \"alert_status\",\n \"value\": \"ERROR\"\n }\n ]\n },\n \"components\": [ ]\n\n}",
Date.now() - 30 * 1000 // 30 seconds ago
)
);
//burgr
dependencies.bodyResponses.push(
"{\n\n \"paging\": {\n \"pageIndex\": 1,\n \"pageSize\": 100,\n \"total\": 0\n },\n \"baseComponent\": {\n \"id\": \"AVKtK8s7wW7gmwRPbaVy\",\n \"key\": \"com.sonarsource.burgr:burgr\",\n \"name\": \"burgr\",\n \"description\": \"BUild Reports aGRegator\",\n \"qualifier\": \"TRK\",\n \"measures\": [\n {\n \"metric\": \"alert_status\",\n \"value\": \"OK\"\n },\n {\n \"metric\": \"last_commit_date\",\n \"value\": \"1467382075000\"\n },\n {\n \"metric\": \"quality_gate_details\",\n \"value\": \"{\\\"level\\\":\\\"OK\\\",\\\"conditions\\\":[{\\\"metric\\\":\\\"new_coverage\\\",\\\"op\\\":\\\"LT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"85\\\",\\\"actual\\\":\\\"\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"new_sqale_debt_ratio\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"5\\\",\\\"actual\\\":\\\"0.0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"reopened_issues\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"open_issues\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"skipped_tests\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"new_bugs\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"0\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"new_vulnerabilities\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"0\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"}]}\"\n }\n ]\n },\n \"components\": [ ]\n\n}"
"{\n\n \"paging\": {\n \"pageIndex\": 1,\n \"pageSize\": 100,\n \"total\": 0\n },\n \"component\": {\n \"id\": \"AVKtK8s7wW7gmwRPbaVy\",\n \"key\": \"com.sonarsource.burgr:burgr\",\n \"name\": \"burgr\",\n \"description\": \"BUild Reports aGRegator\",\n \"qualifier\": \"TRK\",\n \"measures\": [\n {\n \"metric\": \"alert_status\",\n \"value\": \"OK\"\n },\n {\n \"metric\": \"last_commit_date\",\n \"value\": \"1467382075000\"\n },\n {\n \"metric\": \"quality_gate_details\",\n \"value\": \"{\\\"level\\\":\\\"OK\\\",\\\"conditions\\\":[{\\\"metric\\\":\\\"new_coverage\\\",\\\"op\\\":\\\"LT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"85\\\",\\\"actual\\\":\\\"\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"new_sqale_debt_ratio\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"5\\\",\\\"actual\\\":\\\"0.0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"reopened_issues\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"open_issues\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"skipped_tests\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"0\\\",\\\"error\\\":\\\"\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"new_bugs\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"0\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"},{\\\"metric\\\":\\\"new_vulnerabilities\\\",\\\"op\\\":\\\"GT\\\",\\\"period\\\":1,\\\"warning\\\":\\\"\\\",\\\"error\\\":\\\"0\\\",\\\"actual\\\":\\\"0\\\",\\\"level\\\":\\\"OK\\\"}]}\"\n }\n ]\n },\n \"components\": [ ]\n\n}"
);
// list of projects
dependencies.bodyResponses.push(
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('qg-filter', function () {

qgFilter.onRun(config, dependencies, function job_callback (errMsg, data) {

assert.strictEqual(errMsg, 'Bad status 500');
assert.strictEqual(errMsg, 'Bad status 500 from http://sonarqube.hogwarts.edu/api/projects/index?format=json');
assert.strictEqual(typeof data, 'undefined');
done();
});
Expand Down