This repository was archived by the owner on Feb 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define WebhookRequest which wraps StaplerRequest
- Loading branch information
Showing
12 changed files
with
94 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
src/main/java/org/jenkinsci/plugins/typetalk/webhookaction/WebhookParser.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/main/java/org/jenkinsci/plugins/typetalk/webhookaction/WebhookRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.jenkinsci.plugins.typetalk.webhookaction; | ||
|
||
import net.sf.json.JSONObject; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
|
||
public class WebhookRequest { | ||
|
||
private StaplerRequest req; | ||
private JSONObject json; | ||
|
||
WebhookRequest() { | ||
// for test | ||
} | ||
|
||
public WebhookRequest(StaplerRequest req) { | ||
this.req = req; | ||
parseBodyToJson(); | ||
} | ||
|
||
private void parseBodyToJson() { | ||
try { | ||
StringBuilder sb = new StringBuilder(); | ||
BufferedReader reader = req.getReader(); | ||
|
||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
sb.append(line).append('\n'); | ||
} | ||
|
||
json = JSONObject.fromObject(sb.toString()); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
} | ||
|
||
public String getRemoteAddr() { | ||
return req.getRemoteAddr(); | ||
} | ||
|
||
public int getPostId() { | ||
return json.getJSONObject("post").getInt("id"); | ||
} | ||
|
||
public String getPostMessage() { | ||
return json.getJSONObject("post").getString("message"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/org/jenkinsci/plugins/typetalk/webhookaction/executorimpl/HelpExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/org/jenkinsci/plugins/typetalk/webhookaction/executorimpl/ListExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
...ain/java/org/jenkinsci/plugins/typetalk/webhookaction/executorimpl/UndefinedExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters