summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2015-12-10 17:48:03 +0000
committerJoe Robinson <joe@lc8n.com>2015-12-10 17:48:03 +0000
commit89bf0102e1009b4184751776717dd183341d87ed (patch)
tree5185ce39da94e1295fc7ed85fb76926cf32e7970 /src
parente0a4ceb58b120d5f35faad077738a0dbb04552fa (diff)
Add basic gitlab controller for testing
Diffstat (limited to 'src')
-rw-r--r--src/main/java/uk/co/blatech/blaears/controllers/GitRelayController.java34
-rw-r--r--src/main/java/uk/co/blatech/blaears/models/gitlab/Commit.java44
-rw-r--r--src/main/java/uk/co/blatech/blaears/models/gitlab/Push.java55
-rw-r--r--src/main/java/uk/co/blatech/blaears/models/gitlab/Repository.java27
-rw-r--r--src/main/resources/templates/gitlab.vm10
5 files changed, 170 insertions, 0 deletions
diff --git a/src/main/java/uk/co/blatech/blaears/controllers/GitRelayController.java b/src/main/java/uk/co/blatech/blaears/controllers/GitRelayController.java
new file mode 100644
index 0000000..1fd9bc6
--- /dev/null
+++ b/src/main/java/uk/co/blatech/blaears/controllers/GitRelayController.java
@@ -0,0 +1,34 @@
+package uk.co.blatech.blaears.controllers;
+
+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 org.springframework.web.bind.annotation.RequestParam;
+import uk.co.blatech.blaears.models.gitlab.Push;
+
+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 GitRelayController {
+
+ @RequestMapping(value = "/gitlab", method = RequestMethod.PUT)
+ String relay(@RequestBody Push pushMsg, Model model){
+ try {
+ //DANGER
+ Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + pushMsg.getUserName() + " pushed to " + pushMsg.getRepository().getName() + " | 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/models/gitlab/Commit.java b/src/main/java/uk/co/blatech/blaears/models/gitlab/Commit.java
new file mode 100644
index 0000000..f5db061
--- /dev/null
+++ b/src/main/java/uk/co/blatech/blaears/models/gitlab/Commit.java
@@ -0,0 +1,44 @@
+package uk.co.blatech.blaears.models.gitlab;
+
+/**
+ * Model for a GitLab repository as contained in hook messages, to be converted from JSON
+ * See http://www.blatech.co.uk/help/web_hooks/web_hooks
+ */
+public class Commit {
+ String id;
+ String message;
+ String timestamp;
+ String url;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(String timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ 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/Push.java b/src/main/java/uk/co/blatech/blaears/models/gitlab/Push.java
new file mode 100644
index 0000000..bd8c961
--- /dev/null
+++ b/src/main/java/uk/co/blatech/blaears/models/gitlab/Push.java
@@ -0,0 +1,55 @@
+package uk.co.blatech.blaears.models.gitlab;
+
+/**
+ * Model for a GitLab Push message, to be converted from JSON
+ * See http://www.blatech.co.uk/help/web_hooks/web_hooks
+ */
+public class Push {
+
+ String objectKind;
+ String userName;
+ Repository repository;
+
+ Commit[] commits;
+ int totalCommitsCount;
+
+ public String getObjectKind() {
+ return objectKind;
+ }
+
+ public void setObjectKind(String objectKind) {
+ this.objectKind = objectKind;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public Repository getRepository() {
+ return repository;
+ }
+
+ public void setRepository(Repository repository) {
+ this.repository = repository;
+ }
+
+ public Commit[] getCommits() {
+ return commits;
+ }
+
+ public void setCommits(Commit[] commits) {
+ this.commits = commits;
+ }
+
+ public int getTotalCommitsCount() {
+ return totalCommitsCount;
+ }
+
+ public void setTotalCommitsCount(int totalCommitsCount) {
+ this.totalCommitsCount = totalCommitsCount;
+ }
+}
diff --git a/src/main/java/uk/co/blatech/blaears/models/gitlab/Repository.java b/src/main/java/uk/co/blatech/blaears/models/gitlab/Repository.java
new file mode 100644
index 0000000..0e1e26f
--- /dev/null
+++ b/src/main/java/uk/co/blatech/blaears/models/gitlab/Repository.java
@@ -0,0 +1,27 @@
+package uk.co.blatech.blaears.models.gitlab;
+
+/**
+ * Model for a GitLab repository as contained in hook messages, to be converted from JSON
+ * See http://www.blatech.co.uk/help/web_hooks/web_hooks
+ */
+public class Repository {
+ String name;
+ String url;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+}
diff --git a/src/main/resources/templates/gitlab.vm b/src/main/resources/templates/gitlab.vm
new file mode 100644
index 0000000..e3529fc
--- /dev/null
+++ b/src/main/resources/templates/gitlab.vm
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head lang="en">
+ <meta charset="UTF-8">
+ <title></title>
+</head>
+<body>
+ $body
+</body>
+</html> \ No newline at end of file