gr2m / octokit-plugin-create-pull-request

Octokit plugin to create a pull request with multiple file changes
MIT License
104 stars 28 forks source link

Why HTTP 404? #20

Closed saschanaz closed 4 years ago

saschanaz commented 5 years ago

This might be a noob question, but I keep getting HTTP 404 when calling createPullRequest. Looking at the error stack, it seems it fails to create a fork, but what would it even mean when creating a fork?

RequestError [HttpError]: Not Found
    at C:\Users\sasch\Documents\GitHub\webidl-updater\node_modules\@octokit\request\dist-node\index.js:66:23
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async createPullRequest (C:\Users\sasch\Documents\GitHub\webidl-updater\node_modules\octokit-create-pull-request\lib\create-pull-request.js:30:7)
    at async main (C:\Users\sasch\Documents\GitHub\webidl-updater\src\github-pullrequest.js:65:5) {
  name: 'HttpError',
  status: 404,
  headers: {
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type',
    connection: 'close',
    'content-encoding': 'gzip',
    'content-security-policy': "default-src 'none'",
    'content-type': 'application/json; charset=utf-8',
    date: 'Tue, 17 Sep 2019 07:50:00 GMT',
    'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
    server: 'GitHub.com',
    status: '404 Not Found',
    'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
    'transfer-encoding': 'chunked',
    'x-accepted-oauth-scopes': '',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'deny',
    'x-github-media-type': 'github.v3; format=json',
    'x-github-request-id': 'C51B:7495:710479:8DDF84:5D809028',
    'x-oauth-scopes': '',
    'x-ratelimit-limit': '5000',
    'x-ratelimit-remaining': '4976',
    'x-ratelimit-reset': '1568710199',
    'x-xss-protection': '1; mode=block'
  },
    method: 'POST',
    url: 'https://api.github.com/repos/saschanaz/test-spec/forks',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit.js/16.28.9 Node.js/12.10.0 (Windows 10; x64)',
      authorization: 'token [REDACTED]',
      'content-length': 0
    },
    request: { hook: [Function: bound bound register], validate: [Object] }
  },
  documentation_url: 'https://developer.github.com/v3/repos/forks/#create-a-fork'
}

Manually creating a fork bypasses that error and then creates a new 404 error when trying to create a tree.

RequestError [HttpError]: Not Found
    at C:\Users\sasch\Documents\GitHub\webidl-updater\node_modules\@octokit\request\dist-node\index.js:66:23
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async createPullRequest (C:\Users\sasch\Documents\GitHub\webidl-updater\node_modules\octokit-create-pull-request\lib\create-pull-request.js:48:14)
    at async main (C:\Users\sasch\Documents\GitHub\webidl-updater\src\github-pullrequest.js:65:5) {
  name: 'HttpError',
  status: 404,
  headers: {
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type',
    connection: 'close',
    'content-encoding': 'gzip',
    'content-security-policy': "default-src 'none'",
    'content-type': 'application/json; charset=utf-8',
    date: 'Tue, 17 Sep 2019 07:52:27 GMT',
    'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
    server: 'GitHub.com',
    status: '404 Not Found',
    'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
    'transfer-encoding': 'chunked',
    'x-accepted-oauth-scopes': '',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'deny',
    'x-github-media-type': 'github.v3; format=json',
    'x-github-request-id': 'C54C:0438:70AEBA:8E20D8:5D8090BB',
    'x-oauth-scopes': '',
    'x-ratelimit-limit': '5000',
    'x-ratelimit-remaining': '4967',
    'x-ratelimit-reset': '1568710199',
    'x-xss-protection': '1; mode=block'
  },
  request: {
    method: 'POST',
    url: 'https://api.github.com/repos/autokagami/test-spec/git/trees',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit.js/16.28.9 Node.js/12.10.0 (Windows 10; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: `{"base_tree":"181d61b692b26934abcfe6ce24b2de28f99d38cf","tree":[{"path":"index.html","mode":"100644","content":"<!DOCTYPE html>\\r\\n<html>\\r\\n  <head>\\r\\n    <meta charset='utf-8'>\\r\\n    <title>Replace me with a real title</title>\\r\\n    <script type=\\"text/javascript\\" src='https://www.w3.org/Tools/respec/respec-w3c-common' class='remove' async></script>\\r\\n    <script class='remove'>\\r\\n      var respecConfig = {\\r\\n        specStatus: \\"ED\\",\\r\\n        editors: [{\\r\\n          name: \\"Your Name\\",\\r\\n          url: \\"https://your-site.com\\",\\r\\n       
 }],\\r\\n        github: \\"https://github.com/w3c/some-API/\\",\\r\\n      };\\r\\n    </script>\\r\\n  </head>\\r\\n  
<body>\\r\\n    <section id='abstract'>\\r\\n      <p>\\r\\n        This is required.\\r\\n      </p>\\r\\n    </section>\\r\\n    <section id='sotd'>\\r\\n      <p>\\r\\n        This is required.\\r\\n      </p>\\r\\n    </section>\\r\\n    
<section data-dfn-for=\\"Foo\\">\\r\\n      <h2><dfn>Foo</dfn> interface</h2>\\r\\n      <pre class=\\"idl\\">\\r\\n     
 [Exposed=Window]\\r\\n      interface Foo {\\r\\n        constructor();\\r\\n        attribute DOMString bar;\\r\\n     
   void doTheFoo();\\r\\n      };\\r\\n      </pre>\\r\\n    </section>\\r\\n  </body>\\r\\n</html>\\r\\n"}]}`,
    request: { hook: [Function: bound bound register], validate: [Object] }
  },
  documentation_url: 'https://developer.github.com/v3/git/trees/#create-a-tree'
}

I'm using:

{
  "@octokit/rest": "^16.28.9",
  "octokit-create-pull-request": "^1.3.0"
}

and giving personal access token for authentication.

saschanaz commented 5 years ago

Okay, this is because the token didn't have the repo access. Could you add a warning to the readme so that newbies like me won't panic?

gr2m commented 5 years ago

Thanks for opening the the issue. Adding info on the required repo access is a good idea. But I think we could also throw a more helpful error.

The GitHub API often returns a 404 if the authentication is not sufficient to access something.

Update: I've updated the README