Code Monkey home page Code Monkey logo

Comments (10)

jonhoo avatar jonhoo commented on May 2, 2024 1

Great, thank you!

from webhook.

adnanh avatar adnanh commented on May 2, 2024

Hey there, what version of webhook are you using and what is your hooks.json definition for the given hook?

Here is a sample hooks.json definition:

[
  {
    "pass-arguments-to-command": [
      {
        "source": "entire-headers"
      }
    ],
    "execute-command": "/home/adnan/test.sh",
    "id": "test"
  }
]

test.sh script:

#!/bin/sh

echo $1 > /home/adnan/test.log

Trigger with curl:

curl localhost:9000/hooks/test

Webhook log after triggering the hook:

[webhook] 2016/10/31 13:31:51 version 2.5.0 starting
[webhook] 2016/10/31 13:31:51 setting up os signal watcher
[webhook] 2016/10/31 13:31:51 attempting to load hooks from hooks.json
[webhook] 2016/10/31 13:31:51 found 1 hook(s) in file
[webhook] 2016/10/31 13:31:51   loaded: test
[webhook] 2016/10/31 13:31:51 serving hooks on http://0.0.0.0:9000/hooks/{id}
[webhook] 2016/10/31 13:31:51 os signal watcher ready
[webhook] 2016/10/31 13:32:24 Started GET /hooks/test
[webhook] 2016/10/31 13:32:24 test got matched
[webhook] 2016/10/31 13:32:24 test hook triggered successfully
[webhook] 2016/10/31 13:32:24 Completed 200 OK in 44.258ยตs
[webhook] 2016/10/31 13:32:24 executing /home/adnan/test.sh (/home/adnan/test.sh) with arguments ["/home/adnan/test.sh" "{\"Accept\":\"*/*\",\"User-Agent\":\"curl/7.35.0\"}"] and environment [] using  as cwd
[webhook] 2016/10/31 13:32:24 command output: 
[webhook] 2016/10/31 13:32:24 finished handling test

Contents of test.log:

{"Accept":"*/*","User-Agent":"curl/7.35.0"}

from webhook.

adnanh avatar adnanh commented on May 2, 2024

Looking at your script in the commit that referenced this issue, $7 will be JSON string that contains all headers that have been passed to the webhook, it will never be equal to "ping". If you wanted the value from the header that contains ping ("X-Github-Event"?), you should reference it using the syntax you wrote:

{
  "source": "header",
  "name": "X-GitHub-Event"
}

from webhook.

jonhoo avatar jonhoo commented on May 2, 2024

I tried

{
  "source": "header",
  "name": "X-GitHub-Event"
}

first, and got an empty string. I then tried

{
  "source": "entire-headers"
}

just to see if that would work. It also gives me an empty string.

from webhook.

adnanh avatar adnanh commented on May 2, 2024

Weird. Could you create the setup I used in the comment above and copy the webhook output?

from webhook.

adnanh avatar adnanh commented on May 2, 2024

Also, what version of webhook are you using?

from webhook.

adnanh avatar adnanh commented on May 2, 2024

And which OS is webhook running on?

from webhook.

jonhoo avatar jonhoo commented on May 2, 2024
[webhook] 2016/10/31 13:13:56 Started POST /hooks/email-pushbot
[webhook] 2016/10/31 13:13:56 email-pushbot got matched
[webhook] 2016/10/31 13:13:56 email-pushbot hook triggered successfully
[webhook] 2016/10/31 13:13:56 error extracting command arguments: couldn't retrieve argument for {Source:header Name:X-GitHub-Event EnvName:}
[webhook] 2016/10/31 13:13:56 executing /usr/bin/mailer (/usr/bin/mailer) with arguments ["/usr/bin/mailer" "/srv/git/pushbot" "refs/heads/master" "6db40f5186486801785a24241ffaf1a6ba0d2e1a" "328d298f0a8a44e8653430857eebf5d139c756b7" "jonhoo" "[email protected]" ""] and environment [] using /home/default as cwd
[webhook] 2016/10/31 13:13:56 command output: handling  to /srv/git/pushbot
/srv/git/pushbot refs/heads/master 6db40f5186486801785a24241ffaf1a6ba0d2e1a 328d298f0a8a44e8653430857eebf5d139c756b7 jonhoo [email protected]
pushed by: jonhoo <[email protected]>
aliased to Jon Gjengset <[email protected]>
syncing with upstream
  Fetching origin
invoking post-receive-email with
  6db40f5186486801785a24241ffaf1a6ba0d2e1a
  328d298f0a8a44e8653430857eebf5d139c756b7
  refs/heads/master
all done
[webhook] 2016/10/31 13:13:56 finished handling email-pushbot
[webhook] 2016/10/31 13:13:56 Completed 200 OK in 392.731546ms
$ git -C go/src/github.com/adnanh/webhook/ rev-parse HEAD
7d525cf317b7f0e45b9e7e1a1658b4633154ec01

Running Arch Linux.

from webhook.

adnanh avatar adnanh commented on May 2, 2024

Aha! Finally got it!

From RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", Section 4.2, "Message Headers":

Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.

What Golang http package does is normalizes the keys in the request headers map using the "Title case", making webhook unable to extract X-Git_Hub_-Event because in the hash map it's under X-Git_hub_-Event.
As a temporary workaround you can use the X-Github-Event as a header name.

Good catch, thanks!

2.6.0 coming right up!

from webhook.

adnanh avatar adnanh commented on May 2, 2024

Fixed in 2.6.0.

Thanks a lot for your feedback!

from webhook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.