Skip to content

Commit

Permalink
Merge 2492218 into 085ca7c
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsymhoven committed Jul 21, 2021
2 parents 085ca7c + 2492218 commit 9d86952
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 54 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,17 @@ and the dashboard tries to load this portlet, an alert will be displayed with th
Under the settings of each `Run`, various things can be tracked:

1. Are there changes of the pre-defined dashboard since the last build?

2. The current activated source of configuration (Default or User-specific).
* Default means Jenkinsfile if `monitoring` is provided, else all <a href="#available-portlets">available default portlets</a>.
* User-specific means the local changes of dashboard.
* Default means Jenkinsfile if `monitoring` is provided, else all <a href="#available-portlets">available default portlets</a>.

* User-specific means the local changes of dashboard.

3. Configuration synced with the default one? If needed, you can synchronize the
actual configuration with the default one.

4. The actual configuration

5. The default configuration.

> **Prioritising of the different configurations**:
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/io/jenkins/plugins/monitoring/Monitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
import hudson.Extension;
import hudson.model.Run;
import hudson.model.TaskListener;
import io.jenkins.plugins.monitoring.util.PortletService;
import io.jenkins.plugins.monitoring.util.PullRequestFinder;
import io.jenkins.plugins.monitoring.util.PortletUtils;
import io.jenkins.plugins.monitoring.util.PullRequestUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.jenkinsci.plugins.workflow.steps.SynchronousStepExecution;
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.jenkinsci.plugins.workflow.steps.*;
import org.json.JSONArray;
import org.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -80,15 +79,15 @@ public Void run() throws Exception {
return null;
}

if (!PortletService.isValidConfiguration(monitor.getPortlets())) {
if (!PortletUtils.isValidConfiguration(monitor.getPortlets())) {
log("[Monitor] Portlet Configuration is invalid!");
return null;
}

JSONArray portlets = new JSONArray(monitor.getPortlets());
log("[Monitor] Portlet Configuration: " + portlets.toString(3));

List<String> classes = PortletService.getAvailablePortlets(run)
List<String> classes = PortletUtils.getAvailablePortlets(run)
.stream()
.map(MonitorPortlet::getId)
.collect(Collectors.toList());
Expand Down Expand Up @@ -132,7 +131,7 @@ public Void run() throws Exception {
log("[Monitor] Cleaned Portlets: " + cleanedPortlets.toString(3));
}

if (PullRequestFinder.isPullRequest(run.getParent())) {
if (PullRequestUtils.isPullRequest(run.getParent())) {
log("[Monitor] Build is part of a pull request. Add 'MonitoringCustomAction' now.");

run.addAction(new MonitoringCustomAction(monitor.getPortlets()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import hudson.model.UserPropertyDescriptor;

import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.jenkins.plugins.monitoring;

import org.apache.commons.lang3.StringUtils;

import java.util.Optional;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import edu.hm.hafner.util.FilteredLog;
import hudson.model.Run;
import io.jenkins.plugins.forensics.reference.ReferenceFinder;
import io.jenkins.plugins.monitoring.util.PortletService;
import io.jenkins.plugins.monitoring.util.PortletUtils;
import j2html.tags.DomContent;
import jenkins.model.Jenkins;
import org.commonmark.node.*;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import jenkins.model.RunAction2;
import jenkins.scm.api.metadata.ContributorMetadataAction;
import jenkins.scm.api.metadata.ObjectMetadataAction;
import jenkins.scm.api.mixin.ChangeRequestSCMHead2;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty;
import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -86,7 +86,7 @@ public void onLoad(final Run<?, ?> build) {
}

public String getPortlets() {
return PortletService.getDefaultPortletsAsConfiguration(getRun());
return PortletUtils.getDefaultPortletsAsConfiguration(getRun());
}

/**
Expand Down Expand Up @@ -233,7 +233,7 @@ public List<String> getUnavailablePortlets() {
usedPlugins.add(portlet.getString("id"));
}

List<String> availablePlugins = PortletService.getAvailablePortlets(getRun())
List<String> availablePlugins = PortletUtils.getAvailablePortlets(getRun())
.stream().map(MonitorPortlet::getId).collect(Collectors.toList());
return new ArrayList<String>(CollectionUtils.removeAll(usedPlugins, availablePlugins));
}
Expand Down Expand Up @@ -398,7 +398,7 @@ public Object getTarget() {
* all available {@link MonitorPortlet}.
*/
public static List<? extends MonitorPortlet> getAvailablePortlets(final Run<?, ?> build) {
return PortletService.getAvailablePortlets(build);
return PortletUtils.getAvailablePortlets(build);
}

/**
Expand All @@ -408,7 +408,7 @@ public static List<? extends MonitorPortlet> getAvailablePortlets(final Run<?, ?
* all factories as list.
*/
public static List<? extends MonitorPortletFactory> getFactories() {
return PortletService.getFactories();
return PortletUtils.getFactories();
}

/**
Expand All @@ -425,6 +425,6 @@ public static List<? extends MonitorPortletFactory> getFactories() {
*/
public static List<? extends MonitorPortlet> getAvailablePortletsForFactory(
final Run<?, ?> build, final MonitorPortletFactory factory) {
return PortletService.getAvailablePortletsForFactory(build, factory);
return PortletUtils.getAvailablePortletsForFactory(build, factory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Run;
import hudson.model.Action;
import hudson.model.Job;
import io.jenkins.plugins.monitoring.util.PullRequestFinder;
import hudson.model.Run;
import io.jenkins.plugins.monitoring.util.PullRequestUtils;
import jenkins.model.TransientActionFactory;

import java.util.Collection;
Expand Down Expand Up @@ -33,7 +33,7 @@ public Collection<? extends Action> createFor(@NonNull final Run run) {

final Job<?, ?> job = run.getParent();

if (PullRequestFinder.isPullRequest(job)) {
if (PullRequestUtils.isPullRequest(job)) {
return Collections.singletonList(new MonitoringDefaultAction(run));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import hudson.model.Action;
import hudson.model.Job;
import hudson.model.ProminentProjectAction;
import io.jenkins.plugins.monitoring.util.PullRequestFinder;
import io.jenkins.plugins.monitoring.util.PullRequestUtils;
import jenkins.branch.MultiBranchProject;
import jenkins.scm.api.metadata.ContributorMetadataAction;
import jenkins.scm.api.metadata.ObjectMetadataAction;
Expand Down Expand Up @@ -67,7 +67,7 @@ public String getUrlName() {
* filtered list of all {@link #getJobs() jobs} by "Pull Request".
*/
public List<Job<?, ?>> getPullRequests() {
return getJobs().stream().filter(PullRequestFinder::isPullRequest).collect(Collectors.toList());
return getJobs().stream().filter(PullRequestUtils::isPullRequest).collect(Collectors.toList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import hudson.model.Action;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;

import java.io.File;

/**
* This action displays a link on the side panel of a {@link WorkflowJob}. The action is only displayed if the job
* is a pull request, which is described in the associated {@link MonitoringWorkflowJobActionFactory}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Action;
import io.jenkins.plugins.monitoring.util.PullRequestFinder;
import io.jenkins.plugins.monitoring.util.PullRequestUtils;
import jenkins.model.TransientActionFactory;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;

Expand Down Expand Up @@ -46,7 +46,7 @@ public Collection<? extends Action> createFor(@NonNull final WorkflowJob workflo
return Collections.emptyList();
}

if (PullRequestFinder.isPullRequest(workflowJob)) {
if (PullRequestUtils.isPullRequest(workflowJob)) {
return Collections.singletonList(new MonitoringWorkflowJobAction(workflowJob));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
/**
* A utility class for the portlets.
*/
public final class PortletService {
private static final Logger LOGGER = Logger.getLogger(PortletService.class.getName());
public final class PortletUtils {
private static final Logger LOGGER = Logger.getLogger(PortletUtils.class.getName());

private PortletService() {
private PortletUtils() {
// make checkstyle happy.
}

Expand Down Expand Up @@ -106,7 +106,7 @@ public static String getDefaultPortletsAsConfiguration(Run<?, ?> build) {
* true, if the configuration is valid, else false.
*/
public static boolean isValidConfiguration(@NonNull final String configuration) {
try (InputStream schemaStream = PortletService.class.getResourceAsStream("/schema.json")) {
try (InputStream schemaStream = PortletUtils.class.getResourceAsStream("/schema.json")) {
JSONObject jsonSchema = new JSONObject(new JSONTokener(schemaStream));
JSONArray jsonSubject = new JSONArray(configuration);
Schema schema = SchemaLoader.load(jsonSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
/**
* A utility class for pull requests.
*/
public final class PullRequestFinder {
public final class PullRequestUtils {

private PullRequestFinder() {
private PullRequestUtils() {
// make checkstyle happy.
}

Expand Down
28 changes: 14 additions & 14 deletions src/main/webapp/js/pull-request-monitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,6 @@

}

/**
* Resets the current project configuration to the default one.
*/
function resetConfiguration() {
run.resetMonitorConfiguration(function() {
run.getConfiguration(function(config) {
configuration = JSON.parse(config.responseJSON);
resetInput();
loadGrid();
updateConfig();
});
});
}

/**
* Load the grid slots.
*/
Expand Down Expand Up @@ -298,6 +284,20 @@

}

/**
* Resets the current project configuration to the default one.
*/
function resetConfiguration() {
run.resetMonitorConfiguration(function() {
run.getConfiguration(function(config) {
configuration = JSON.parse(config.responseJSON);
resetInput();
loadGrid();
updateConfig();
});
});
}

/**
* Initialise the grid. Adds all event listener to grid methods.
*/
Expand Down

0 comments on commit 9d86952

Please sign in to comment.