Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
hubot-gitlab mearge request review
https = require('https')
random = require('hubot').Response::random
BASE_URL = 'https://slack.com/api/chat.postMessage?token=xxxx-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxx-xxxxxxx' #replace your Slack API key!
members = [ #replae and add your team members!
'aaa',
'bbb',
'ccc',
'ddd'
]
module.exports = (robot) ->
robot.router.post '/hubot/gitlab', (req, res) ->
channel = "%23test" # replace team name!
json = req.body
if not json
res.end ""
return
gitlab_event = "#{json.object_kind}" || 'push'
if gitlab_event is "merge_request" and json.object_attributes.state is "opened"
merge_request json, channel
res.end()
merge_request = (json, channel) ->
title = "#{json.object_attributes.title}"
description = "#{json.object_attributes.description}"
iid = "#{json.object_attributes.iid}"
update_time = "#{json.object_attributes.updated_at}"
namespace = "#{json.object_attributes.source.namespace}".toLowerCase()
name = "#{json.object_attributes.source.name}".toLowerCase()
url = "http://10.13.0.6/#{namespace}/#{name}/merge_requests/#{iid}" # replace your GitLab URL!
assignee = random members
message = """
Merge Request was created at #{update_time}.
#{title}
#{description}
#{url}
@#{assignee}: レビューお願いしやす。
"""
url = BASE_URL + 'channel=' + channel + '&text=' + encodeURIComponent(message) + '&link_names=1'
console.log(url)
robot.http(url).get() (err, res, body) ->
console.log body
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment