Skip to content
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

[suricate] update sonar project metrics and new project coverage #45

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
19 changes: 19 additions & 0 deletions content/sonar/widgets/project-coverage/content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="grid-stack-item-content-inner">
<a href="{{sonarConfigUrl}}/portfolio?id={{SURI_PROJECT_KEY}}" target="_blank">
<div class="fullwidget">
<div class="grid-stack-item-content-inner">
<h1 class="title">{{SURI_TITLE}}</h1>
<ul>
{{#results}}
<li>
<span class="label">{{title}}</span>
<span class="value">{{value}}</span>
</li>
{{/results}}
</ul>
<i class="fa fa-heartbeat icon-background"></i>
</div>
</div>
</a>
</div>
<div class="sonarqube"></div>
4 changes: 4 additions & 0 deletions content/sonar/widgets/project-coverage/description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: Metrics
description: Display the selected Sonar metrics of a new code in an application
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New widget is only related to coverage, right? If yes, update the description so it specifies it only display Sonar coverage metrics

technicalName: sonar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical name should be more precise (and unique), something like sonarProjectCoverage

delay: 500
Copy link
Contributor

@loicgreffier loicgreffier Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the image of the project-coverage widget itself, not the metrics widget

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions content/sonar/widgets/project-coverage/params.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
widgetParams:
-
name: 'SURI_TITLE'
description: 'Widget title'
type: TEXT
usageExample: 'My title'
required: true
-
name: 'SURI_PROJECT_KEY'
description: 'Project key'
type: TEXT
usageExample: 'com.project.key:ProjectName'
required: true
-
name: 'SURI_METRICS'
description: 'Metrics to display'
type: MULTIPLE
possibleValuesMap:
-
jsKey: 'new_line_coverage'
value: 'Lines of code'
-
jsKey: 'new_lines_to_cover'
value: 'Lines to Cover'
-
jsKey: 'new_uncovered_lines'
value: 'Uncovered Lines'
-
jsKey: 'new_coverage'
value: 'Coverage on New Code(%)'
-
jsKey: 'new_conditions_to_cover'
value: 'Conditions to Cover'
-
jsKey: 'new_uncovered_conditions'
value: 'Unconver conditions'
required: true
-
name: 'SURI_BRANCH'
description: 'Branch name, if user provides both branch and pull request, the branch takes precedence.'
type: TEXT
usageExample: 'My branch'
required: false
-
name: 'SURI_PULL_REQUEST'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation should be fixed (I know it is not fixed in every widget)

description: 'Merge/Pull Request Number'
type: TEXT
usageExample: '111'
required: false
48 changes: 48 additions & 0 deletions content/sonar/widgets/project-coverage/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

function run() {
var data = {};
var branch = (SURI_BRANCH != null ? "branch="
+ SURI_BRANCH + "&" : (SURI_PULL_REQUEST != null ? "pullRequest=" + SURI_PULL_REQUEST + "&" : ""));
data.results = [];

// added to remove the trailing slash from the URL if present
data.sonarConfigUrl = (WIDGET_CONFIG_SONAR_URL) ? WIDGET_CONFIG_SONAR_URL.replace(/\/+$/, '') : WIDGET_CONFIG_SONAR_URL;

var response = JSON.parse(
Packages.get(data.sonarConfigUrl + "/api/measures/component?" + branch
+"component=" + SURI_PROJECT_KEY + "&additionalFields=metrics&metricKeys=" + SURI_METRICS,
"Authorization", "Basic " + Packages.btoa(WIDGET_CONFIG_SONAR_TOKEN + ":")));


if (response && response.component && response.component.measures && response.component.measures.length > 0) {
response.component.measures.forEach(function(measure) {
data.results.push({
title: response.metrics.filter(function(metric) {
if (metric.key == measure.metric) {
return metric;
}
})[0].name,
value:measure.period.value,

});
});

}

return JSON.stringify(data);
}
57 changes: 57 additions & 0 deletions content/sonar/widgets/project-coverage/style.css

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions content/sonar/widgets/project-metrics/params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ widgetParams:
-
jsKey: 'sqale_index'
value: 'Technical debt (total effort (in hours) to fix all the issues)'
-
jsKey: 'coverage'
value: 'Coverage (%)'
-
jsKey: 'blocker_violations'
value: 'Number of issues with blocker severity'
Expand Down
Loading