Skip to content

Commit 5523bdc

Browse files
authored
Merge pull request #308 from jenkinsci/clickable-chart
Open commit repository URL on click in trend chart
2 parents 63153c7 + 8d6c50a commit 5523bdc

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<data-tables-api.version>1.10.25-3</data-tables-api.version>
3232
<jquery3-api.version>3.6.0-2</jquery3-api.version>
3333
<font-awesome-api.version>5.15.3-4</font-awesome-api.version>
34-
<echarts-api.version>5.1.2-3</echarts-api.version>
34+
<echarts-api.version>5.1.2-4</echarts-api.version>
3535
<bootstrap5-api.version>5.0.2-1</bootstrap5-api.version>
3636

3737
</properties>

src/main/java/io/jenkins/plugins/forensics/miner/FileDetailsView.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ public LinesChartModel createChartModel() {
8585
return new FileChurnTrendChart().create(fileStatistics, decorator);
8686
}
8787

88+
/**
89+
* Returns the repository URL for the specified commit.
90+
*
91+
* @param commit
92+
* the commit to get the URL for
93+
*
94+
* @return the repository URL
95+
*/
96+
@JavaScriptMethod
97+
@SuppressWarnings("unused") // Called by jelly view
98+
public String getCommitUrl(final String commit) {
99+
return decorator.getRawLink(commit);
100+
}
101+
88102
@JavaScriptMethod
89103
@SuppressWarnings("unused") // Called by jelly view
90104
@Override
@@ -182,6 +196,7 @@ public LinesChartModel create(final FileStatistics fileStatistics,
182196
LinesDataSet dataSet = createDataSetPerCommit(fileStatistics, decorator);
183197

184198
LinesChartModel model = new LinesChartModel(dataSet);
199+
model.setDomainAxisItemName("Commit");
185200
LineSeries added = new LineSeries(Messages.TrendChart_Churn_Legend_Added(), Palette.GREEN.getNormal(),
186201
StackedMode.SEPARATE_LINES, FilledMode.FILLED);
187202
added.addAll(dataSet.getSeries(ADDED_KEY));

src/main/java/io/jenkins/plugins/forensics/util/CommitDecorator.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.jenkins.plugins.forensics.util;
22

3+
import org.apache.commons.lang3.StringUtils;
4+
35
import hudson.scm.RepositoryBrowser;
46

57
/**
@@ -21,12 +23,26 @@ public abstract class CommitDecorator {
2123
public abstract String asLink(String id);
2224

2325
/**
24-
* Renders the commit ID as a human readable text.
26+
* Returns the raw link for the specified commit ID.
27+
*
28+
* @param id
29+
* the ID of the commit
30+
*
31+
* @return a raw link to the commit, e.g. https://github.com/jenkinsci/analysis-model/commit/9f5eb8b28e422d6249e6c29dc65173a59f2d9f6f
32+
*/
33+
public String getRawLink(final String id) {
34+
return StringUtils.defaultString(
35+
StringUtils.substringBetween(asLink(id), "href=\"", "\""),
36+
id);
37+
}
38+
39+
/**
40+
* Renders the commit ID as a human-readable text.
2541
*
2642
* @param id
2743
* the ID of the commit
2844
*
29-
* @return a commit ID as human readable text
45+
* @return a commit ID as human-readable text
3046
*/
3147
public String asText(final String id) {
3248
return id;

src/main/resources/io/jenkins/plugins/forensics/miner/FileDetailsView/index.jelly

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,17 @@
3636

3737
<script>
3838
{
39-
const trendProxy = <st:bind value="${it}"/>;
40-
trendProxy.getBuildTrendModel(function (lineModel) {
41-
echartsJenkinsApi.renderConfigurableZoomableTrendChart('churn-trend-chart', lineModel.responseJSON);
42-
});
39+
const trendProxy = <st:bind value="${it}"/>;
40+
trendProxy.getBuildTrendModel(function (lineModel) {
41+
const openCommit = function (commit) {
42+
trendProxy.getCommitUrl(commit, function (commitUrl) {
43+
if (commitUrl.responseJSON.startsWith('http')) {
44+
window.location.assign(commitUrl.responseJSON);
45+
}
46+
});
47+
};
48+
echartsJenkinsApi.renderConfigurableZoomableTrendChart('churn-trend-chart', lineModel.responseJSON, null, openCommit);
49+
});
4350
}
4451
</script>
4552
</bs:page>

0 commit comments

Comments
 (0)