Skip to content

Commit

Permalink
Merge pull request #383 from cashlalala/master
Browse files Browse the repository at this point in the history
  • Loading branch information
rsandell committed Feb 15, 2019
2 parents 6c836a4 + 730a382 commit 57796ce
Show file tree
Hide file tree
Showing 17 changed files with 484 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,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
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import hudson.model.Hudson;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import java.io.Serializable;

Expand All @@ -47,12 +48,19 @@ 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.
*/
@DataBoundConstructor
public PluginPatchsetCreatedEvent() {
this(false, false, false);
this.excludeDrafts = false;
this.excludeTrivialRebase = false;
this.excludeNoCodeChange = false;
this.excludePrivateState = false;
this.excludeWipState = false;
}

/**
Expand All @@ -61,7 +69,7 @@ public PluginPatchsetCreatedEvent() {
* @param excludeTrivialRebase if trivial rebases should be excluded or not.
* @param excludeNoCodeChange if message-only changes should be excluded.
*/
@DataBoundConstructor
@Deprecated
public PluginPatchsetCreatedEvent(boolean excludeDrafts,
boolean excludeTrivialRebase,
boolean excludeNoCodeChange) {
Expand All @@ -70,6 +78,51 @@ public PluginPatchsetCreatedEvent(boolean excludeDrafts,
this.excludeNoCodeChange = excludeNoCodeChange;
}

/**
* Setter for excludeDrafts.
* @param excludeDrafts if drafts should be excluded or not.
*/
@DataBoundSetter
public void setExcludeDrafts(boolean excludeDrafts) {
this.excludeDrafts = excludeDrafts;
}

/**
* Setter for excludeTrivialRebase.
* @param excludeTrivialRebase if trivial rebases should be excluded or not.
*/
@DataBoundSetter
public void setExcludeTrivialRebase(boolean excludeTrivialRebase) {
this.excludeTrivialRebase = excludeTrivialRebase;
}

/**
* Setter for excludeNoCodeChange.
* @param excludeNoCodeChange if message-only changes should be excluded.
*/
@DataBoundSetter
public void setExcludeNoCodeChange(boolean excludeNoCodeChange) {
this.excludeNoCodeChange = excludeNoCodeChange;
}

/**
* Setter for excludePrivateState.
* @param excludePrivateState if private state changes should be excluded.
*/
@DataBoundSetter
public void setExcludePrivateState(boolean excludePrivateState) {
this.excludePrivateState = excludePrivateState;
}

/**
* Setter for excludeWipState.
* @param excludeWipState if wip state changes should be excluded.
*/
@DataBoundSetter
public void setExcludeWipState(boolean excludeWipState) {
this.excludeWipState = excludeWipState;
}

/**
* Getter for the Descriptor.
* @return the Descriptor for the PluginPatchsetCreatedEvent.
Expand Down Expand Up @@ -108,6 +161,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 +197,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
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public final class GerritVersionChecker {

/**
* The feature version we want to compare the current Gerrit version with.
* Skipping WIPStateChanged & PrivateStateChanged version check due to not necessary for now.
*/
public static enum Feature {
/**
Expand Down Expand Up @@ -68,6 +69,7 @@ public static enum Feature {
*/
commentAlwaysApproval("CommentAdded always contains approval", "2.13");


private final String displayName;
private final String version;
private final VersionNumber versionNumber;
Expand Down
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 57796ce

Please sign in to comment.