Skip to content

Commit

Permalink
Merge pull request #177 from rinrinne/notify-for-ssh
Browse files Browse the repository at this point in the history
Provide notification level to gerrit command
  • Loading branch information
rsandell committed Sep 9, 2014
2 parents 278ac80 + 18f4e15 commit bbbf405
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 10 deletions.
Expand Up @@ -104,7 +104,8 @@ public String getBuildStartedCommand(AbstractBuild r, TaskListener taskListener,
String gerritCmd = config.getGerritCmdBuildStarted();
Map<String, String> parameters = createStandardParameters(r, event,
getBuildStartedCodeReviewValue(r),
getBuildStartedVerifiedValue(r));
getBuildStartedVerifiedValue(r),
Notify.ALL.name());
StringBuilder startedStats = new StringBuilder();
if (stats.getTotalBuildsToStart() > 1) {
startedStats.append(stats.toString());
Expand Down Expand Up @@ -206,15 +207,17 @@ private int getBuildStartedCodeReviewValue(AbstractBuild r) {
* <li><strong>BUILDURL</strong>: The URL to the build.</li>
* <li><strong>VERIFIED</strong>: The verified vote.</li>
* <li><strong>CODE_REVIEW</strong>: The code review vote.</li>
* <li><strong>NOTIFICATION_LEVEL</strong>: The notification level.</li>
* </ul>
* @param r the build.
* @param gerritEvent the event.
* @param codeReview the code review vote.
* @param verified the verified vote.
* @param notifyLevel the notify level.
* @return the parameters and their values.
*/
private Map<String, String> createStandardParameters(AbstractBuild r, GerritTriggeredEvent gerritEvent,
int codeReview, int verified) {
int codeReview, int verified, String notifyLevel) {
//<GERRIT_NAME> <BRANCH> <CHANGE> <PATCHSET> <PATCHSET_REVISION> <REFSPEC> <BUILDURL> VERIFIED CODE_REVIEW
Map<String, String> map = new HashMap<String, String>(DEFAULT_PARAMETERS_COUNT);
if (gerritEvent instanceof ChangeBasedEvent) {
Expand All @@ -234,6 +237,7 @@ private Map<String, String> createStandardParameters(AbstractBuild r, GerritTrig
}
map.put("VERIFIED", String.valueOf(verified));
map.put("CODE_REVIEW", String.valueOf(codeReview));
map.put("NOTIFICATION_LEVEL", notifyLevel);

return map;
}
Expand Down Expand Up @@ -476,12 +480,15 @@ public String getBuildCompletedCommand(MemoryImprint memoryImprint, TaskListener

int verified = 0;
int codeReview = 0;
Notify notifyLevel = Notify.ALL;
if (memoryImprint.getEvent().isScorable()) {
verified = getMinimumVerifiedValue(memoryImprint, onlyCountBuilt);
codeReview = getMinimumCodeReviewValue(memoryImprint, onlyCountBuilt);
notifyLevel = getHighestNotificationLevel(memoryImprint, onlyCountBuilt);
}

Map<String, String> parameters = createStandardParameters(null, memoryImprint.getEvent(), codeReview, verified);
Map<String, String> parameters = createStandardParameters(null, memoryImprint.getEvent(),
codeReview, verified, notifyLevel.name());
parameters.put("BUILDS_STATS", createBuildsStats(memoryImprint, listener, parameters));

AbstractBuild build = null;
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/help-GerritNotificationLevel.html
Expand Up @@ -3,4 +3,5 @@
This can either be nobody, the change owner, reviewers plus change owner, or all interested users
(owning, reviewing, watching, and starring).
<p/>
This setting only applies if the Gerrit REST API is enabled in the server configuration.
This setting applies implicitly if the Gerrit REST API is enabled in the server configuration.
If not use REST API, you need to add option to Gerrit command configuration in server configuration.
1 change: 1 addition & 0 deletions src/main/webapp/help-GerritVerifiedCmdBuildFailed.html
Expand Up @@ -18,6 +18,7 @@
<li><strong>BUILDURL</strong>: The URL to the build.</li>
<li><strong>VERIFIED</strong>: The verified vote.</li>
<li><strong>CODE_REVIEW</strong>: The code review vote.</li>
<li><strong>NOTIFICATION_LEVEL</strong>: The notification level.</li>
</ul>
<p>
<strong>The following special &lt;PARAMETER&gt; values are available:</strong>
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/help-GerritVerifiedCmdBuildFailed_ja.html
Expand Up @@ -18,6 +18,7 @@
<li><strong>BUILDURL</strong>: ビルド結果へのURL</li>
<li><strong>VERIFIED</strong>: Verifiedスコア</li>
<li><strong>CODE_REVIEW</strong>: Code-Reviewスコア</li>
<li><strong>NOTIFICATION_LEVEL</strong>: 通知レベル</li>
</ul>
<p>
<strong>利用可能なスペシャルパラメータ</strong>
Expand All @@ -29,5 +30,5 @@
</li>
</ul>
<p>
最初のビルドが始まってから定義された環境変数は<strong>$ENV_VAR</strong>の形で参照できます。
最初のビルドが始まってから定義された環境変数は<strong>$ENV_VAR</strong>の形で参照できます。
</p>
1 change: 1 addition & 0 deletions src/main/webapp/help-GerritVerifiedCmdBuildNotBuilt.html
Expand Up @@ -18,6 +18,7 @@
<li><strong>BUILDURL</strong>: The URL to the build.</li>
<li><strong>VERIFIED</strong>: The verified vote.</li>
<li><strong>CODE_REVIEW</strong>: The code review vote.</li>
<li><strong>NOTIFICATION_LEVEL</strong>: The notification level.</li>
</ul>
<p>
<strong>The following special &lt;PARAMETER&gt; values are available:</strong>
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/help-GerritVerifiedCmdBuildNotBuilt_ja.html
Expand Up @@ -18,6 +18,7 @@
<li><strong>BUILDURL</strong>: ビルド結果へのURL</li>
<li><strong>VERIFIED</strong>: Verifiedスコア</li>
<li><strong>CODE_REVIEW</strong>: Code-Reviewスコア</li>
<li><strong>NOTIFICATION_LEVEL</strong>: 通知レベル</li>
</ul>
<p>
<strong>利用可能なスペシャルパラメータ</strong>
Expand All @@ -29,5 +30,5 @@
</li>
</ul>
<p>
最初のビルドが始まってから定義された環境変数は<strong>$ENV_VAR</strong>の形で参照できます。
最初のビルドが始まってから定義された環境変数は<strong>$ENV_VAR</strong>の形で参照できます。
</p>
1 change: 1 addition & 0 deletions src/main/webapp/help-GerritVerifiedCmdBuildStarted.html
Expand Up @@ -18,6 +18,7 @@
<li><strong>BUILDURL</strong>: The URL to the build.</li>
<li><strong>VERIFIED</strong>: The verified vote.</li>
<li><strong>CODE_REVIEW</strong>: The code review vote.</li>
<li><strong>NOTIFICATION_LEVEL</strong>: The notification level. (always ALL)</li>
</ul>
<p>
<strong>The following special &lt;PARAMETER&gt; values are available:</strong>
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/help-GerritVerifiedCmdBuildStarted_ja.html
Expand Up @@ -18,6 +18,7 @@
<li><strong>BUILDURL</strong>: ビルド結果へのURL</li>
<li><strong>VERIFIED</strong>: Verifiedスコア</li>
<li><strong>CODE_REVIEW</strong>: Code-Reviewスコア</li>
<li><strong>NOTIFICATION_LEVEL</strong>: 通知レベル(常にALL)</li>
</ul>
<p>
<strong>利用可能なスペシャルパラメータ</strong>
Expand All @@ -30,5 +31,5 @@
</li>
</ul>
<p>
最初のビルドが始まってから定義された環境変数は<strong>$ENV_VAR</strong>の形で参照できます。
最初のビルドが始まってから定義された環境変数は<strong>$ENV_VAR</strong>の形で参照できます。
</p>
1 change: 1 addition & 0 deletions src/main/webapp/help-GerritVerifiedCmdBuildSuccessful.html
Expand Up @@ -18,6 +18,7 @@
<li><strong>BUILDURL</strong>: The URL to the build.</li>
<li><strong>VERIFIED</strong>: The verified vote.</li>
<li><strong>CODE_REVIEW</strong>: The code review vote.</li>
<li><strong>NOTIFICATION_LEVEL</strong>: The notification level.</li>
</ul>
<p>
<strong>The following special &lt;PARAMETER&gt; values are available:</strong>
Expand Down
Expand Up @@ -18,6 +18,7 @@
<li><strong>BUILDURL</strong>: ビルド結果へのURL</li>
<li><strong>VERIFIED</strong>: Verifiedスコア</li>
<li><strong>CODE_REVIEW</strong>: Code-Reviewスコア</li>
<li><strong>NOTIFICATION_LEVEL</strong>: 通知レベル</li>
</ul>
<p>
<strong>利用可能なスペシャルパラメータ</strong>
Expand All @@ -29,5 +30,5 @@
</li>
</ul>
<p>
最初のビルドが始まってから定義された環境変数は<strong>$ENV_VAR</strong>の形で参照できます。
最初のビルドが始まってから定義された環境変数は<strong>$ENV_VAR</strong>の形で参照できます。
</p>
1 change: 1 addition & 0 deletions src/main/webapp/help-GerritVerifiedCmdBuildUnstable.html
Expand Up @@ -18,6 +18,7 @@
<li><strong>BUILDURL</strong>: The URL to the build.</li>
<li><strong>VERIFIED</strong>: The verified vote.</li>
<li><strong>CODE_REVIEW</strong>: The code review vote.</li>
<li><strong>NOTIFICATION_LEVEL</strong>: The notification level.</li>
</ul>
<p>
<strong>The following special &lt;PARAMETER&gt; values are available:</strong>
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/help-GerritVerifiedCmdBuildUnstable_ja.html
Expand Up @@ -18,6 +18,7 @@
<li><strong>BUILDURL</strong>: ビルド結果へのURL</li>
<li><strong>VERIFIED</strong>: Verifiedスコア</li>
<li><strong>CODE_REVIEW</strong>: Code-Reviewスコア</li>
<li><strong>NOTIFICATION_LEVEL</strong>: 通知レベル</li>
</ul>
<p>
<strong>利用可能なスペシャルパラメータ</strong>
Expand All @@ -29,5 +30,5 @@
</li>
</ul>
<p>
最初のビルドが始まってから定義された環境変数は<strong>$ENV_VAR</strong>の形で参照できます。
最初のビルドが始まってから定義された環境変数は<strong>$ENV_VAR</strong>の形で参照できます。
</p>
Expand Up @@ -108,6 +108,7 @@ public void testGetBuildStartedCommand() throws Exception {
assertTrue("Missing PATCHSET", result.indexOf("PATCHSET=1") >= 0);
assertTrue("Missing VERIFIED", result.indexOf("VERIFIED=1") >= 0);
assertTrue("Missing CODEREVIEW", result.indexOf("CODEREVIEW=32") >= 0);
assertTrue("Missing NOTIFICATION_LEVEL", result.indexOf("NOTIFICATION_LEVEL=ALL") >= 0);
assertTrue("Missing REFSPEC", result.indexOf("REFSPEC=" + expectedRefSpec) >= 0);
assertTrue("Missing ENV_BRANCH", result.indexOf("ENV_BRANCH=branch") >= 0);
assertTrue("Missing ENV_CHANGE", result.indexOf("ENV_CHANGE=1000") >= 0);
Expand Down Expand Up @@ -439,6 +440,7 @@ public void tryGetBuildCompletedCommandSuccessfulEvent(String customUrl, String
assertTrue("Missing PATCHSET", result.indexOf("PATCHSET=1") >= 0);
assertTrue("Missing VERIFIED", result.indexOf("VERIFIED=" + expectedVerifiedVote) >= 0);
assertTrue("Missing CODEREVIEW", result.indexOf("CODEREVIEW=" + expectedCodeReviewVote) >= 0);
assertTrue("Missing NOTIFICATION_LEVEL", result.indexOf("NOTIFICATION_LEVEL=ALL") >= 0);
assertTrue("Missing REFSPEC", result.indexOf("REFSPEC=" + expectedRefSpec) >= 0);
assertTrue("Missing ENV_BRANCH", result.indexOf("ENV_BRANCH=branch") >= 0);
assertTrue("Missing ENV_CHANGE", result.indexOf("ENV_CHANGE=1000") >= 0);
Expand Down
Expand Up @@ -56,6 +56,7 @@ public String getGerritCmdBuildStarted() {
+ " PATCHSET=<PATCHSET>"
+ " VERIFIED=<VERIFIED>"
+ " CODEREVIEW=<CODE_REVIEW>"
+ " NOTIFICATION_LEVEL=<NOTIFICATION_LEVEL>"
+ " REFSPEC=<REFSPEC> MSG=I started a build."
+ " BUILDURL=<BUILDURL>"
+ " STARTED_STATS=<STARTED_STATS>"
Expand All @@ -73,6 +74,7 @@ public String getGerritCmdBuildSuccessful() {
+ " PATCHSET=<PATCHSET>"
+ " VERIFIED=<VERIFIED>"
+ " CODEREVIEW=<CODE_REVIEW>"
+ " NOTIFICATION_LEVEL=<NOTIFICATION_LEVEL>"
+ " REFSPEC=<REFSPEC> MSG='Your friendly butler says OK. BS=<BUILDS_STATS>'"
+ " BUILDURL=<BUILDURL>"
+ " STARTED_STATS=<STARTED_STATS>"
Expand Down Expand Up @@ -147,7 +149,7 @@ public String getGerritEMail() {

@Override
public Notify getNotificationLevel() {
throw new UnsupportedOperationException("Not supported yet.");
return Notify.ALL;
}

@Override
Expand Down

0 comments on commit bbbf405

Please sign in to comment.