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

Add delta forensics for PR and branch builds #293

Merged
merged 7 commits into from
Jul 4, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package io.jenkins.plugins.forensics.miner;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import hudson.model.Action;
import hudson.model.InvisibleAction;
import hudson.model.Run;
import jenkins.model.RunAction2;
import jenkins.tasks.SimpleBuildStep.LastBuildAction;

import io.jenkins.plugins.forensics.reference.ReferenceBuild;

/**
* Controls the life cycle of the commit statistics in a job. This action persists the results of a build and displays a
* summary on the build page. The actual visualization of the results is defined in the matching {@code summary.jelly}
* file.
*
* @author Ullrich Hafner
*/
@SuppressWarnings("PMD.DataClass")
public class CommitStatisticsBuildAction extends InvisibleAction implements LastBuildAction, RunAction2, Serializable {
private static final long serialVersionUID = -263122257268060032L;

@SuppressFBWarnings(value = "SE", justification = "transient field owner ist restored using a Jenkins callback")
private transient Run<?, ?> owner;

private final String scmKey;
private final CommitStatistics commitStatistics;

/**
* Creates a new instance of {@link CommitStatisticsBuildAction}.
*
* @param owner
* the associated build that created the statistics
* @param scmKey
* key of the repository
* @param commitStatistics
* the statistics to persist with this action
*/
public CommitStatisticsBuildAction(final Run<?, ?> owner,
final String scmKey, final CommitStatistics commitStatistics) {
super();

this.owner = owner;
this.scmKey = scmKey;
this.commitStatistics = commitStatistics;
}

public Run<?, ?> getOwner() {
return owner;
}

public String getScmKey() {
return scmKey;
}

public CommitStatistics getCommitStatistics() {
return commitStatistics;
}

@CheckForNull
public ReferenceBuild getReferenceBuild() {
return getOwner().getAction(ReferenceBuild.class);
}

@Override
public String toString() {
return String.format("%s [%s]", scmKey, commitStatistics);
}

@Override
public void onAttached(final Run<?, ?> run) {
owner = run;
}

@Override
public void onLoad(final Run<?, ?> run) {
owner = run;
}

@Override
public Collection<? extends Action> getProjectActions() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@
import io.jenkins.plugins.util.BuildAction;

/**
* Controls the live cycle of the forensics results in a job. This action persists the results of a build and displays a
* Controls the life cycle of the forensics results in a job. This action persists the results of a build and displays a
* summary on the build page. The actual visualization of the results is defined in the matching {@code summary.jelly}
* file. This action also provides access to the forensics details: these are rendered using a new view instance.
*
* @author Ullrich Hafner
*/
@SuppressWarnings("PMD.DataClass")
public class ForensicsBuildAction extends BuildAction<RepositoryStatistics> implements StaplerProxy {
private static final long serialVersionUID = -263122257268060032L;
private static final String DEFAULT_FILE_NAME = "repository-statistics.xml";

private final int numberOfFiles;
private final int miningDurationSeconds;
private final String urlName;

private String scmKey; // since 0.9.0
private String fileName; // since 0.9.0

private final int numberOfFiles;
private final int totalLinesOfCode; // since 1.1.0
private final int totalChurn; // since 1.1.0
private CommitStatistics commitStatistics; // since 1.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
* <li>total number of different authors</li>
* <li>creation time</li>
* <li>last modification time</li>
* <li>lines of code (from the commit details)</li>
* <li>code churn (changed lines since created)</li>
* </ul>
* Stores the created statistics in a {@link RepositoryStatistics} instance. The result is attached to
* a {@link Run} by registering a {@link ForensicsBuildAction}.
Expand All @@ -62,6 +64,7 @@ public RepositoryMinerStep() {
*
* @return this
*/
@SuppressWarnings("unused")
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "Deserialization of instances that do not have all fields yet")
protected Object readResolve() {
if (scm == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:t="/lib/hudson">

<t:summary icon="/plugin/forensics-api/icons/diff-stat-48x48.png">
${%title}: ${it.scmKey}
<j:set var="s" value="${it.commitStatistics}"/>
<ul>
<li>
Commits: ${s.commitCount} -
<j:choose>
<j:when test="${it.referenceBuild != null}">
compared to target branch of build <j:out value="${it.referenceBuild.referenceLink}"/>
</j:when>
compared to previous build
</j:choose>
</li>
<li>
Changed files: ${s.filesCount}
</li>
<li>
Changed lines: ${s.addedLines} added, ${s.deletedLines} deleted
</li>
</ul>
</t:summary>

</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title=Commit Diff Statistics
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
New commits: ${s.commitCount} (from ${s.authorCount} authors in ${s.filesCount} files)
</li>
<li>
New added lines: ${s.addedLines}
</li>
<li>
New deleted lines: ${s.deletedLines}
Changed lines: ${s.addedLines} added, ${s.deletedLines} deleted
</li>
<li>
Miner runtime: ${it.miningDurationSeconds} seconds
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/icons/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
License for FontAwesome icon: CC BY 4.0 License
License for FontAwesome icons: CC BY 4.0 License
https://fontawesome.com/license/free


Binary file added src/main/webapp/icons/diff-stat-24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/icons/diff-stat-48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/test/resources/design.puml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ skinparam component {

[Blamer] --> [Utilities]
[Miner] --> [Utilities]
[Miner] -> [Reference Recorder]
[Reference Recorder] --> [Utilities]

@enduml