From 683b32a7155418e1c03e53d79fe7aacd9a723999 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 23 Jun 2016 22:09:56 +0200 Subject: [PATCH 1/6] Add project name for merge requests; --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 8c4f986..b1e546d 100644 --- a/index.js +++ b/index.js @@ -65,6 +65,8 @@ var handlers = { var request = body.object_attributes; + var projectName = request.target.name; + var from = request.source_branch; var to = request.target_branch; From 9d31b30444e76fc1278dabd9fa12c2479eb51851 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 23 Jun 2016 22:14:37 +0200 Subject: [PATCH 2/6] Add diagnostic and CI; --- .gitlab-ci.yml | 4 ++++ index.js | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..283d918 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,4 @@ +image: ubuntu:latest + +before_script: + - echo "Hello world!" diff --git a/index.js b/index.js index b1e546d..8694cbe 100644 --- a/index.js +++ b/index.js @@ -94,6 +94,8 @@ app.post('/', function(req, res) { var msgs = null; if (body.object_kind && handlers[body.object_kind]) msgs = handlers[body.object_kind](body); + else + console.log("Unexpected object_kind:", body.object_kind); if (msgs) { if (msgs instanceof Array) { From 94cb421a29ce08698377a7239196f582b1e1baaa Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 23 Jun 2016 22:15:45 +0200 Subject: [PATCH 3/6] You had one job! --- .gitlab-ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 283d918..5a20fbd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,5 @@ image: ubuntu:latest -before_script: - - echo "Hello world!" +job: + script: + - echo "Hello world!" From cf6492970dbb134e96861c8c1f0b6ce38d5c39da Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 23 Jun 2016 22:21:04 +0200 Subject: [PATCH 4/6] Add messaging for build; --- index.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 8694cbe..f909bbc 100644 --- a/index.js +++ b/index.js @@ -81,9 +81,22 @@ var handlers = { }, build: function(body) { - console.log('build event NYI because not documented'); - console.log(body); - return null; + + var id = body.build_id; + var status = body.build_status; + + var isFinished = body.build_finished_at !== null; + var duration = body.build_duration; + + var projectName = body.project_name; + var stage = body.build_stage; + + var msg = []; + msg.push(projectName + ': build #' + id + ' (' + stage + ') changed status: ' + status); + if (isFinished) + msg.push('build finished in ' + duration + ' seconds. '); + + return msg; } }; From bda1e25f5eb9f60160f7ea3a59d7d8e137f3acec Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 23 Jun 2016 22:25:26 +0200 Subject: [PATCH 5/6] Subtle bug is subtle; --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index f909bbc..62817ea 100644 --- a/index.js +++ b/index.js @@ -78,6 +78,8 @@ var handlers = { var msg = [projectName + ': merge request (' + from + ':' + to + ') #' + id + ' has changed state ("' + state + '")']; msg.push(title); msg.push(url); + + return msg; }, build: function(body) { From e6013e04c65f2c0418cc623f08ca791c694177f4 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 23 Jun 2016 22:26:52 +0200 Subject: [PATCH 6/6] Be more concise; --- index.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 62817ea..c68ab92 100644 --- a/index.js +++ b/index.js @@ -35,8 +35,7 @@ var handlers = { if (commits.length < 4) { msg = msg.concat(commits.map(formatCommit)); } else { - msg.push(formatCommit(commits[0])); - msg.push('...'); + msg.push(formatCommit(commits[0]) + ' ...'); msg.push(formatCommit(commits[commits.length - 1])); } @@ -54,8 +53,7 @@ var handlers = { var url = issue.url; var msg = [projectName + ': issue #' + issueNumber + ' has changed state ("' + issueState + '")']; - msg.push(issueTitle); - msg.push(url); + msg.push(issueTitle + ' ' + url); return msg; }, @@ -76,8 +74,7 @@ var handlers = { var state = request.state; var msg = [projectName + ': merge request (' + from + ':' + to + ') #' + id + ' has changed state ("' + state + '")']; - msg.push(title); - msg.push(url); + msg.push(title + ' ' + url); return msg; },