nazrhyn / gitlab-slack

A service that receives hook notifications from GitLab and posts information to an incoming webhook on Slack.
MIT License
79 stars 20 forks source link

StatusCodeError: 500 - undefined #19

Closed icougil closed 8 years ago

icougil commented 8 years ago

Hi! I'm trying to use your project integrating gitlab with Slack, and I've receive a 500 error after trying to make a test webhook inside the Gitlab project /yourproject/hooks. So, here is the trace I've found in the logfile:

[2016-07-15T11:48:23.218Z](DEBUG) xx.xx.xx.98 POST -- DATA: {"object_kind":"push","event_name":"push","before":"3ebffceb071611684f8143272febfe871ca69736","after":"ca1ef66dbb057f7689922919255b001bb5e3ee1b","ref":"refs/heads/development","checkout_sha":"ca1ef66dbb057f7689922919255b001bb5e3ee1b","message":null,"user_id":392556,................"git_http_url":"https://gitlab.com/xxxxx/ourproject.git","git_ssh_url":"git@gitlab.com:xxxxx/ourproject.git","visibility_level":0}}
[2016-07-15T11:48:23.219Z](DEBUG) xx.xx.xx.98 POST -- PROCESS: Commit
[2016-07-15T11:48:24.184Z](ERROR) xx.xx.xx.98 POST -- GITLAB: -- StatusCodeError: 500 - undefined    at new StatusCodeError (/opt/gitlab-slack/node_modules/request-promise/lib/errors.js:26:15)
    at Request.RP$callback [as _callback] (/opt/gitlab-slack/node_modules/request-promise/lib/rp.js:68:32)
    at Request.self.callback (/opt/gitlab-slack/node_modules/request-promise/node_modules/request/request.js:187:22)
    at Request.emit (events.js:98:17)
    at Request.<anonymous> (/opt/gitlab-slack/node_modules/request-promise/node_modules/request/request.js:1044:10)
    at Request.emit (events.js:95:17)
    at IncomingMessage.<anonymous> (/opt/gitlab-slack/node_modules/request-promise/node_modules/request/request.js:965:12)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:944:16
    at process._tickCallback (node.js:448:13)

Btw, I've checked that the simple request it has worked properly: curl -X POST --data-urlencode 'payload={"channel": "#gitlab", "username": "webhookbot", "text": "This is posted to #gitlab and comes from a bot named webhookbot.", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/xxxxxxx

What we can do? Best,

nazrhyn commented 8 years ago

Hey there.

While I was thinking about your issue this morning, I realized that my README doesn't say anything about the requirements of the gitlab.api.token in the config.json. I use it to query these APIs:

And, if you have issue label tracking enabled:

I would expect GitLab to return a 403 if that token can't do any of those things, but who knows. Outside of that possibility, looks like one of the requests to GitLab for more information is failing before it gets a response. (The POST -- GITLAB ties it down to coming from the requests going to GitLab.) Can you add this above line 24 (info):

Promise.config({
    longStackTraces: true,
    warnings: false
});

That should give us some more information about which request is failing.

Also, try your curl from the box running the service, but try to curl one of the GitLab API urls using the same host information you have in the config.

icougil commented 8 years ago

Hi. Thanks for your quick reply. First, just understand that what I'm trying is the "Test" button gitlab provides to check the Webhook. Next, just to understand, where I should add this line? Here is where I've found the Promise.config code:

node_modules/bluebird/js/browser/bluebird.core.js:742:Promise.config = function(opts) {
node_modules/bluebird/js/browser/bluebird.js:889:Promise.config = function(opts) {
node_modules/bluebird/js/release/debuggability.js:220:Promise.config = function(opts) {

Can you please give me a simple curl to check the GitLab API? Best,

nazrhyn commented 8 years ago

Yeah, I use the Test button for verification too. When the code receives the webhook request, it has to resolve some IDs to more information for output. For example, for commits, I have to query the GitLab API for: (1) the project (to get its path), (2) the user who made the commit (for their username), and (3) each of the commit lines' users (for their usernames).

Just to make sure we're on the same page as regards the config.json, here's what we're using:

{
    "port": 21012,
    "slackWebhookUrl": "<webhook>",
    "gitlab": {
        "baseUrl": "<protocol>://<hostname>",
        "api": {
            "basePath": "/api/v3",
            "token": "<token>"
        },
        "projects": {}
    }
}

So, using those terms, here's an example curl for one of the GitLab APIs:

 curl --header "PRIVATE-TOKEN: <token>" --insecure "<protocol>://<hostname>/api/v3/users"

EDIT: As for the Promise.config, I'm sorry I wasn't more specific. Edit server.js, and add that code above this line: https://github.com/nazrhyn/gitlab-slack/blob/master/server.js#L30

icougil commented 8 years ago

I can confirm that I'm using this kind of config.json. Also I've decided to leave empty the content of the projects element (as you have showed) with the same result.

Regarding the query via curl, I think I've found the issue, because I haven't tell you that right now Gitlab holds all of our code, so the connection and protocol we are using is Gitlab, so the final protocol and hostname we are using is https://gitlab.com/touche/api/v3/users. May be the main problem is that because we are hosting our code on gitlab the query to launch against Gitlab is not working properly? The curl returns a 404 not found.

Finally, about the Promise.conf and changing the server.js this is the result:

Promise.config({
    longStackTraces: true,
    warnings: false
});

var config,
    gitlab,
...

It is ok? I don't think so because the stacktrace I've found is the same after Testing on gitlab. Best,

nazrhyn commented 8 years ago

I figured the stack trace might be the same; I just wanted to check to see for sure. That is the correct place for that code. Thanks.

Oh, I see. You're using GitLab's online repository. I just logged in there and grabbed my private token and tried curling their API. Here's what I typed (where<token> was replaced with my token):

$ curl --header "PRIVATE-TOKEN: <token>" --insecure "https://gitlab.com/api/v3/users"

A list of users was returned from that. Assuming that the code is hosted on gitlab.com, here's the config.json for that (where webhook and token are replaced with your values for those):

{
    "port": 21012,
    "slackWebhookUrl": "<webhook>",
    "gitlab": {
        "baseUrl": "https://gitlab.com",
        "api": {
            "basePath": "/api/v3",
            "token": "<token>"
        },
        "projects": {}
    }
}

If you leave projects empty, then it will post all project notifications to whatever the default channel for the webhook is, as configured in Slack:
image

If you can't curl the users API from the box hosting the service, then that's a problem.

icougil commented 8 years ago

Ok, I found the 1st problem which was that the baseUrl should not include the project neither the root user who has all the repos that I'd like to receive notifications in Slack. So, from the Gitlab perspective, querying the users returns first 20 users. Regarding the connection with gitlab, the result is different, now the log shows this error:

our_project.git","visibility_level":0}}
[2016-07-18T14:38:49.144Z](DEBUG) 13.68.20.218 POST -- PROCESS: Commit
[2016-07-18T14:38:50.666Z](ERROR) 13.68.20.218 POST -- TypeError: expecting an array, a promise or a thenable

    See http://goo.gl/s8MMhc

    at PromiseArray.init [as _init] (/opt/gitlab-slack/node_modules/request-promise/node_modules/bluebird/js/main/promise_array.js:42:27)
    at Promise._settlePromiseAt (/opt/gitlab-slack/node_modules/request-promise/node_modules/bluebird/js/main/promise.js:579:21)
    at Promise._settlePromises (/opt/gitlab-slack/node_modules/request-promise/node_modules/bluebird/js/main/promise.js:697:14)
    at Async._drainQueue (/opt/gitlab-slack/node_modules/request-promise/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/opt/gitlab-slack/node_modules/request-promise/node_modules/bluebird/js/main/async.js:133:10)
    at Async.drainQueues (/opt/gitlab-slack/node_modules/request-promise/node_modules/bluebird/js/main/async.js:15:14)
    at process._tickCallback (node.js:448:13)

May be I should add some option to enable more debug information? Best,

nazrhyn commented 8 years ago

Hooray! That error is actually not an error. It's from bluebird's warning system and should be shut up by adding that warnings: false part of the code I gave you. I've been meaning to silence the warnings in the code, but just hadn't gotten around to it.

Even if that error is being logged, it should still work. Could you try the webhook test button again? Even if the test page shows that it fails, the Slack notification should still go through.

Before I resolve this issue, I'll update the README with better information about what should be in that config.json file based on our conversation here.

nazrhyn commented 8 years ago

Here's a screen capture of me running the test and still getting a Slack notification when the test page says that it was a 500:
webhook-test

icougil commented 8 years ago

OOOk!! So yes, it seems that it is working right now! Thank you. Regarding the integration, now I've found that when someone approves a merge request, it seems that the communication is done but the data that Slack receives is not well recognized (may be it is not already developed, I don't know). In any case, thank you it seems that now we are able to receive some notifications on Slack which is one of the things we were looking for. Cheers,

nazrhyn commented 8 years ago

Merge request notifications aren't implemented yet, but after the merge request completes, the commit notification should go through.

icougil commented 8 years ago

Ok, I understand. Regarding the merge requests, I understand. Now I suppose that builds are also not implemented yet? Because I've received an unrecognized Data when I've launched a build (due to a commit). Best,

nazrhyn commented 8 years ago

That's right. The events that are supported are covered in the README.

Merge requests should be added at some point here, as we've started using them as part of our process. Builds might come later. Comment events will probably never be supported as I can't imagine wanting to have all comments made on items in a project going to a Slack channel.

On Wed, Jul 20, 2016 at 5:30 AM, Nacho Cougil notifications@github.com wrote:

Ok, I undestand. Regarding the not merge requests, I understand. Now I suppose that builds are also not implemented yet? I've received an unrecognized Data when I've launched a build (due to a commit). Best,

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/nazrhyn/gitlab-slack/issues/19#issuecomment-233899587, or mute the thread https://github.com/notifications/unsubscribe-auth/ABmE1TywdO_2FRDAn3HxdkZkI2ku8B4iks5qXerCgaJpZM4JNVKe .

icougil commented 8 years ago

Ok thank you! I'll be aware of any news on your project ;-) Best!