rvagg / rvagg/github-webhook

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

Open
#21 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
115
Forks
23
Avg merge
3d 5h
Merged PRs (30d)
3

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in github-webhook.js at lines 202 and 206, then reproduce the example configuration with repeated push webhook executions. Verify that the configured exec array is not shortened between triggers: each run should execute the original foo bar baz command and should not fail after the array has been consumed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.