summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java38
1 files changed, 23 insertions, 15 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
index dc65f12..b5e9df9 100644
--- a/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java
+++ b/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java
@@ -1,12 +1,11 @@
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;
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;
@@ -18,33 +17,42 @@ import java.io.IOException;
@Controller
public class GitMergeController {
+ private static final Logger log = Logger.getLogger(GitMergeController.class);
+
@RequestMapping(value = "/git/merge", method = RequestMethod.POST)
String merge(@RequestBody Merge mergeMsg, Model model){
try {
- String action = "";
-
- if (mergeMsg.getObjectAttributes().getAction().equals("open")) {
- action = " created a merge request from ";
- } else if (mergeMsg.getObjectAttributes().getAction().equals("merge")) {
- action = " merged from branch ";
- } else if (!mergeMsg.getObjectAttributes().getAction().equals("update")){
- action = " did a " + mergeMsg.getObjectAttributes().getAction() + " from ";
- } else {
- return "gitlab";
- }
+ String action = mergeMsg.getObjectAttributes().getAction();
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();
+
+ log.info ("Received a merge " + action + " by " + user + " from " + source + " to " + target + ", " + title + " " + url);
+ String actionTxt = "";
+
+ if (action.equals("open")) {
+ actionTxt = " created a merge request from ";
+ } else if (action.equals("merge")) {
+ actionTxt = " merged from branch ";
+ } else if (!action.equals("update")){
+ actionTxt = " did a " + mergeMsg.getObjectAttributes().getAction() + " from ";
+ } else {
+ log.info ("Dropping update message");
+ return "gitlab";
+ }
+
+ String command = "echo theblueroom " + user + actionTxt + source + " to " + target + " on " + repo + ": [" + title + "] "+ url + " | bash /home/smsd/msgrelay.bash ";
+ log.info("Running command: " + command);
//DANGER
- Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + user + action + source + " to " + target + " on " + repo + ": [" + title + "] "+ url + " | bash /home/smsd/msgrelay.bash "});
+ Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", command});
model.addAttribute("result", "OK");
} catch (IOException e) {
- System.out.println("Failed to run command");
+ log.error("Failed to run command");
e.printStackTrace();
model.addAttribute("result", "failed");
}