Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Adding support for PUT and DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Apr 14, 2015
1 parent ca37d24 commit 0e92ec9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Changelog of Pull Request Notifier for Stash.

## 1.9
* Adding support for PUT and DELETE

## 1.8
* Support for HTTP POST requests, with content that is rendered with variables
* Letting variable ${PULL_REQUEST_ACTION} return RESCOPED_FROM or RESCOPED_TO instead of just RESCOPED
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The Pull Request Notifier for Stash can:

* Invoke any URL, or set of URL:s, when a pull request event happens.
* With variables available to add necessary parameters.
* HTTP POST (with post content) and GET.
* HTTP POST, PUT, GET and DELETE. POST and PUT also supports rendered post content.
* Be configured to trigger on any pull request event. Including source branch change (RESCOPED_FROM) and target branch change (RESCOPED_TO).
* Be configured to only trigger if the pull request mathches a filter. A filter text is constructed with any combination of the variables and then a regexp is constructed to match that text.
* Authenticate with HTTP basic authentication.
Expand Down
Binary file modified sandbox/all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sandbox/closer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/main/java/se/bjurr/prnfs/listener/UrlInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void ivoke(String urlParam, Optional<String> user, Optional<String> passw
setAuthorization(uc, user, password);
uc.setDoOutput(true);
if (shouldPostContent(method, postContent)) {
logger.debug("POST >\n" + postContent.get());
logger.debug(method + " >\n" + postContent.get());
uc.setDoInput(true);
uc.setRequestProperty("Content-Length", postContent.get().length() + "");
wr = new DataOutputStream(uc.getOutputStream());
Expand Down Expand Up @@ -71,7 +71,7 @@ void setAuthorization(URLConnection uc, Optional<String> user, Optional<String>

@VisibleForTesting
public static boolean shouldPostContent(String method, Optional<String> postContent) {
return method.equals("POST") && postContent.isPresent();
return (method.equals("POST") || method.equals("PUT")) && postContent.isPresent();
}

@VisibleForTesting
Expand Down
16 changes: 10 additions & 6 deletions src/main/resources/admin.vm
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,20 @@
<div>
<fieldset>
<legend>HTTP method</legend>
<label for="GET">GET</label>
<input type="radio" name="method" value="GET" onClick="jQuery('.method_post').hide()">
<label for="post">POST</label>
<input type="radio" name="method" value="POST" onClick="jQuery('.method_post').show()">
<input type="radio" name="method" value="GET" onClick="jQuery('.method_POST').hide()">
<label for="GET">GET</label><br>
<input type="radio" name="method" value="POST" onClick="jQuery('.method_POST').show()">
<label for="post">POST</label><br>
<input type="radio" name="method" value="PUT" onClick="jQuery('.method_POST').show()">
<label for="post">PUT</label><br>
<input type="radio" name="method" value="DELETE" onClick="jQuery('.method_POST').hide()">
<label for="post">DELETE</label>
</fieldset>
</div>
<div class="visibleif method_POST">
<div class="visibleif method_POST method_PUT">
<fieldset>
<legend>POST content</legend>
<textarea name="post_content" rows="10" cols="40"></textarea>
<textarea name="post_content" rows="6" cols="40"></textarea>
</fieldset>
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ public void testThatPostContentIsNotSentIfMethodIsGETAndThereIsPostContent() {
.invokedUrl("http://bjurr.se/").invokedMethod("GET").didNotSendPostContentAt(0);
}

@Test
public void testThatPostContentIsNotSentIfMethodIsDELETEAndThereIsPostContent() {
prnfsTestBuilder()
.isLoggedInAsAdmin()
.withNotification(
notificationBuilder().withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/")
.withFieldValue(AdminFormValues.FIELDS.events, OPENED.name()) //
.withFieldValue(AdminFormValues.FIELDS.post_content, "some content") //
.withFieldValue(AdminFormValues.FIELDS.method, "DELETE") //
.build()).store().trigger(pullRequestEventBuilder().withPullRequestAction(OPENED).build())
.invokedUrl("http://bjurr.se/").invokedMethod("DELETE").didNotSendPostContentAt(0);
}

@Test
public void testThatPostContentIsSentIfMethodIsPOSTAndThereIsPostContent() {
prnfsTestBuilder()
Expand All @@ -207,6 +220,19 @@ public void testThatPostContentIsSentIfMethodIsPOSTAndThereIsPostContent() {
.invokedUrl("http://bjurr.se/").didSendPostContentAt(0, "some content");
}

@Test
public void testThatPostContentIsSentIfMethodIsPUTAndThereIsPostContent() {
prnfsTestBuilder()
.isLoggedInAsAdmin()
.withNotification(
notificationBuilder().withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/")
.withFieldValue(AdminFormValues.FIELDS.events, OPENED.name()) //
.withFieldValue(AdminFormValues.FIELDS.post_content, "some content") //
.withFieldValue(AdminFormValues.FIELDS.method, "PUT") //
.build()).store().trigger(pullRequestEventBuilder().withPullRequestAction(OPENED).build())
.invokedUrl("http://bjurr.se/").didSendPostContentAt(0, "some content");
}

@Test
public void testThatPostContentIsSentAndRenderedIfMethodIsPOSTAndThereIsPostContent() {
prnfsTestBuilder()
Expand Down

0 comments on commit 0e92ec9

Please sign in to comment.