rvagg / github-webhook

A flexible web server for reacting GitHub Webhooks
MIT License
116 stars 24 forks source link

Incorrect command execution behavior when `rules.exec` is an array #21

Open ustc-zzzz opened 3 years ago

ustc-zzzz commented 3 years ago

The code pops the first element of an array in each execution and the length of the array is reduced by one each time when the webhook is triggered since the array is passed by reference in the code.

For example, consider the config shown as following:

{
  "port": 8080,
  "path": "/postreceive",
  "secret": "0123456789abcdef",
  "rules": [{
    "event": "push",
    "exec": ["foo", "bar", "baz"]
  }]
}

When the webhook is triggered for the first time, foo bar baz is executed. For the second time, the command will be bar baz, and baz for the third time, and then an error is thrown for the fourth time since the array is empty and nothing can be popped.

The simplest solution might be copying the array instead of passing by reference.