summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java44
-rw-r--r--src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java (renamed from src/main/java/uk/co/blatech/blaears/controllers/GitRelayController.java)4
-rw-r--r--src/main/java/uk/co/blatech/blaears/models/gitlab/Merge.java50
-rw-r--r--src/main/java/uk/co/blatech/blaears/models/gitlab/ObjectAttributes.java45
-rw-r--r--src/main/java/uk/co/blatech/blaears/models/gitlab/User.java29
5 files changed, 170 insertions, 2 deletions
diff --git a/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java b/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java
new file mode 100644
index 0000000..5622aea
--- /dev/null
+++ b/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java
@@ -0,0 +1,44 @@
+package uk.co.blatech.blaears.controllers;
+
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import uk.co.blatech.blaears.models.gitlab.Commit;
+import uk.co.blatech.blaears.models.gitlab.Merge;
+
+import java.io.IOException;
+
+/**
+ * Takes messages sent by GitLab and sends them to IRC
+ * Currently just testing to see what we get
+ */
+@Controller
+public class GitMergeController {
+
+ @RequestMapping(value = "/git/merge", method = RequestMethod.POST)
+ String relay(@RequestBody Merge mergeMsg, Model model){
+ try {
+ String action = "";
+
+ if (mergeMsg.getObjectKind().equals("open")) {
+ action = " created a merge request from ";
+ } else if (mergeMsg.getObjectKind().equals("merge")) {
+ action = " merged from branch ";
+ } else {
+ return "gitlab";
+ }
+ //DANGER
+ Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + mergeMsg.getUser().getUserName()+ " created a merge request from " + mergeMsg.getObjectAttributes().getSourceBranch() + " to " + mergeMsg.getObjectAttributes().getTargetBranch() + ": " + mergeMsg.getUrl() + " | bash /home/smsd/msgrelay.bash "});
+ model.addAttribute("result", "OK");
+ } catch (IOException e) {
+ System.out.println("Failed to run command");
+ e.printStackTrace();
+ model.addAttribute("result", "failed");
+ }
+ return "gitlab";
+ }
+
+}
diff --git a/src/main/java/uk/co/blatech/blaears/controllers/GitRelayController.java b/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java
index 256d5fa..85592c8 100644
--- a/src/main/java/uk/co/blatech/blaears/controllers/GitRelayController.java
+++ b/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java
@@ -16,9 +16,9 @@ import java.io.IOException;
* Currently just testing to see what we get
*/
@Controller
-public class GitRelayController {
+public class GitPushController {
- @RequestMapping(value = "/gitlab", method = RequestMethod.POST)
+ @RequestMapping(value = "/git/push", method = RequestMethod.POST)
String relay(@RequestBody Push pushMsg, Model model){
try {
String commitMsg = "";
diff --git a/src/main/java/uk/co/blatech/blaears/models/gitlab/Merge.java b/src/main/java/uk/co/blatech/blaears/models/gitlab/Merge.java
new file mode 100644
index 0000000..d8eaa99
--- /dev/null
+++ b/src/main/java/uk/co/blatech/blaears/models/gitlab/Merge.java
@@ -0,0 +1,50 @@
+package uk.co.blatech.blaears.models.gitlab;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Model for a GitLab Push message, to be converted from JSON
+ * See http://www.blatech.co.uk/help/web_hooks/web_hooks
+ */
+public class Merge {
+
+ @JsonProperty("object_kind")
+ String objectKind;
+ User user;
+ ObjectAttributes objectAttributes;
+ String url;
+
+ public String getObjectKind() {
+ return objectKind;
+ }
+
+ public void setObjectKind(String objectKind) {
+ this.objectKind = objectKind;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ public ObjectAttributes getObjectAttributes() {
+ return objectAttributes;
+ }
+
+ public void setObjectAttributes(ObjectAttributes objectAttributes) {
+ this.objectAttributes = objectAttributes;
+ }
+
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+}
diff --git a/src/main/java/uk/co/blatech/blaears/models/gitlab/ObjectAttributes.java b/src/main/java/uk/co/blatech/blaears/models/gitlab/ObjectAttributes.java
new file mode 100644
index 0000000..8c679d7
--- /dev/null
+++ b/src/main/java/uk/co/blatech/blaears/models/gitlab/ObjectAttributes.java
@@ -0,0 +1,45 @@
+package uk.co.blatech.blaears.models.gitlab;
+
+/**
+ * Model for a GitLab object_attribute which is used in various hook messages, to be converted from JSON
+ * See http://www.blatech.co.uk/help/web_hooks/web_hooks
+ */
+public class ObjectAttributes {
+
+ int id;
+ String targetBranch;
+ String sourceBranch;
+ String title;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTargetBranch() {
+ return targetBranch;
+ }
+
+ public void setTargetBranch(String targetBranch) {
+ this.targetBranch = targetBranch;
+ }
+
+ public String getSourceBranch() {
+ return sourceBranch;
+ }
+
+ public void setSourceBranch(String sourceBranch) {
+ this.sourceBranch = sourceBranch;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+}
diff --git a/src/main/java/uk/co/blatech/blaears/models/gitlab/User.java b/src/main/java/uk/co/blatech/blaears/models/gitlab/User.java
new file mode 100644
index 0000000..8403d83
--- /dev/null
+++ b/src/main/java/uk/co/blatech/blaears/models/gitlab/User.java
@@ -0,0 +1,29 @@
+package uk.co.blatech.blaears.models.gitlab;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Model for a GitLab User as sent by hooks, to be converted from JSON
+ * See http://www.blatech.co.uk/help/web_hooks/web_hooks
+ */
+public class User {
+ String name;
+ @JsonProperty("user_name")
+ String userName;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+}