From 73f847f9ef7dd7ae06b39a4a75540fed39392d5c Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 10 Dec 2015 23:41:12 +0000 Subject: Assign properties to variables to debug --- .../java/uk/co/blatech/blaears/controllers/GitMergeController.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 09c7134..e8d521a 100644 --- a/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java +++ b/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java @@ -31,8 +31,13 @@ public class GitMergeController { action = " did a " + mergeMsg.getObjectKind() + " from "; // return "gitlab"; } + + String user = mergeMsg.getUser().getUsername(); + String source = mergeMsg.getObjectAttributes().getSourceBranch(); + String target = mergeMsg.getObjectAttributes().getTargetBranch(); + String url = mergeMsg.getUrl(); //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 + ": " + url + " | bash /home/smsd/msgrelay.bash "}); model.addAttribute("result", "OK"); } catch (IOException e) { System.out.println("Failed to run command"); -- cgit v1.2.3 From fb9d381938d026cfcca564f64d795a832486165e Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 10 Dec 2015 23:51:48 +0000 Subject: Add annotation to fix object attributes --- src/main/java/uk/co/blatech/blaears/models/gitlab/Merge.java | 1 + 1 file changed, 1 insertion(+) 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..18c910d 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,6 +11,7 @@ public class Merge { @JsonProperty("object_kind") String objectKind; User user; + @JsonProperty("object_attributes") ObjectAttributes objectAttributes; String url; -- cgit v1.2.3 From 251a5821bb590e7f71d68615b6d7cc4ebf124ca1 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 10 Dec 2015 23:58:58 +0000 Subject: Move URL to object attributes, add title --- .../blaears/controllers/GitMergeController.java | 11 ++++++----- .../uk/co/blatech/blaears/models/gitlab/Merge.java | 10 ---------- .../blaears/models/gitlab/ObjectAttributes.java | 18 ++++++++++++++++++ 3 files changed, 24 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 8752401..b33b075 100644 --- a/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java +++ b/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java @@ -23,21 +23,22 @@ public class GitMergeController { 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.getUrl(); + String url = mergeMsg.getObjectAttributes().getUrl(); + String title = mergeMsg.getObjectAttributes().getUrl(); //DANGER - Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + user + action + source + " to " + target + ": " + url + " | bash /home/smsd/msgrelay.bash "}); + Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + user + action + source + " to " + target + ": [" + title + "] "+ url + " | bash /home/smsd/msgrelay.bash "}); model.addAttribute("result", "OK"); } catch (IOException e) { 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 18c910d..ced162c 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 @@ -13,7 +13,6 @@ public class Merge { User user; @JsonProperty("object_attributes") ObjectAttributes objectAttributes; - String url; public String getObjectKind() { return objectKind; @@ -39,13 +38,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; + } } -- cgit v1.2.3 From 4c06810ef15a522f7131bbc230e5105a2e8a9f8e Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 11 Dec 2015 00:05:13 +0000 Subject: Add repository name to merge message --- .../uk/co/blatech/blaears/controllers/GitMergeController.java | 5 +++-- src/main/java/uk/co/blatech/blaears/models/gitlab/Merge.java | 9 +++++++++ 2 files changed, 12 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 index b33b075..d5cabaf 100644 --- a/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java +++ b/src/main/java/uk/co/blatech/blaears/controllers/GitMergeController.java @@ -36,9 +36,10 @@ public class GitMergeController { String source = mergeMsg.getObjectAttributes().getSourceBranch(); String target = mergeMsg.getObjectAttributes().getTargetBranch(); String url = mergeMsg.getObjectAttributes().getUrl(); - String title = mergeMsg.getObjectAttributes().getUrl(); + String title = mergeMsg.getObjectAttributes().getTitle(); + String repo = mergeMsg.getRepository().getName(); //DANGER - Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + user + action + source + " to " + target + ": [" + title + "] "+ url + " | 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) { 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 ced162c..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 @@ -13,6 +13,15 @@ public class Merge { User user; @JsonProperty("object_attributes") ObjectAttributes objectAttributes; + Repository repository; + + public Repository getRepository() { + return repository; + } + + public void setRepository(Repository repository) { + this.repository = repository; + } public String getObjectKind() { return objectKind; -- cgit v1.2.3 From 4cca5fdada19f93039ddef9a910a43f09a7634b2 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 11 Dec 2015 00:15:15 +0000 Subject: Debug message --- .../java/uk/co/blatech/blaears/controllers/GitMergeController.java | 2 +- .../java/uk/co/blatech/blaears/controllers/GitPushController.java | 4 +++- 2 files changed, 4 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 index d5cabaf..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,7 +19,7 @@ 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 = ""; 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..b3563cd 100644 --- a/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java +++ b/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java @@ -19,7 +19,7 @@ import java.io.IOException; public class GitPushController { @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()) { @@ -28,6 +28,8 @@ public class GitPushController { } commitMsg += commit.getMessage(); } + Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom beep | bash /home/smsd/msgrelay.bash "}); + //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"); -- cgit v1.2.3 From 3c9d15ce7de4bb919a1933682ef799c36c40b72d Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 11 Dec 2015 00:16:01 +0000 Subject: Debug message --- src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java | 1 + 1 file changed, 1 insertion(+) 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 b3563cd..c8c39d0 100644 --- a/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java +++ b/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java @@ -29,6 +29,7 @@ public class GitPushController { commitMsg += commit.getMessage(); } Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom beep | bash /home/smsd/msgrelay.bash "}); + Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + commitMsg + " | bash /home/smsd/msgrelay.bash "}); //DANGER Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + pushMsg.getUserName() + " pushed to " + pushMsg.getRepository().getName() + ": "+ commitMsg + " | bash /home/smsd/msgrelay.bash "}); -- cgit v1.2.3 From 9352a6048cff723220cd022591d93f9ccd2eb814 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 11 Dec 2015 00:31:03 +0000 Subject: Add log4j for logging --- config/log4j.properties | 6 ++++++ pom.xml | 11 +++++++++++ .../uk/co/blatech/blaears/controllers/GitPushController.java | 5 ++++- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 config/log4j.properties 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..50b836d 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,16 @@ org.springframework.boot spring-boot-starter-test test + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-log4j @@ -46,6 +56,7 @@ jackson-databind ${jackson.version} + 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 c8c39d0..825ce8f 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,6 +19,8 @@ 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 push(@RequestBody Push pushMsg, Model model){ try { @@ -28,8 +31,8 @@ public class GitPushController { } commitMsg += commit.getMessage(); } + log.info(commitMsg); Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom beep | bash /home/smsd/msgrelay.bash "}); - Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + commitMsg + " | bash /home/smsd/msgrelay.bash "}); //DANGER Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom " + pushMsg.getUserName() + " pushed to " + pushMsg.getRepository().getName() + ": "+ commitMsg + " | bash /home/smsd/msgrelay.bash "}); -- cgit v1.2.3 From 71c4e0a0ca19e5437c382a970d96fb94c6c9abca Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 11 Dec 2015 00:43:41 +0000 Subject: Fixes for log4j --- pom.xml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 50b836d..6c169be 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,16 @@ org.springframework.boot spring-boot-starter-web - + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-logging + + + org.springframework.boot spring-boot-starter-test -- cgit v1.2.3 From 8950c5e28033b0abdf65c67a8c5bf0de8a833d63 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 11 Dec 2015 00:46:06 +0000 Subject: Trim commit message to avoid newlines --- src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 825ce8f..eb5ff74 100644 --- a/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java +++ b/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java @@ -29,8 +29,9 @@ public class GitPushController { if (StringUtils.isNotEmpty(commitMsg)) { commitMsg += ", "; } - commitMsg += commit.getMessage(); + commitMsg += commit.getMessage().trim(); } + log.info(commitMsg); Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom beep | bash /home/smsd/msgrelay.bash "}); -- cgit v1.2.3 From 342336f51c2e714f12238cf272127ac608a11409 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 11 Dec 2015 01:03:18 +0000 Subject: Remove debug output --- src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 eb5ff74..9d461c9 100644 --- a/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java +++ b/src/main/java/uk/co/blatech/blaears/controllers/GitPushController.java @@ -32,8 +32,7 @@ public class GitPushController { commitMsg += commit.getMessage().trim(); } - log.info(commitMsg); - Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo theblueroom beep | bash /home/smsd/msgrelay.bash "}); + 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 "}); -- cgit v1.2.3 From 3b649e6855ea849808473349f8213f1304f0c92a Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 11 Dec 2015 01:04:51 +0000 Subject: Add .gitignore to ignore IDE files and compiled classes --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ef6b74 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +*.iml +/target -- cgit v1.2.3