Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Commit

Permalink
add undefined check
Browse files Browse the repository at this point in the history
  • Loading branch information
oltruong committed Jan 10, 2018
1 parent f763a67 commit 9c9900c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ deploy:
skip_cleanup: true
api_key:
secure: UQ710bDILz7B+GKtlFNY/u4jgccy+m2W+ZevAFGzsTedxAMybR6HtOCForrl5G2jUduyirCYR5u10COI/E7qrwDM/aXhC6jrCiHsb4Syhbn3S5F+sLOpiSCRfb++JGbs5urLY8JtOMDyxsn6XYiOHnx8A4cVI78PXcCotC5YZz7WPYPuT1w23qcHC6XFdSuAsJ+khYHVeXxjytmW7uYF6AtuRIwj+H3g+xzUVdUYF+L3T95nQw+0Q3ADlHJpJUUo+Jvp87e2ljYhzORQWKJ35/t3I0eR3VNIAQ71W5qkW0e/bOoE1Zd/zKxx7z8yDLCXLBrUDz/1QtzDZBn17JwsJlAOxTAIvo/kdQj8xepl0vCBFKUqF+FP8aqvZmxvAv05WKskn7DZ2z17CncizLe8T4xoGnXFPbdQGya7dg3Njw0+EKByVWfk24qCcH8i7J2NLH3yEeuTWiyMLbJRYxSOa6U34Oc5ODLp6lsWFQWkZWcd1AGNu5WsK9iMnR8i5BwFE/owV1aHaHK3Nmw6vfL9oPuS+dLoIhLnRxnopHksgp2AAHKcI/nLWvZ3HXVtzS+4eAhZwC2tJHhGlBJdnXuIEqyi835OYoZaT3NcQDWAhMAxm1/uKMf23U0QK4YUm76BqxWFBbNcCYxxJ9Ao1yFJj7RT1RhYw18fk9kHA4i/kss=
file: hubot-gitlab-connector-0.0.7.tgz
file: hubot-gitlab-connector-0.0.8.tgz
on:
repo: oltruong/hubot-gitlab-connector
tags: true
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hubot-gitlab-connector",
"description": "A hubot script that communicates with Gitlab API",
"version": "0.0.7",
"version": "0.0.8",
"author": "Olivier Truong <[email protected]>",
"license": "MIT",
"keywords": "hubot, hubot-scripts, gitlab",
Expand Down
15 changes: 8 additions & 7 deletions src/parser-branch.coffee
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
utils = require("./utils")

getBranches = (gitlabClient, res, command) ->
if (command.length != 2)
res.reply "Correct usage is gitlab branches \<projectId\>"
return
projectId = command[1]
gitlabClient.getBranches(projectId) (err, response, body) ->
utils.parseResult(res, err, response, returnBranches,body)
if (gitlabClient? && res? && command?)
if (command.length != 2)
res.reply "Correct usage is gitlab branches \<projectId\>"
return
projectId = command[1]
gitlabClient.getBranches(projectId) (err, response, body) ->
utils.parseResult(res, err, response, returnBranches, body)

returnBranches = (res, body)->
data = JSON.parse body
branch_infos = utils.buildListInfo(data, formatBranch)
branch_infos = utils.buildListInfo(data, formatBranch)
res.reply "#{data.length} branches found" + '\n' + branch_infos.join('\n\n')


Expand Down
38 changes: 19 additions & 19 deletions src/parser-merge-requests.coffee
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
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\>"
if (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)->
Expand All @@ -35,5 +36,4 @@ confirmMergeRequest = (res, body)->
res.reply "merge request #{data.iid} is now #{data.state}. See #{data.web_url}"



module.exports = getMergeRequests
17 changes: 8 additions & 9 deletions src/parser-pipeline.coffee
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
utils = require("./utils")

createPipeline = (gitlabClient, res, command) ->
if (command.length != 4 || command[1] != 'trigger')
res.reply "Correct usage is gitlab pipeline trigger \<projectId\> \<branch\> "
return

projectId = command[2]
branchName = command[3]

gitlabClient.getProject(projectId) (err, response, body) ->
utils.parseResult(res, err, response, findBranches, body, gitlabClient, branchName)
if (gitlabClient? && res? && command?)
if (command.length != 4 || command[1] != 'trigger')
res.reply "Correct usage is gitlab pipeline trigger \<projectId\> \<branch\> "
return
projectId = command[2]
branchName = command[3]
gitlabClient.getProject(projectId) (err, response, body) ->
utils.parseResult(res, err, response, findBranches, body, gitlabClient, branchName)


findBranches = (res, body, gitlabClient, branchName, projectId) ->
Expand Down
23 changes: 12 additions & 11 deletions src/parser-project.coffee
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
utils = require("./utils")

getProjects = (gitlabClient, res, command) ->
if (command.length == 1)
gitlabClient.getProjects() (err, response, body) ->
readProjects(res, err, response, body)
else if (command.length == 2)
searchName = command[1]
gitlabClient.getProjectsByName(searchName) (err, response, body) ->
readProjects(res, err, response, body)
else
res.reply "Correct usage is 'gitlab projects' or gitlab projects \<searchName\>'"
return
if (gitlabClient? && res? && command?)
if (command.length == 1)
gitlabClient.getProjects() (err, response, body) ->
readProjects(res, err, response, body)
else if (command.length == 2)
searchName = command[1]
gitlabClient.getProjectsByName(searchName) (err, response, body) ->
readProjects(res, err, response, body)
else
res.reply "Correct usage is 'gitlab projects' or gitlab projects \<searchName\>'"
return

readProjects = (res, err, response, body)->
utils.parseResult(res, err, response, returnProject,body)
utils.parseResult(res, err, response, returnProject, body)


returnProject = (res, body)->
Expand Down
5 changes: 3 additions & 2 deletions src/parser-version.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
utils = require("./utils")

getVersion = (gitlabClient, res) ->
gitlabClient.getVersion() (err, response, body)->
utils.parseResult(res, err, response, readVersion,body)
if (gitlabClient? && res?)
gitlabClient.getVersion() (err, response, body)->
utils.parseResult(res, err, response, readVersion, body)

readVersion = (res, body)->
data = JSON.parse body
Expand Down

0 comments on commit 9c9900c

Please sign in to comment.