Skip to content

Commit

Permalink
do not call URL with &sha1=null
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Neff committed Oct 20, 2015
1 parent 204c77d commit 919b108
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/nerdwin15/stash/webhook/Notifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ protected String getUrl(final Repository repository, final String jenkinsBase,

if(strRef != null && !omitBranchName)
url.append(String.format(BRANCH_URL_PARAMETER, urlEncode(strRef)));
if(!omitHashCode)
if(strSha1 != null && !omitHashCode)
url.append(String.format(HASH_URL_PARAMETER, strSha1));

return url.toString();
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/nerdwin15/stash/webhook/NotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,25 @@ public void shouldCallTheCorrectURLWithOmitBranchNameOff()
captor.getValue().getURI().toString());
}

/**
* Validates that the correct path is used when the sha1 is null
* @throws Exception
*/
@Test
public void shouldCallTheCorrectURLWhenSha1IsNull()
throws Exception {
when(settings.getBoolean(Notifier.OMIT_BRANCH_NAME, false)).thenReturn(false);
notifier.notify(repo, "refs/heads/master", null);

ArgumentCaptor<HttpGet> captor = ArgumentCaptor.forClass(HttpGet.class);

verify(httpClientFactory, times(1)).getHttpClient(false, false);
verify(httpClient, times(1)).execute(captor.capture());
verify(connectionManager, times(1)).shutdown();

assertEquals("http://localhost.jenkins/git/notifyCommit?"
+ "url=http%3A%2F%2Fsome.stash.com%2Fscm%2Ffoo%2Fbar.git"
+ "&branches=refs%2Fheads%2Fmaster",
captor.getValue().getURI().toString());
}
}

0 comments on commit 919b108

Please sign in to comment.