我一直在尝试让我的hubot实例在来自http侦听器的回调中执行http请求时遇到问题。我的猜测是它处于req / res周期的中间,无法完成不同的请求。通常机器人对象有一个允许发送一个的http方法,但我一直得到“未定义的'TypeError:无法读取属性'”在我见过的其他hubot示例中,它们指的是响应对象的使用,但这只是聊天监听器内部的情况,实际上当我尝试使用响应对象时,它会抛出一个错误,“TypeError:res.http不是一个函数”。任何帮助深表感谢。谢谢!
robot.router.post '/gitlab-incoming', (req, res) ->
data = {
"request_type": req.body.object_kind,
"status": req.body.object_attributes.state,
"project_name": req.body.object_attributes.source.name,
"branch_name": req.body.object_attributes.source_branch,
"job_name": 'review_stop',
"team_name": process.env.GITLAB_TEAM_NAME,
"gitlab_ci_token": process.env.GITLAB_CI_TOKEN,
"action": 'play',
"project_id": "#{process.env.GITLAB_TEAM_NAME}%2F#{req.body.object_attributes.source.name}"
}
if data['status'] == 'merged'
robot.http("https://gitlab.com/api/v4/projects/#{data['project_id']}/jobs")
.header('Accept', 'application/json')
.header('PRIVATE-TOKEN', data['gitlab_ci_token'])
.get() (err, http_res, body) ->
if err
res.send 'Sorry. Unable to fetch the list of jobs from Gitlab'
job_found = false
job_id = undefined