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

support triggering for wip-state-changed and private-state-changed #383

Merged
merged 20 commits into from Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -71,7 +71,7 @@
<dependency>
<groupId>com.sonymobile.tools.gerrit</groupId>
<artifactId>gerrit-events</artifactId>
<version>2.12.0</version>
<version>2.13.0</version>
<exclusions>
<exclusion>
<!-- json-lib-2.4-jenkins-2 is provided by core/stapler -->
Expand Down
Expand Up @@ -230,8 +230,8 @@ private void tryLoadProjectList() {
}
}
try {
logger.info("Trying to load project list.");
if (isConnected()) {
logger.info("Trying to load project list.");
IGerritHudsonTriggerConfig activeConfig = getConfig();
SshConnection sshConnection = SshConnectionFactory.getConnection(
activeConfig.getGerritHostName(),
Expand All @@ -247,6 +247,9 @@ private void tryLoadProjectList() {
logger.warn("Project list from {} contains 0 projects", serverName);
}
sshConnection.disconnect();
} else {
logger.warn("Could not connect to Gerrit server when updating Gerrit project list: "
+ "Server is not connected (timeout)");
}
} catch (SshException ex) {
logger.warn("Could not connect to Gerrit server when updating Gerrit project list: ", ex);
Expand Down Expand Up @@ -341,4 +344,3 @@ public String getDisplayName() {
return StringUtil.getDefaultDisplayNameForSpecificServer(this, getServerName());
}
}

Expand Up @@ -389,6 +389,7 @@ public Job findJob() {
if (jenkins == null) {
return null;
}
// With security handler, this method return null, if current user could not read this project.
return jenkins.getItemByFullName(job, Job.class);
}

Expand Down
Expand Up @@ -1888,6 +1888,11 @@ public Object readResolve() throws ObjectStreamException {
* /DEPRECATION HANDLING
*/

@Override
public TriggerDescriptor getDescriptor() {
return Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
}

/**
* The Descriptor for the Trigger.
*/
Expand Down
Expand Up @@ -62,6 +62,14 @@
* @author Robert Sandell &lt;robert.sandell@sonyericsson.com&gt;
*/
public enum GerritTriggerParameters {
/**
* Parameter name for change private state.
*/
GERRIT_CHANGE_PRIVATE_STATE,
/**
* Parameter name for change wip state.
*/
GERRIT_CHANGE_WIP_STATE,
/**
* Parameter name for the commit subject (commit message's 1st line).
*/
Expand Down Expand Up @@ -391,6 +399,10 @@ public static void setOrCreateParameters(GerritTriggeredEvent gerritEvent, Job p
parameters, String.valueOf(((java.lang.Object)gerritEvent).hashCode()), escapeQuotes);
if (gerritEvent instanceof ChangeBasedEvent) {
ChangeBasedEvent event = (ChangeBasedEvent)gerritEvent;
GERRIT_CHANGE_WIP_STATE.setOrCreateStringParameterValue(
parameters, String.valueOf(event.getChange().isWip()), escapeQuotes);
GERRIT_CHANGE_PRIVATE_STATE.setOrCreateStringParameterValue(
parameters, String.valueOf(event.getChange().isPrivate()), escapeQuotes);
GERRIT_BRANCH.setOrCreateStringParameterValue(
parameters, event.getChange().getBranch(), escapeQuotes);
GERRIT_TOPIC.setOrCreateStringParameterValue(
Expand Down
Expand Up @@ -47,27 +47,35 @@ public class PluginPatchsetCreatedEvent extends PluginGerritEvent implements Ser
private boolean excludeDrafts = false;
private boolean excludeTrivialRebase = false;
private boolean excludeNoCodeChange = false;
private boolean excludePrivateState = false;
private boolean excludeWipState = false;

/**
* Default constructor.
*/
public PluginPatchsetCreatedEvent() {
this(false, false, false);
this(false, false, false, false, false);
}

/**
* Standard DataBoundConstructor.
* @param excludeDrafts if drafts should be excluded or not.
* @param excludeTrivialRebase if trivial rebases should be excluded or not.
* @param excludeNoCodeChange if message-only changes should be excluded.
* @param excludePrivateState if private state changes should be excluded.
* @param excludeWipState if wip state changes should be excluded.
*/
@DataBoundConstructor
public PluginPatchsetCreatedEvent(boolean excludeDrafts,
boolean excludeTrivialRebase,
boolean excludeNoCodeChange) {
boolean excludeNoCodeChange,
boolean excludePrivateState,
cashlalala marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

By keep the original signature with deprecation I meant the original signature before you started making changes :)
We try to strive for keeping binary copatibility between releases of the plugin (since there is no clear way of indicating defined APIs)
And this change breaks binary compatibility because the signature PluginPatchsetCreatedEvent(boolean, boolean) is gone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the misunderstanding, I should aware that.
If you still need me to change anything, just inform me.
Thanks for the patience.

boolean excludeWipState) {
this.excludeDrafts = excludeDrafts;
this.excludeTrivialRebase = excludeTrivialRebase;
this.excludeNoCodeChange = excludeNoCodeChange;
this.excludePrivateState = excludePrivateState;
this.excludeWipState = excludeWipState;
}

/**
Expand Down Expand Up @@ -108,6 +116,22 @@ public boolean isExcludeNoCodeChange() {
return excludeNoCodeChange;
}

/**
* Getter for the excludePrivateState field.
* @return excludePrivateState
*/
public boolean isExcludePrivateState() {
return excludePrivateState;
}

/**
* Getter for the excludeWipState field.
* @return excludeWipState
*/
public boolean isExcludeWipState() {
return excludeWipState;
}

@Override
public boolean shouldTriggerOn(GerritTriggeredEvent event) {
if (!super.shouldTriggerOn(event)) {
Expand All @@ -128,6 +152,12 @@ public boolean shouldTriggerOn(GerritTriggeredEvent event) {
&& GerritChangeKind.NO_CODE_CHANGE == ((PatchsetCreated)event).getPatchSet().getKind()) {
return false;
}
if (excludePrivateState && ((PatchsetCreated)event).getChange().isPrivate()) {
return false;
}
if (excludeWipState && ((PatchsetCreated)event).getChange().isWip()) {
return false;
}
return true;
}

Expand Down
@@ -0,0 +1,79 @@
/*
* The MIT License
*
* Copyright 2012 Intel, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events;

import java.io.Serializable;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

import com.sonyericsson.hudson.plugins.gerrit.trigger.Messages;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.PrivateStateChanged;

import hudson.Extension;
import hudson.model.Descriptor;
import jenkins.model.Jenkins;

/**
* An event configuration that causes the build to be triggered when a change's
* private state changed.
*/
public class PluginPrivateStateChangedEvent extends PluginGerritEvent implements Serializable {
private static final long serialVersionUID = 782691143033502579L;

/**
* Standard constructor.
*/
@DataBoundConstructor
public PluginPrivateStateChangedEvent() {
}

/**
* Getter for the Descriptor.
*
* @return the Descriptor for the PluginPrivateStateChangedEvent.
*/
@Override
public Descriptor<PluginGerritEvent> getDescriptor() {
return Jenkins.getInstance().getDescriptorByType(PluginPrivateStateChangedEventDescriptor.class);
}

@Override
public Class getCorrespondingEventClass() {
return PrivateStateChanged.class;
}

/**
* The descriptor for the PluginPrivateStateChangedEvent.
*/
@Extension
@Symbol("privateStateChanged")
public static class PluginPrivateStateChangedEventDescriptor extends PluginGerritEventDescriptor {

@Override
public String getDisplayName() {
return Messages.PrivateStateChangedDisplayName();
}
}
}
@@ -0,0 +1,79 @@
/*
* The MIT License
*
* Copyright 2012 Intel, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events;

import java.io.Serializable;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

import com.sonyericsson.hudson.plugins.gerrit.trigger.Messages;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.WipStateChanged;

import hudson.Extension;
import hudson.model.Descriptor;
import jenkins.model.Jenkins;

/**
* An event configuration that causes the build to be triggered when a change's
* WIP state changed.
*/
public class PluginWipStateChangedEvent extends PluginGerritEvent implements Serializable {
private static final long serialVersionUID = 5530163420962242330L;

/**
* Standard constructor.
*/
@DataBoundConstructor
public PluginWipStateChangedEvent() {
}

/**
* Getter for the Descriptor.
*
* @return the Descriptor for the PluginWipStateChangedEvent.
*/
@Override
public Descriptor<PluginGerritEvent> getDescriptor() {
return Jenkins.getInstance().getDescriptorByType(PluginWorkInProgressStateChangedEventDescriptor.class);
}

@Override
public Class getCorrespondingEventClass() {
return WipStateChanged.class;
}

/**
* The descriptor for the PluginWipStateChangedEvent.
*/
@Extension
@Symbol("wipStateChanged")
public static class PluginWorkInProgressStateChangedEventDescriptor extends PluginGerritEventDescriptor {

@Override
public String getDisplayName() {
return Messages.WorkInProgressStateChangedDisplayName();
}
}
}
Expand Up @@ -66,7 +66,17 @@ public static enum Feature {
/**
* Gerrit CommentAdded always contains approval information, added in Gerrit 2.13.
*/
commentAlwaysApproval("CommentAdded always contains approval", "2.13");
commentAlwaysApproval("CommentAdded always contains approval", "2.13"),

/**
* WIPStateChanged events, added in Gerrit 2.15.
*/
wipStateChanged("WIPStateChanged events", "2.15"),

/**
* PrivateStateChanged events, added in Gerrit 2.15.
*/
privateStateChanged("privateStateChanged events", "2.15");
cashlalala marked this conversation as resolved.
Show resolved Hide resolved
cashlalala marked this conversation as resolved.
Show resolved Hide resolved

private final String displayName;
private final String version;
Expand Down
Expand Up @@ -82,6 +82,10 @@ ManualTriggerPermissionDescription=\
Permission for the use of "Query and Trigger Gerrit Patches".
RetriggerPermissionDescription=\
Permission for the use of the "Retrigger" option on builds.
PrivateStateChangedDisplayName=\
Private State Changed
WorkInProgressStateChangedDisplayName=\
WIP State Changed
CommentAddedDisplayName=\
Comment Added
PatchsetCreatedDisplayName=\
Expand Down
Expand Up @@ -37,4 +37,12 @@
help="/plugin/gerrit-trigger/trigger/help-ExcludeNoCodeChange.html">
<f:checkbox/>
</f:entry>
<f:entry title="${%Exclude Private Changes}"
field="excludePrivateState">
<f:checkbox/>
</f:entry>
<f:entry title="${%Exclude WIP Changes}"
field="excludeWipState">
<f:checkbox/>
</f:entry>
</j:jelly>
@@ -0,0 +1,26 @@
<!--
~ The MIT License
~
~ Copyright 2012 Intel, Inc. All rights reserved.
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in
~ all copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
~ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
</j:jelly>