Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.jenkins.plugins.checks.github;

import hudson.Extension;
import jenkins.model.GlobalConfiguration;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

@Extension
public class GitHubChecksGlobalConfig extends GlobalConfiguration {


private boolean skipProgressUpdates = false;
private boolean enforceSkipProgressUpdates = false;

public static GitHubChecksGlobalConfig get() {
return GlobalConfiguration.all().get(GitHubChecksGlobalConfig.class);
}

public GitHubChecksGlobalConfig() {
load();
}

public synchronized boolean isSkipProgressUpdates() {
return skipProgressUpdates;
}

public synchronized void setSkipProgressUpdates(boolean skipProgressUpdates) {
this.skipProgressUpdates = skipProgressUpdates;
save();
}

public synchronized boolean isEnforceSkipProgressUpdates() {
return enforceSkipProgressUpdates;
}

public synchronized void setEnforceSkipProgressUpdates(boolean enforceSkipProgressUpdates) {
this.enforceSkipProgressUpdates = enforceSkipProgressUpdates;
save();
}

@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
req.bindJSON(this, json);
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.jenkins.plugins.checks.github.status;

import io.jenkins.plugins.checks.github.GitHubChecksGlobalConfig;
import org.apache.commons.lang3.StringUtils;

import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -27,13 +28,17 @@ public class GitHubSCMSourceStatusChecksTrait extends SCMSourceTrait implements
private boolean unstableBuildNeutral = false;
private String name = "Jenkins";
private boolean suppressLogs = false;
private boolean skipProgressUpdates = false;
private boolean skipProgressUpdates = DescriptorImpl.defaultSkipProgressUpdates;

public GitHubChecksGlobalConfig globalConfig = GitHubChecksGlobalConfig.get();
public boolean enforceSkipProgressUpdates = GitHubChecksGlobalConfig.get().isEnforceSkipProgressUpdates();

/**
* Constructor for stapler.
*/
@DataBoundConstructor
public GitHubSCMSourceStatusChecksTrait() {

super();
}

Expand Down Expand Up @@ -72,6 +77,9 @@ public boolean isSkipNotifications() {
return skipNotifications;
}

@Override
public boolean isEnforceSkipProgressUpdates() { return enforceSkipProgressUpdates; }

@Override
public boolean isSuppressLogs() {
return suppressLogs;
Expand Down Expand Up @@ -136,6 +144,13 @@ protected void decorateContext(final SCMSourceContext<?, ?> context) {
*/
@Extension
public static class DescriptorImpl extends SCMSourceTraitDescriptor {
public static final boolean defaultSkipProgressUpdates;
public static final boolean enforceSkipProgressUpdates;
Comment on lines +147 to +148
Copy link
Member

Choose a reason for hiding this comment

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

these shouldn't be final / static, why do you need them in here? these will only get set on jenkins start


static {
enforceSkipProgressUpdates = GitHubChecksGlobalConfig.get().isEnforceSkipProgressUpdates();
defaultSkipProgressUpdates = true;
}
/**
* Returns the display name.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.jenkins.plugins.checks.github.status;

import hudson.model.Job;

/**
* Configurations for users to customize status checks.
*/
Expand Down Expand Up @@ -39,6 +41,8 @@ public interface GitHubStatusChecksConfigurations {
* @return true if progress updates should be skipped.
*/
boolean isSkipProgressUpdates();

boolean isEnforceSkipProgressUpdates();
}

class DefaultGitHubStatusChecksConfigurations implements GitHubStatusChecksConfigurations {
Expand Down Expand Up @@ -66,5 +70,10 @@ public boolean isSuppressLogs() {
public boolean isSkipProgressUpdates() {
return false;
}

@Override
public boolean isEnforceSkipProgressUpdates() {
return false;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import edu.hm.hafner.util.VisibleForTesting;

import io.jenkins.plugins.checks.github.GitHubChecksGlobalConfig;
import org.jenkinsci.plugins.github_branch_source.GitHubSCMSource;
import hudson.Extension;
import hudson.model.Job;
Expand Down Expand Up @@ -66,7 +67,10 @@ public boolean isSuppressLogs(final Job<?, ?> job) {

@Override
public boolean isSkipProgressUpdates(final Job<?, ?> job) {
return getConfigurations(job).orElse(DEFAULT_CONFIGURATION).isSkipProgressUpdates();
if (GitHubChecksGlobalConfig.get().isEnforceSkipProgressUpdates())
return GitHubChecksGlobalConfig.get().isSkipProgressUpdates();
else
return getConfigurations(job).orElse(DEFAULT_CONFIGURATION).isSkipProgressUpdates();
}

private Optional<GitHubStatusChecksConfigurations> getConfigurations(final Job<?, ?> job) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.jenkins.plugins.checks.github.status;

import io.jenkins.plugins.checks.github.GitHubChecksGlobalConfig;
import org.apache.commons.lang3.StringUtils;

import org.kohsuke.stapler.DataBoundConstructor;
Expand All @@ -22,6 +23,7 @@ public class GitSCMStatusChecksExtension extends GitSCMExtension implements GitH
private String name = "Jenkins";
private boolean suppressLogs;
private boolean skipProgressUpdates = false;
public boolean enforceSkipProgressUpdates = GitHubChecksGlobalConfig.get().isEnforceSkipProgressUpdates();

/**
* Constructor for stapler.
Expand Down Expand Up @@ -56,6 +58,9 @@ public boolean isSkipProgressUpdates() {
return skipProgressUpdates;
}

@Override
public boolean isEnforceSkipProgressUpdates() { return enforceSkipProgressUpdates; }

@DataBoundSetter
public void setSkipProgressUpdates(final boolean skipProgressUpdates) {
this.skipProgressUpdates = skipProgressUpdates;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:section title="GitHub Checks Global Configuration">
<f:entry title="${%Suppress progress updates in job check}" field="skipProgressUpdates"
description="${%Queued, checkout and completed will still be sent}">
<f:checkbox default="${descriptor.defaultSkipProgressUpdates}"/>
</f:entry>
<f:entry title="${%Enforce global setting suppress progress updates in job check}" field="enforceSkipProgressUpdates"
description="${%Enforce this setting.}">
<f:checkbox/>
</f:entry>
</f:section>
</j:jelly>
14 changes: 8 additions & 6 deletions src/main/resources/lib/github-checks/status/properties.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
<f:textbox default="Jenkins"/>
</f:entry>


<f:entry title="${%Publish unstable builds as neutral status checks}" field="unstableBuildNeutral">
<f:checkbox/>
</f:entry>

<f:entry title="${%Suppress log output in checks}" field="suppressLogs">
<f:checkbox/>
</f:entry>

<f:entry title="${%Suppress progress updates in job check}" field="skipProgressUpdates"
description="${%Queued, checkout and completed will still be sent}">
<f:checkbox/>
</f:entry>

<j:var set="readOnlyMode" value="${descriptor.enforceSkipProgressUpdates}" />
<j:if test="${!readP}">
Comment on lines +20 to +21
Copy link
Member

Choose a reason for hiding this comment

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

why not just do this?

Suggested change
<j:var set="readOnlyMode" value="${descriptor.enforceSkipProgressUpdates}" />
<j:if test="${!readP}">
<j:if test="${!descriptor.enforceSkipProgressUpdates}">

Copy link

Choose a reason for hiding this comment

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

Same result. We built that complicated workaround because this did not work initially.

<f:entry title="${%Suppress progress updates in job check}" field="skipProgressUpdates"
description="${%Queued, checkout and completed will still be sent}">
<f:checkbox default="${descriptor.defaultSkipProgressUpdates}"/>
</f:entry>
</j:if>
Comment on lines +20 to +26
Copy link

Choose a reason for hiding this comment

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

We would need some advice on Jelly conditional rendering here.. we try to hide the option on the jobs, if the global configuration says that the option is enforced.
It seems like ${!readOnlyMode} does not resolve correctly here (we tried it with and without the descriptor). If you have any idea, let us know. Thanks!

</j:jelly>