Add support for new patchset-created exclude fields

New exclude features added to Gerrit Trigger plugin version 2.12.0.

Exclude Features:
  - Drafts
  - Trivial Rebase
  - No Code Change

This patch still supports the old trigger non-dict format yaml config:

	- patchset-created-event

Using the old configuration (non-dict) works in the new Gerrit Trigger
v2.12.0 as well as the previous versions.

In addition the newer configuration (dict) format also works in old
<2.12.0 and new >2.12.0 versions of Gerrit Trigger.

Added additional unit tests to verify old and new formats working.

Change-Id: I923b0be47085dc50da48f5ed271a13eae7e1dfa0
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
This commit is contained in:
Thanh Ha 2014-12-08 12:39:33 -05:00
parent 520f3c5459
commit 7447292b57
5 changed files with 131 additions and 5 deletions

View File

@ -135,8 +135,8 @@ def build_gerrit_triggers(xml_parent, data):
if isinstance(event, six.string_types): if isinstance(event, six.string_types):
tag_name = available_simple_triggers.get(event) tag_name = available_simple_triggers.get(event)
if event == 'patchset-uploaded-event': if event == 'patchset-uploaded-event':
logger.warn("'%s' is deprecated. Use 'patchset-created-event'" logger.warn("'%s' is deprecated. Use 'patchset-created-event' "
"instead.", event) "format instead.", event)
if not tag_name: if not tag_name:
known = ', '.join(available_simple_triggers.keys() known = ', '.join(available_simple_triggers.keys()
@ -148,6 +148,18 @@ def build_gerrit_triggers(xml_parent, data):
XML.SubElement(trigger_on_events, XML.SubElement(trigger_on_events,
'%s.%s' % (tag_namespace, tag_name)) '%s.%s' % (tag_namespace, tag_name))
else: else:
if 'patchset-created-event' in event.keys():
pce = event['patchset-created-event']
pc = XML.SubElement(
trigger_on_events,
'%s.%s' % (tag_namespace, 'PluginPatchsetCreatedEvent'))
XML.SubElement(pc, 'excludeDrafts').text = str(
pce.get('exclude-drafts', False)).lower()
XML.SubElement(pc, 'excludeTrivialRebase').text = str(
pce.get('exclude-trivial-rebase', False)).lower()
XML.SubElement(pc, 'excludeNoCodeChange').text = str(
pce.get('exclude-no-code-change', False)).lower()
if 'comment-added-event' in event.keys(): if 'comment-added-event' in event.keys():
comment_added_event = event['comment-added-event'] comment_added_event = event['comment-added-event']
cadded = XML.SubElement( cadded = XML.SubElement(
@ -200,7 +212,19 @@ def gerrit(parser, xml_parent, data):
:Trigger on: :Trigger on:
* **patchset-created-event** -- Trigger upon patchset creation. * **patchset-created-event** (`dict`) -- Trigger upon patchset
creation.
:Patchset created:
* **exclude-drafts** (`bool`) -- exclude drafts (Default: False)
* **exclude-trivial-rebase** (`bool`) -- exclude trivial rebase
(Default: False)
* **exclude-no-code-change** (`bool`) -- exclude no code change
(Default: False)
Exclude drafts|trivial-rebase|no-code-change needs
Gerrit Trigger v2.12.0
* **patchset-uploaded-event** -- Trigger upon patchset creation * **patchset-uploaded-event** -- Trigger upon patchset creation
(this is a alias for `patchset-created-event`). (this is a alias for `patchset-created-event`).

View File

@ -44,7 +44,11 @@
<triggerConfigURL>http://myhost/mytrigger</triggerConfigURL> <triggerConfigURL>http://myhost/mytrigger</triggerConfigURL>
<allowTriggeringUnreviewedPatches>true</allowTriggeringUnreviewedPatches> <allowTriggeringUnreviewedPatches>true</allowTriggeringUnreviewedPatches>
<triggerOnEvents> <triggerOnEvents>
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent/> <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
<excludeDrafts>true</excludeDrafts>
<excludeTrivialRebase>true</excludeTrivialRebase>
<excludeNoCodeChange>true</excludeNoCodeChange>
</com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginCommentAddedEvent> <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginCommentAddedEvent>
<verdictCategory>APRV</verdictCategory> <verdictCategory>APRV</verdictCategory>
<commentAddedTriggerApprovalValue>1</commentAddedTriggerApprovalValue> <commentAddedTriggerApprovalValue>1</commentAddedTriggerApprovalValue>

View File

@ -1,7 +1,10 @@
triggers: triggers:
- gerrit: - gerrit:
trigger-on: trigger-on:
- patchset-created-event - patchset-created-event:
exclude-drafts: true
exclude-trivial-rebase: true
exclude-no-code-change: true
- comment-added-event: - comment-added-event:
approval-category: 'APRV' approval-category: 'APRV'
approval-value: 1 approval-value: 1

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger>
<spec/>
<gerritProjects>
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject>
<compareType>PLAIN</compareType>
<pattern>test-project</pattern>
<branches>
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
<compareType>PLAIN</compareType>
<pattern>master</pattern>
</com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
<compareType>PLAIN</compareType>
<pattern>stable</pattern>
</com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
</branches>
<filePaths>
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.FilePath>
<compareType>ANT</compareType>
<pattern>subdirectory/**</pattern>
</com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.FilePath>
</filePaths>
<topics>
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Topic>
<compareType>ANT</compareType>
<pattern>refactor-xy**</pattern>
</com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Topic>
</topics>
</com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject>
</gerritProjects>
<skipVote>
<onSuccessful>true</onSuccessful>
<onFailed>true</onFailed>
<onUnstable>true</onUnstable>
<onNotBuilt>true</onNotBuilt>
</skipVote>
<silentMode>false</silentMode>
<escapeQuotes>false</escapeQuotes>
<noNameAndEmailParameters>false</noNameAndEmailParameters>
<dynamicTriggerConfiguration>True</dynamicTriggerConfiguration>
<triggerConfigURL>http://myhost/mytrigger</triggerConfigURL>
<allowTriggeringUnreviewedPatches>true</allowTriggeringUnreviewedPatches>
<triggerOnEvents>
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent/>
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginCommentAddedEvent>
<verdictCategory>APRV</verdictCategory>
<commentAddedTriggerApprovalValue>1</commentAddedTriggerApprovalValue>
</com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginCommentAddedEvent>
</triggerOnEvents>
<buildStartMessage/>
<buildFailureMessage/>
<buildSuccessfulMessage/>
<buildUnstableMessage/>
<buildNotBuiltMessage/>
<customUrl/>
<serverName>my-server</serverName>
</com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger>
</triggers>
</project>

View File

@ -0,0 +1,33 @@
triggers:
- gerrit:
trigger-on:
- patchset-created-event
- comment-added-event:
approval-category: 'APRV'
approval-value: 1
projects:
- project-compare-type: 'PLAIN'
project-pattern: 'test-project'
branches:
- branch-compare-type: 'PLAIN'
branch-pattern: 'master'
- branch-compare-type: 'PLAIN'
branch-pattern: 'stable'
file-paths:
- compare-type: ANT
pattern: subdirectory/**
topics:
- compare-type: ANT
pattern: refactor-xy**
skip-vote:
successful: true
failed: true
unstable: true
notbuilt: true
silent: false
escape-quotes: false
no-name-and-email: false
dynamic-trigger-enabled: true
dynamic-trigger-url: http://myhost/mytrigger
trigger-for-unreviewed-patches: true
server-name: my-server