From 19c61beb786f821532fa1ad75bc74b22abf6f874 Mon Sep 17 00:00:00 2001 From: POIROTTE Francois Date: Wed, 27 Nov 2024 23:09:24 +0100 Subject: [PATCH] Add usernames to build parameters Include GERRIT_*_USERNAME (Gerrit login) in build parameters, similarly to GERRIT_*_NAME and GERRIT_*_EMAIL. --- .../GerritTriggerParameters.java | 55 +++++++++++++++++++ src/main/webapp/help-whatIsGerritTrigger.html | 5 ++ .../webapp/help-whatIsGerritTrigger_ja.html | 5 ++ .../hudsontrigger/GerritTriggerTest.java | 30 +++++++++- 4 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerParameters.java b/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerParameters.java index 427331352..2ba5afdc4 100644 --- a/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerParameters.java +++ b/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerParameters.java @@ -107,6 +107,10 @@ public enum GerritTriggerParameters { * The email of the changer of the topic. */ GERRIT_TOPIC_CHANGER_EMAIL, + /** + * The username of the changer of the topic. + */ + GERRIT_TOPIC_CHANGER_USERNAME, /** * Parameter name for the change-id. */ @@ -147,6 +151,10 @@ public enum GerritTriggerParameters { * The email of the abandoner of the change. */ GERRIT_CHANGE_ABANDONER_EMAIL, + /** + * The username of the abandoner of the change. + */ + GERRIT_CHANGE_ABANDONER_USERNAME, /** * The name and email of the owner of the change. */ @@ -159,6 +167,10 @@ public enum GerritTriggerParameters { * The email of the owner of the change. */ GERRIT_CHANGE_OWNER_EMAIL, + /** + * The username of the owner of the change. + */ + GERRIT_CHANGE_OWNER_USERNAME, /** * The name and email of the restorer of the change. */ @@ -171,6 +183,10 @@ public enum GerritTriggerParameters { * The email of the restorer of the change. */ GERRIT_CHANGE_RESTORER_EMAIL, + /** + * The username of the restorer of the change. + */ + GERRIT_CHANGE_RESTORER_USERNAME, /** * The name and email of the uploader of the patch-set. */ @@ -183,6 +199,10 @@ public enum GerritTriggerParameters { * The email of the uploader of the patch-set. */ GERRIT_PATCHSET_UPLOADER_EMAIL, + /** + * The username of the uploader of the patch-set. + */ + GERRIT_PATCHSET_UPLOADER_USERNAME, /** * The name and email of the person who triggered the event. */ @@ -195,6 +215,10 @@ public enum GerritTriggerParameters { * The email of the person who triggered the event. */ GERRIT_EVENT_ACCOUNT_EMAIL, + /** + * The username of the person who triggered the event. + */ + GERRIT_EVENT_ACCOUNT_USERNAME, /** * The refname in a ref-updated event. */ @@ -219,6 +243,10 @@ public enum GerritTriggerParameters { * The email of the submitter in a ref-updated event. */ GERRIT_SUBMITTER_EMAIL, + /** + * The username of the submitter in a ref-updated event. + */ + GERRIT_SUBMITTER_USERNAME, /** * The name of the Gerrit instance. */ @@ -443,6 +471,8 @@ public static void setOrCreateParameters(GerritTriggeredEvent gerritEvent, Job p parameters, getName(account), escapeQuotes); GERRIT_EVENT_ACCOUNT_EMAIL.setOrCreateStringParameterValue( parameters, getEmail(account), escapeQuotes); + GERRIT_EVENT_ACCOUNT_USERNAME.setOrCreateStringParameterValue( + parameters, getUsername(account), escapeQuotes); } Provider provider = gerritEvent.getProvider(); if (provider != null) { @@ -515,6 +545,8 @@ private static void setOrCreateParametersForChangeBasedEvent(ChangeBasedEvent ev parameters, getName(((ChangeRestored)event).getRestorer()), escapeQuotes); GERRIT_CHANGE_RESTORER_EMAIL.setOrCreateStringParameterValue( parameters, getEmail(((ChangeRestored)event).getRestorer()), escapeQuotes); + GERRIT_CHANGE_RESTORER_USERNAME.setOrCreateStringParameterValue( + parameters, getUsername(((ChangeRestored)event).getRestorer()), escapeQuotes); } changeSubjectMode.setOrCreateParameterValue(GERRIT_CHANGE_SUBJECT, parameters, event.getChange().getSubject(), ParameterMode.PlainMode.STRING, escapeQuotes); @@ -536,6 +568,8 @@ private static void setOrCreateParametersForChangeBasedEvent(ChangeBasedEvent ev parameters, getName(((ChangeAbandoned)event).getAbandoner()), escapeQuotes); GERRIT_CHANGE_ABANDONER_EMAIL.setOrCreateStringParameterValue( parameters, getEmail(((ChangeAbandoned)event).getAbandoner()), escapeQuotes); + GERRIT_CHANGE_ABANDONER_USERNAME.setOrCreateStringParameterValue( + parameters, getUsername(((ChangeAbandoned)event).getAbandoner()), escapeQuotes); } if (event instanceof TopicChanged) { GERRIT_OLD_TOPIC.setOrCreateStringParameterValue(parameters, @@ -548,6 +582,8 @@ private static void setOrCreateParametersForChangeBasedEvent(ChangeBasedEvent ev parameters, getName(((TopicChanged)event).getChanger()), escapeQuotes); GERRIT_TOPIC_CHANGER_EMAIL.setOrCreateStringParameterValue( parameters, getEmail(((TopicChanged)event).getChanger()), escapeQuotes); + GERRIT_TOPIC_CHANGER_USERNAME.setOrCreateStringParameterValue( + parameters, getUsername(((TopicChanged)event).getChanger()), escapeQuotes); } if (event instanceof ChangeMerged) { GERRIT_NEWREV.setOrCreateStringParameterValue( @@ -559,6 +595,8 @@ private static void setOrCreateParametersForChangeBasedEvent(ChangeBasedEvent ev parameters, getName(event.getChange().getOwner()), escapeQuotes); GERRIT_CHANGE_OWNER_EMAIL.setOrCreateStringParameterValue( parameters, getEmail(event.getChange().getOwner()), escapeQuotes); + GERRIT_CHANGE_OWNER_USERNAME.setOrCreateStringParameterValue( + parameters, getUsername(event.getChange().getOwner()), escapeQuotes); Account uploader = findUploader(event); nameAndEmailParameterMode.setOrCreateParameterValue(GERRIT_PATCHSET_UPLOADER, parameters, getNameAndEmail(uploader), ParameterMode.PlainMode.STRING, escapeQuotes); @@ -566,6 +604,8 @@ private static void setOrCreateParametersForChangeBasedEvent(ChangeBasedEvent ev parameters, getName(uploader), escapeQuotes); GERRIT_PATCHSET_UPLOADER_EMAIL.setOrCreateStringParameterValue( parameters, getEmail(uploader), escapeQuotes); + GERRIT_PATCHSET_UPLOADER_USERNAME.setOrCreateStringParameterValue( + parameters, getUsername(uploader), escapeQuotes); if (event instanceof CommentAdded) { String comment = ((CommentAdded)event).getComment(); if (comment != null) { @@ -659,6 +699,21 @@ private static Account findUploader(ChangeBasedEvent event) { } } + /** + * Convenience method to avoid NPE on none existent accounts. + * + * @param account the account. + * @return the username in the account or null if Account is null. + * @see com.sonymobile.tools.gerrit.gerritevents.dto.attr.Account#getUsername() + */ + private static String getUsername(Account account) { + if (account == null) { + return ""; + } else { + return account.getUsername(); + } + } + /** * Convenience method to avoid NPE on none existent accounts. * diff --git a/src/main/webapp/help-whatIsGerritTrigger.html b/src/main/webapp/help-whatIsGerritTrigger.html index 6290fd7a3..d8185d228 100644 --- a/src/main/webapp/help-whatIsGerritTrigger.html +++ b/src/main/webapp/help-whatIsGerritTrigger.html @@ -13,6 +13,7 @@ "Name" <name@somewhere.com>.
  • GERRIT_EVENT_ACCOUNT_NAME: The name of the account associated with the event, if any.
  • GERRIT_EVENT_ACCOUNT_EMAIL: The email of the account associated with the event, if any.
  • +
  • GERRIT_EVENT_ACCOUNT_USERNAME: The username of the account associated with the event, if any.
  • GERRIT_NAME: The name of the Gerrit instance that provided the event.
  • GERRIT_HOST: The hostname of the Gerrit instance that provided the event.
  • GERRIT_PORT: The port number of the Gerrit instance that provided the event.
  • @@ -40,21 +41,25 @@
  • GERRIT_CHANGE_OWNER_NAME: The name of the owner of the change.
  • GERRIT_CHANGE_OWNER_EMAIL: The email of the owner of the change.
  • +
  • GERRIT_CHANGE_OWNER_USERNAME: The username of the owner of the change.
  • GERRIT_PATCHSET_UPLOADER: The name and email of the uploader of the Patch Set "Name" <name@somewhere.com>.
  • GERRIT_PATCHSET_UPLOADER_NAME: The name of the uploader of the Patch Set.
  • GERRIT_PATCHSET_UPLOADER_EMAIL: The email of the uploader of the Patch Set.
  • +
  • GERRIT_PATCHSET_UPLOADER_USERNAME: The username of the uploader of the Patch Set.
  • GERRIT_PATCHSET_ABANDONER: The name and email of the abandoner of the Patch Set "Name" <name@somewhere.com>.
  • GERRIT_PATCHSET_ABANDONER_NAME: The name of the abandoner of the Patch Set.
  • GERRIT_PATCHSET_ABANDONER_EMAIL: The email of the abandoner of the Patch Set.
  • +
  • GERRIT_PATCHSET_ABANDONER_USERNAME: The username of the abandoner of the Patch Set.
  • GERRIT_PATCHSET_RESTORER: The name and email of the restorer of the Patch Set "Name" <name@somewhere.com>.
  • GERRIT_PATCHSET_RESTORER_NAME: The name of the restorer of the Patch Set.
  • GERRIT_PATCHSET_RESTORER_EMAIL: The email of the restorer of the Patch Set.
  • +
  • GERRIT_PATCHSET_RESTORER_USERNAME: The username of the restorer of the Patch Set.
  • diff --git a/src/main/webapp/help-whatIsGerritTrigger_ja.html b/src/main/webapp/help-whatIsGerritTrigger_ja.html index 6651bc9d7..6df2b9058 100644 --- a/src/main/webapp/help-whatIsGerritTrigger_ja.html +++ b/src/main/webapp/help-whatIsGerritTrigger_ja.html @@ -13,6 +13,7 @@ "Name" <name@somewhere.com>.
  • GERRIT_EVENT_ACCOUNT_NAME: イベントに関連付けられているアカウントの名前(もしあれば)
  • GERRIT_EVENT_ACCOUNT_EMAIL: イベントに関連付けられているアカウントのメールアドレス(もしあれば)
  • +
  • GERRIT_EVENT_ACCOUNT_USERNAME: イベントに関連付けられているアカウントのユーザー名(もしあれば)
  • GERRIT_NAME: イベントを提供するGerritの名前
  • GERRIT_HOST: イベントを提供するGerritのホスト名
  • GERRIT_PORT: イベントを提供するGerritのポート番号
  • @@ -40,21 +41,25 @@
  • GERRIT_CHANGE_OWNER_NAME: チェンジ・オーナーの名前
  • GERRIT_CHANGE_OWNER_EMAIL: チェンジ・オーナーのメールアドレス
  • +
  • GERRIT_CHANGE_OWNER_USERNAME: チェンジ・オーナーのユーザー名
  • GERRIT_PATCHSET_UPLOADER: パッチセットをアップロードした人の名前とメールアドレス "Name" <name@somewhere.com>.
  • GERRIT_PATCHSET_UPLOADER_NAME: パッチセット・アップロードした人の名前
  • GERRIT_PATCHSET_UPLOADER_EMAIL: パッチセット・アップロードした人のメールアドレス
  • +
  • GERRIT_PATCHSET_UPLOADER_USERNAME: パッチセット・アップロードした人のユーザー名
  • GERRIT_PATCHSET_ABANDONER: パッチセットを破棄した人の名前とメールアドレス "Name" <name@somewhere.com>.
  • GERRIT_PATCHSET_ABANDONER_NAME: パッチセットを破棄した人の名前
  • GERRIT_PATCHSET_ABANDONER_EMAIL: パッチセットを破棄した人のメールアドレス
  • +
  • GERRIT_PATCHSET_ABANDONER_USERNAME: パッチセットを破棄した人のユーザー名
  • GERRIT_PATCHSET_RESTORER: パッチセットをレストアした人の名前とメールアドレス "Name" <name@somewhere.com>.
  • GERRIT_PATCHSET_RESTORER_NAME: パッチセットをレストアした人の名前
  • GERRIT_PATCHSET_RESTORER_EMAIL: パッチセットをレストアした人のメールアドレス
  • +
  • GERRIT_PATCHSET_RESTORER_USERNAME: パッチセットをレストアした人のユーザー名
  • diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java index fd990f7e5..1fe46d810 100644 --- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java +++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java @@ -97,17 +97,19 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -//CS IGNORE LineLength FOR NEXT 11 LINES. REASON: static imports can get long +//CS IGNORE LineLength FOR NEXT 13 LINES. REASON: static imports can get long import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_CHANGE_COMMIT_MESSAGE; import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_CHANGE_ID; import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_CHANGE_OWNER; import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_CHANGE_OWNER_EMAIL; import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_CHANGE_OWNER_NAME; +import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_CHANGE_OWNER_USERNAME; import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_CHANGE_SUBJECT; import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_CHANGE_URL; import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_PATCHSET_UPLOADER; import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_PATCHSET_UPLOADER_EMAIL; import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_PATCHSET_UPLOADER_NAME; +import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.GERRIT_PATCHSET_UPLOADER_USERNAME; import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.EMAIL; import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.NAME; import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.NUMBER; @@ -475,6 +477,9 @@ public void testScheduleWithOwnerAndUploader() { final Account owner = new Account("Bobby", "bobby@somewhere.com"); final Account uploader = new Account("Nisse", "nisse@acme.org"); + owner.setUsername("bobby"); + uploader.setUsername("nisse"); + mockPluginConfig(0); final PatchsetCreated event = Setup.createPatchsetCreatedWithAccounts(owner, uploader, uploader); @@ -490,9 +495,11 @@ public void testScheduleWithOwnerAndUploader() { hasCauseActionContainingCauseMatcher(gerritCause), hasParamActionMatcher(GERRIT_CHANGE_OWNER, owner.getNameAndEmail()), hasParamActionMatcher(GERRIT_CHANGE_OWNER_NAME, owner.getName()), + hasParamActionMatcher(GERRIT_CHANGE_OWNER_USERNAME, owner.getUsername()), hasParamActionMatcher(GERRIT_CHANGE_OWNER_EMAIL, owner.getEmail()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER, uploader.getNameAndEmail()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_NAME, uploader.getName()), + hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_USERNAME, uploader.getUsername()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_EMAIL, uploader.getEmail()) )); } @@ -511,6 +518,9 @@ public void testScheduleWithOwnerAndOneUploaderNull() { final Account owner = new Account("Bobby", "bobby@somewhere.com"); final Account uploader = new Account("Nisse", "nisse@acme.org"); + owner.setUsername("bobby"); + uploader.setUsername("nisse"); + mockPluginConfig(0); final PatchsetCreated event = Setup.createPatchsetCreatedWithAccounts(owner, uploader, null); @@ -526,9 +536,11 @@ public void testScheduleWithOwnerAndOneUploaderNull() { hasCauseActionContainingCauseMatcher(gerritCause), hasParamActionMatcher(GERRIT_CHANGE_OWNER, owner.getNameAndEmail()), hasParamActionMatcher(GERRIT_CHANGE_OWNER_NAME, owner.getName()), + hasParamActionMatcher(GERRIT_CHANGE_OWNER_USERNAME, owner.getUsername()), hasParamActionMatcher(GERRIT_CHANGE_OWNER_EMAIL, owner.getEmail()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER, uploader.getNameAndEmail()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_NAME, uploader.getName()), + hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_USERNAME, uploader.getUsername()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_EMAIL, uploader.getEmail()) )); } @@ -547,6 +559,9 @@ public void testScheduleWithOwnerAndOtherUploaderNull() { final Account owner = new Account("Bobby", "bobby@somewhere.com"); final Account uploader = new Account("Nisse", "nisse@acme.org"); + owner.setUsername("bobby"); + uploader.setUsername("nisse"); + mockPluginConfig(0); final PatchsetCreated event = Setup.createPatchsetCreatedWithAccounts(owner, null, uploader); @@ -563,9 +578,11 @@ public void testScheduleWithOwnerAndOtherUploaderNull() { hasCauseActionContainingCauseMatcher(gerritCause), hasParamActionMatcher(GERRIT_CHANGE_OWNER, owner.getNameAndEmail()), hasParamActionMatcher(GERRIT_CHANGE_OWNER_NAME, owner.getName()), + hasParamActionMatcher(GERRIT_CHANGE_OWNER_USERNAME, owner.getUsername()), hasParamActionMatcher(GERRIT_CHANGE_OWNER_EMAIL, owner.getEmail()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER, uploader.getNameAndEmail()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_NAME, uploader.getName()), + hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_USERNAME, uploader.getUsername()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_EMAIL, uploader.getEmail()) )); } @@ -583,6 +600,8 @@ public void testScheduleWithOwnerAndBothUploadersNull() { final Account owner = new Account("Bobby", "bobby@somewhere.com"); + owner.setUsername("bobby"); + mockPluginConfig(0); final PatchsetCreated event = Setup.createPatchsetCreatedWithAccounts(owner, null, null); @@ -599,9 +618,11 @@ public void testScheduleWithOwnerAndBothUploadersNull() { hasCauseActionContainingCauseMatcher(gerritCause), hasParamActionMatcher(GERRIT_CHANGE_OWNER, owner.getNameAndEmail()), hasParamActionMatcher(GERRIT_CHANGE_OWNER_NAME, owner.getName()), + hasParamActionMatcher(GERRIT_CHANGE_OWNER_USERNAME, owner.getUsername()), hasParamActionMatcher(GERRIT_CHANGE_OWNER_EMAIL, owner.getEmail()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER, ""), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_NAME, ""), + hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_USERNAME, ""), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_EMAIL, "") )); } @@ -620,6 +641,9 @@ public void testScheduleWithOwnerAndPartOfUploadersNull() { final Account owner = new Account("Bobby", "bobby@somewhere.com"); final Account uploader = new Account("Bobby", null); + owner.setUsername("bobby"); + uploader.setUsername("nisse"); + mockPluginConfig(0); final PatchsetCreated event = Setup.createPatchsetCreatedWithAccounts(owner, uploader, uploader); @@ -637,9 +661,11 @@ public void testScheduleWithOwnerAndPartOfUploadersNull() { hasParamActionMatcher(GERRIT_CHANGE_OWNER, owner.getNameAndEmail()), hasParamActionMatcher(GERRIT_CHANGE_OWNER_NAME, owner.getName()), hasParamActionMatcher(GERRIT_CHANGE_OWNER_EMAIL, owner.getEmail()), + hasParamActionMatcher(GERRIT_CHANGE_OWNER_USERNAME, owner.getUsername()), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER, ""), hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_NAME, uploader.getName()), - hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_EMAIL, "") + hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_EMAIL, ""), + hasParamActionMatcher(GERRIT_PATCHSET_UPLOADER_USERNAME, uploader.getUsername()) )); }