summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--config/log4j.properties6
-rw-r--r--pom.xml22
-rw-r--r--src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java18
-rw-r--r--src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java10
-rw-r--r--src/main/java/uk/co/blatech/blaears/models/gitlab/Merge.java20
-rw-r--r--src/main/java/uk/co/blatech/blaears/models/gitlab/ObjectAttributes.java18
7 files changed, 79 insertions, 18 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4ef6b74
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.idea/
+*.iml
+/target
diff --git a/config/log4j.properties b/config/log4j.properties
new file mode 100644
index 0000000..6b34072
--- /dev/null
+++ b/config/log4j.properties
@@ -0,0 +1,6 @@
+
+# Redirect log messages to console
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index ec69c63..6c169be 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,11 +33,30 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
<!-- Jackson JSON Mapper -->
@@ -46,6 +65,7 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
+
</dependencies>
<build>
diff --git a/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java b/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java
index 941633b..179caee 100644
--- a/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java
+++ b/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java
@@ -19,20 +19,28 @@ import java.io.IOException;
public class GitMergeController {
@RequestMapping(value = "/git/merge", method = RequestMethod.POST)
- String relay(@RequestBody Merge mergeMsg, Model model){
+ String merge(@RequestBody Merge mergeMsg, Model model){
try {
String action = "";
- if (mergeMsg.getObjectKind().equals("open")) {
+ if (mergeMsg.getObjectAttributes().getAction().equals("open")) {
action = " created a merge request from ";
- } else if (mergeMsg.getObjectKind().equals("merge")) {
+ } else if (mergeMsg.getObjectAttributes().getAction().equals("merge")) {
action = " merged from branch ";
} else {
- action = " did a " + mergeMsg.getObjectKind() + " from ";
+ action = " did a " + mergeMsg.getObjectAttributes().getAction() + " from ";
// return "gitlab";
}
+
+ String user = mergeMsg.getUser().getUsername();
+ String source = mergeMsg.getObjectAttributes().getSourceBranch();
+ String target = mergeMsg.getObjectAttributes().getTargetBranch();
+ String url = mergeMsg.getObjectAttributes().getUrl();
+ String title = mergeMsg.getObjectAttributes().getTitle();
+ String repo = mergeMsg.getRepository().getName();
//DANGER
- Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + mergeMsg.getUser().getUsername() + action + mergeMsg.getObjectAttributes().getSourceBranch() + " to " + mergeMsg.getObjectAttributes().getTargetBranch() + ": " + mergeMsg.getUrl() + " | bash /home/smsd/msgrelay.bash "});
+ Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + user + action + source + " to " + target + " on " + repo + ": [" + title + "] "+ url + " | bash /home/smsd/msgrelay.bash "});
+
model.addAttribute("result", "OK");
} catch (IOException e) {
System.out.println("Failed to run command");
diff --git a/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java b/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java
index 2e8020b..9d461c9 100644
--- a/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java
+++ b/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java
@@ -1,6 +1,7 @@
package uk.co.blatech.blaears.controllers;
import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
@@ -18,16 +19,21 @@ import java.io.IOException;
@Controller
public class GitPushController {
+ private static final Logger log = Logger.getLogger(GitPushController.class);
+
@RequestMapping(value = "/git/push", method = RequestMethod.POST)
- String relay(@RequestBody Push pushMsg, Model model){
+ String push(@RequestBody Push pushMsg, Model model){
try {
String commitMsg = "";
for (Commit commit: pushMsg.getCommits()) {
if (StringUtils.isNotEmpty(commitMsg)) {
commitMsg += ", ";
}
- commitMsg += commit.getMessage();
+ commitMsg += commit.getMessage().trim();
}
+
+ log.info("Received commits: " + commitMsg);
+
//DANGER
Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + pushMsg.getUserName() + " pushed to " + pushMsg.getRepository().getName() + ": "+ commitMsg + " | bash /home/smsd/msgrelay.bash "});
model.addAttribute("result", "OK");
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
index d8eaa99..2e1f0d9 100644
--- a/src/main/java/uk/co/blatech/blaears/models/gitlab/Merge.java
+++ b/src/main/java/uk/co/blatech/blaears/models/gitlab/Merge.java
@@ -11,8 +11,17 @@ public class Merge {
@JsonProperty("object_kind")
String objectKind;
User user;
+ @JsonProperty("object_attributes")
ObjectAttributes objectAttributes;
- String url;
+ Repository repository;
+
+ public Repository getRepository() {
+ return repository;
+ }
+
+ public void setRepository(Repository repository) {
+ this.repository = repository;
+ }
public String getObjectKind() {
return objectKind;
@@ -38,13 +47,4 @@ public class Merge {
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
index 63bc758..9c3a0c3 100644
--- a/src/main/java/uk/co/blatech/blaears/models/gitlab/ObjectAttributes.java
+++ b/src/main/java/uk/co/blatech/blaears/models/gitlab/ObjectAttributes.java
@@ -16,6 +16,8 @@ public class ObjectAttributes {
@JsonProperty("source_branch")
String sourceBranch;
String title;
+ String action;
+ String url;
public int getId() {
return id;
@@ -48,4 +50,20 @@ public class ObjectAttributes {
public void setTitle(String title) {
this.title = title;
}
+
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
}