This repository has been archived by the owner on Jun 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
149 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
utils = require("./utils") | ||
|
||
getMergeRequests = (gitlabClient, res, command) -> | ||
if (command.length == 3) | ||
projectId = command[2] | ||
gitlabClient.getMergeRequests(projectId,"") (err, response, body) -> | ||
utils.parseResult(res, err, response, returnMergeRequests, body) | ||
else if (command.length == 4) | ||
projectId = command[2] | ||
gitlabClient.getMergeRequests(projectId,command[3]) (err, response, body) -> | ||
utils.parseResult(res, err, response, returnMergeRequests, body) | ||
else if (command.length == 4) | ||
projectId = command[2] | ||
gitlabClient.getMergeRequests(projectId,command[3]) (err, response, body) -> | ||
utils.parseResult(res, err, response, returnMergeRequests, body) | ||
else if (command.length == 5 && command[3]=="accept") | ||
projectId = command[2] | ||
gitlabClient.acceptMergeRequest(projectId,command[4]) (err, response, body) -> | ||
utils.parseResult(res, err, response, confirmMergeRequest, body) | ||
else | ||
res.reply "Correct usage is gitlab merge requests \<projectId\> \<filter>\ (optional, e.g. state=opened) or gitlab merge requests \<projectId\> accept \<merge iid\>" | ||
return | ||
|
||
returnMergeRequests = (res, body)-> | ||
data = JSON.parse body | ||
merge_infos = utils.buildListInfo(data, formatMerge) | ||
res.reply "#{data.length} merge requests found" + '\n' + merge_infos.join('\n\n') | ||
|
||
|
||
formatMerge = (mergeRequest) -> | ||
"- id: #{mergeRequest.iid}, #{mergeRequest.title}, from #{mergeRequest.source_branch} to #{mergeRequest.target_branch}" + '\n' + " state: #{mergeRequest.state.toUpperCase()}, updated at \"#{mergeRequest.updated_at}\", author: #{mergeRequest.author.name}" + '\n' + " upvotes: #{mergeRequest.upvotes}, downvotes: #{mergeRequest.downvotes}" + '\n' + " #{mergeRequest.web_url}" | ||
|
||
confirmMergeRequest = (res, body)-> | ||
data = JSON.parse body | ||
res.reply "merge request #{data.iid} is now #{data.state}. See #{data.web_url}" | ||
|
||
|
||
|
||
module.exports = getMergeRequests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
Helper = require('hubot-test-helper') | ||
chai = require 'chai' | ||
expect = chai.expect | ||
nock = require('nock') | ||
co = require('co') | ||
|
||
helper = new Helper('../src/gitlab-connector.coffee') | ||
|
||
|
||
describe 'merge requests', -> | ||
beforeEach -> | ||
@room = helper.createRoom() | ||
nock.disableNetConnect | ||
nock('http://gitlab.com') | ||
.get('/api/v4/projects/123/merge_requests') | ||
.reply 200, '[{"iid":68, "title":"Merge 1", "upvotes":0,"downvotes":1,"target_branch":"acceptance","source_branch":"dev", "updated_at":"2018-01-04T16:04:54.598Z", "author":{"name":"Bob"},"web_url":"http://gitlab.com/toto/merge_requests/68", "state": "opened"},{"iid":78, "title":"Merge production","target_branch":"production","source_branch":"acceptance", "upvotes":3,"downvotes":0, "updated_at":"2018-01-05T16:04:54.598Z", "author":{"name":"Jack"},"web_url":"http://gitlab.com/toto/merge_requests/78", "state": "merged"}]' | ||
process.env.HUBOT_GITLAB_URL = "http://gitlab.com" | ||
process.env.HUBOT_GITLAB_TOKEN = "secretToken" | ||
co => | ||
@room.user.say('alice', '@hubot gitlab merge requests 123') | ||
new Promise((resolve, reject) -> | ||
setTimeout(resolve, 1000) | ||
) | ||
afterEach -> | ||
@room.destroy() | ||
nock.cleanAll() | ||
|
||
it 'responds to gitlab merge requests', -> | ||
expect(@room.messages).to.eql [ | ||
['alice', '@hubot gitlab merge requests 123'] | ||
['hubot', | ||
'@alice 2 merge requests found\n- id: 68, Merge 1, from dev to acceptance\n state: OPENED, updated at \"2018-01-04T16:04:54.598Z\", author: Bob\n upvotes: 0, downvotes: 1\n http://gitlab.com/toto/merge_requests/68\n\n- id: 78, Merge production, from acceptance to production\n state: MERGED, updated at "2018-01-05T16:04:54.598Z", author: Jack\n upvotes: 3, downvotes: 0\n http://gitlab.com/toto/merge_requests/78'] | ||
] | ||
|
||
|
||
describe 'merge requests with filter', -> | ||
beforeEach -> | ||
@room = helper.createRoom() | ||
nock.disableNetConnect | ||
nock('http://gitlab.com') | ||
.get('/api/v4/projects/123/merge_requests?state=closed') | ||
.reply 200, '[{"iid":68, "title":"Merge 1", "upvotes":0,"downvotes":1,"target_branch":"acceptance","source_branch":"dev", "updated_at":"2018-01-04T16:04:54.598Z", "author":{"name":"Bob"},"web_url":"http://gitlab.com/toto/merge_requests/68", "state": "closed"},{"iid":78, "title":"Merge production","target_branch":"production","source_branch":"acceptance", "upvotes":3,"downvotes":0, "updated_at":"2018-01-05T16:04:54.598Z", "author":{"name":"Jack"},"web_url":"http://gitlab.com/toto/merge_requests/78", "state": "closed"}]' | ||
process.env.HUBOT_GITLAB_URL = "http://gitlab.com" | ||
process.env.HUBOT_GITLAB_TOKEN = "secretToken" | ||
co => | ||
@room.user.say('alice', '@hubot gitlab merge requests 123 state=closed') | ||
new Promise((resolve, reject) -> | ||
setTimeout(resolve, 1000) | ||
) | ||
afterEach -> | ||
@room.destroy() | ||
nock.cleanAll() | ||
|
||
it 'responds to gitlab merge requests', -> | ||
expect(@room.messages).to.eql [ | ||
['alice', '@hubot gitlab merge requests 123 state=closed'] | ||
['hubot', | ||
'@alice 2 merge requests found\n- id: 68, Merge 1, from dev to acceptance\n state: CLOSED, updated at \"2018-01-04T16:04:54.598Z\", author: Bob\n upvotes: 0, downvotes: 1\n http://gitlab.com/toto/merge_requests/68\n\n- id: 78, Merge production, from acceptance to production\n state: CLOSED, updated at "2018-01-05T16:04:54.598Z", author: Jack\n upvotes: 3, downvotes: 0\n http://gitlab.com/toto/merge_requests/78'] | ||
] | ||
|
||
|
||
describe 'merge requests: accept', -> | ||
beforeEach -> | ||
@room = helper.createRoom() | ||
nock.disableNetConnect | ||
nock('http://gitlab.com') | ||
.put('/api/v4/projects/123/merge_requests/68/merge') | ||
.reply 200, '{"iid":68, "title":"Merge 1", "upvotes":0,"downvotes":1,"target_branch":"acceptance","source_branch":"dev", "updated_at":"2018-01-04T16:04:54.598Z", "author":{"name":"Bob"},"web_url":"http://gitlab.com/toto/merge_requests/68", "state": "merged"}' | ||
process.env.HUBOT_GITLAB_URL = "http://gitlab.com" | ||
process.env.HUBOT_GITLAB_TOKEN = "secretToken" | ||
co => | ||
@room.user.say('alice', '@hubot gitlab merge requests 123 accept 68') | ||
new Promise((resolve, reject) -> | ||
setTimeout(resolve, 1000) | ||
) | ||
afterEach -> | ||
@room.destroy() | ||
nock.cleanAll() | ||
|
||
it 'responds to gitlab merge requests', -> | ||
expect(@room.messages).to.eql [ | ||
['alice', '@hubot gitlab merge requests 123 accept 68'] | ||
['hubot', | ||
'@alice merge request 68 is now merged. See http://gitlab.com/toto/merge_requests/68'] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters