olipo186/Git-Auto-Deploy

Error 400 Bad Request - The URLs references in the webhook did not match any repository entry in the config.

edgariscoding opened this issue · 2 comments

I'm using GitHub and Ubuntu 14 on a DigitalOcean Droplet.

The error message is pretty self explanatory, so I went ahead and tried every single one of the variations it suggested for my repo address (both HTTPS and SSH).

  • https://github.com/edgar-team/edgar-app
  • https://github.com/edgar-team/edgar-app.git
  • git://github.com/edgar-team/edgar-app.git
  • git@github.com:edgar-team/edgar-app.git

They all resulted in the same error.

I've made sure to restart the service, even restarted the entire server. Any advice?

(Note I replaced the real team name and repo name with dummy text)


When I test the webhook from within GitHub's settings page, I get the following error:

Response: 404

Headers

Access-Control-Allow-Origin: *
Connection: close
Content-Length: 203
Content-Type: text/html
Date: Fri, 16 Feb 2018 22:22:22 GMT
Server: SimpleHTTP/0.6 Python/2.7.12

Body

<head>
<title>Error response</title>
</head>
<body>
<h1>Error response</h1>
<p>Error code 400.
<p>Message: Bad request.
<p>Error code explanation: 400 = Bad request syntax or unsupported method.
</body>

When I check Git-Auto-Deploy on my server I can see the following output:

Git-Auto-Deploy output

edgar@edgar-app:~$ git-auto-deploy
2018-02-16 22:22:07,753 [CRITI]  Unable to activate SSL: File does not exist: /home/edgar/cert.pem
2018-02-16 22:22:07,771 [INFO ]  Listening for connections on http://0.0.0.0:8001
2018-02-16 22:22:22,203 [INFO ]  Incoming request from 192.30.252.38:43025
2018-02-16 22:22:22,205 [INFO ]  Handling the request with GitHubRequestParser
2018-02-16 22:22:22,205 [INFO ]  Received 'push' event from GitHub
2018-02-16 22:22:22,206 [WARNI]  The URLs references in the webhook did not match any repository entry in the config. For this webhook to work, make sure you have at least one repository configured with one of the following URLs; https://github.com/edgar-team/edgar-app, git://github.com/edgar-team/edgar-app.git, https://github.com/edgar-team/edgar-app.git, git@github.com:edgar-team/edgar-app.git
2018-02-16 22:22:22,206 [INFO ]  0 candidates matches the request
2018-02-16 22:22:22,207 [INFO ]  192.30.252.38 - code 400, message Bad request
2018-02-16 22:22:22,207 [INFO ]  192.30.252.38 - "POST / HTTP/1.1" 400 -
2018-02-16 22:22:22,207 [ERROR]  No matching projects

Git remote origin

edgar@edgar-app:~/public_html$ git config --get remote.origin.url
git@github.com:edgar-team/edgar-app.git

edgar@edgar-app:/var/www/edgar-app.com/public_html$ git remote -v
origin	git@github.com:edgar-team/edgar-app.git (fetch)
origin	git@github.com:edgar-team/edgar-app.git (push)

The request body

Looking at the request body on GitHub's Webhooks settings page shows the following URLs:

[...]
"git_url": "git://github.com/edgar-team/edgar-app.git",
"ssh_url": "git@github.com:edgar-team/edgar-app.git",
"clone_url": "https://github.com/edgar-team/edgar-app.git",
"svn_url": "https://github.com/edgar-team/edgar-app",
"homepage": "https://edgar-app.com",
[...]

Config file

Located at `/etc/git-auto-deploy.conf.json

{
  // HTTP server options
  "http-enabled": true,
  "http-host": "0.0.0.0",
  "http-port": 8001,

  // HTTPS server options
  "https-enabled": true,
  "https-host": "0.0.0.0",
  "https-port": 8002,

  // Web socket server options (used by web UI for real time updates)
  "wss-enabled": false,
  "wss-host": "0.0.0.0",
  "wss-port": 8003,

  // Web user interface options
  "web-ui-enabled": false,
  "web-ui-username": "admin",
  "web-ui-password": "password",
  //"web-ui-whitelist": ["127.0.0.1"],

  // TLS/SSL cert (necessary for HTTPS and web socket server to work)
  "ssl-key": "/etc/letsencrypt/live/edgar-app.com/privkey.pem",
  "ssl-cert": "/etc/letsencrypt/live/edgar-app.com/fullchain.pem",

  // File to store a copy of the console output
  "log-file": "/var/log/git-auto-deploy.log",

  // Record all log levels by default
  //"log-level": "NOTSET",

  Deploy commands that should be executed for all projects
  "global_deploy": [
    "echo Deploy started!",
    "echo Deploy completed!"
  ],

  // Project configs
  "repositories": [
    {
      "url": "git@github.com:edgar-team/edgar-app.git",
      "branch": "master",
      "remote": "origin",
      "path": "/var/www/edgar-app.com/public_html/",
      "deploy": "echo deploying"
    }
  ]
}

Getting the same 400 bad request error for Bitbucket private repository using ssh.

I encounter the same problem, I read Git-Auto-Deploy source code and I realize that if we declare only url in repositories config, that is not enough. When gitautodeploy check, sometimes (i don't know the reason) the actual request URL what it got is the last path of URL (with your example: 'git@github.com:edgar-team/edgar-app.git' then it get 'edgar-app' ), then I see we have another config is match-url, if this config is declared, the script will check it first, you only need declare config "match-url":"edgar-app" below url config, it will work. like this:
// Project configs

"repositories": [
{
"url": "git@github.com:edgar-team/edgar-app.git",
"match-url": "edgar-app",
"branch": "master",
"remote": "origin",
"path": "/var/www/edgar-app.com/public_html/",
"deploy": "echo deploying"
}
]