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

Restore compatiblity with junit-sql-storage #630

Merged
merged 1 commit into from
Jul 29, 2024
Merged
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
266 changes: 126 additions & 140 deletions src/main/java/hudson/tasks/junit/History.java

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions src/main/java/hudson/tasks/junit/HistoryTestResultSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import hudson.Util;
import hudson.model.Run;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.TestResult;

public class HistoryTestResultSummary {

Expand All @@ -11,21 +13,19 @@
private final int skipCount;
private final int passCount;
private final String description;
private final hudson.tasks.test.TestResult resultInRun;

public HistoryTestResultSummary(Run<?, ?> run, hudson.tasks.test.TestResult resultInRun,
public HistoryTestResultSummary(Run<?, ?> run,
Copy link
Member Author

Choose a reason for hiding this comment

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

this was the critical change, adding resultInRun broke the plugin and I can't see a way to retrieve it there. The API could be modified to maybe pass some more info down but it didn't seem necessary the only additional information that is missing now is the id of the test report which could be stored maybe if required

float duration, int failCount, int skipCount, int passCount) {
this(run, resultInRun, duration, failCount, skipCount, passCount, null);
this(run, duration, failCount, skipCount, passCount, null);

Check warning on line 19 in src/main/java/hudson/tasks/junit/HistoryTestResultSummary.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 19 is not covered by tests
}

public HistoryTestResultSummary(Run<?, ?> run, hudson.tasks.test.TestResult resultInRun, float duration, int failCount, int skipCount, int passCount, String description) {
public HistoryTestResultSummary(Run<?, ?> run, float duration, int failCount, int skipCount, int passCount, String description) {
this.run = run;
this.duration = duration;
this.failCount = failCount;
this.skipCount = skipCount;
this.passCount = passCount;
this.description = description;
this.resultInRun = resultInRun;
}

public String getDescription() {
Expand All @@ -36,6 +36,10 @@
return run;
}

public float getDuration() {
return duration;
}

public String getDurationString() {
return Util.getTimeSpanString((long) (duration * 1000));
}
Expand Down Expand Up @@ -65,10 +69,9 @@
}

public String getUrl() {
return resultInRun.getUrl();
}
AbstractTestResultAction<?> action = run.getAction(AbstractTestResultAction.class);

public hudson.tasks.test.TestResult getResultInRun() {
return resultInRun;
// TODO pass id to end of url

Check warning on line 74 in src/main/java/hudson/tasks/junit/HistoryTestResultSummary.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: pass id to end of url
return getRun().getUrl() + action.getUrlName() + "/";
}
}
7 changes: 4 additions & 3 deletions src/main/java/hudson/tasks/junit/TestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,11 @@ public int getFailCount() {
if (impl != null) {
return impl.getFailCount();
}
if(failedTests==null)
if(failedTests==null) {
return 0;
else
return failedTests.size();
} else {
return failedTests.size();
}
}

@Exported(visibility=999)
Expand Down
9 changes: 7 additions & 2 deletions src/main/resources/hudson/tasks/junit/History/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ function onBuildIntervalChange(selectObj) {
interval = dataEl.getAttribute("data-interval")
let trendChartJsonStr = dataEl.innerHTML
trendChartJson = JSON.parse(trendChartJsonStr)
appRootUrl = dataEl.getAttribute("data-appRootUrl")
const rootUrl = document.head.dataset.rooturl
if (!rootUrl.endsWith("/")) {
appRootUrl = `${rootUrl}/`
} else {
appRootUrl = rootUrl
}
testObjectUrl = dataEl.getAttribute("data-testObjectUrl")

trendChartJsonStr = null
Expand Down Expand Up @@ -390,7 +395,7 @@ function onBuildIntervalChange(selectObj) {
renderTrendChart(trendChartId, trendChartJson, trendConfigurationDialogId,
function (buildDisplayName) {
if (trendChartJson.buildMap[buildDisplayName]) {
window.open(rootUrl + trendChartJson.buildMap[buildDisplayName].url);
window.open(appRootUrl + trendChartJson.buildMap[buildDisplayName].url);
}
});
renderDistributionChart('test-distribution-chart', trendChartJson, trendConfigurationDialogId, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ THE SOFTWARE.
data-end="${end}"
data-count="${count}"
data-interval="${interval}"
data-appRootUrl="${app.rootUrl}"
data-testObjectUrl="${it.testObject.url}"
type="application/json"
>${historySummary.trendChartJson}</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public List<HistoryTestResultSummary> getHistorySummary(int offset) {
Job<?, ?> theJob = Jenkins.get().getItemByFullName(getJobName(), Job.class);
if (theJob != null) {
Run<?, ?> run = theJob.getBuildByNumber(buildNumber);
historyTestResultSummaries.add(new HistoryTestResultSummary(run, null, duration, failed, skipped, passed));
Copy link
Member Author

Choose a reason for hiding this comment

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

this shouldn't have had null passed as it made the test run but if any one actually tried to access the history view they got null pointers

historyTestResultSummaries.add(new HistoryTestResultSummary(run, duration, failed, skipped, passed));
}
}
return historyTestResultSummaries;
Expand Down