Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release fails when adding "release" labels. Error 422. #138

Closed
Aghassi opened this issue Dec 14, 2018 · 17 comments · Fixed by #140
Closed

Release fails when adding "release" labels. Error 422. #138

Aghassi opened this issue Dec 14, 2018 · 17 comments · Fixed by #140

Comments

@Aghassi
Copy link

Aghassi commented Dec 14, 2018

Hello,

I'm not sure which version introduced this issue, but I know it happens as far back as 5.2.1 for me (It happened on 5.2.5 and 5.2.6).

I'm seeing the following only when PRs are merged:

[14:14:30] [semantic-release] [@semantic-release/github] › ℹ  Added comment to issue #538: https://github.enterprise.com/ORG/plugin-cli/pull/538#issuecomment-518258
[14:14:33] [semantic-release] [@semantic-release/github] › ℹ  Added comment to issue #539: https://github.enterprise.com/ORG/plugin-cli/pull/539#issuecomment-518259
[14:14:36] [semantic-release] [@semantic-release/github] › ℹ  Added comment to issue #541: https://github.enterprise.com/ORG/plugin-cli/pull/541#issuecomment-518260
[14:15:06] [semantic-release] [@semantic-release/github] › ✖  Failed to add a comment to the issue #538.
[14:15:09] [semantic-release] [@semantic-release/github] › ✖  Failed to add a comment to the issue #539.
[14:15:12] [semantic-release] [@semantic-release/github] › ✖  Failed to add a comment to the issue #541.
  semantic-release:github found semantic-release issues: [] +42s
[14:15:12] [semantic-release] › ✖  Failed step "success" of plugin "@semantic-release/github"
[14:15:12] [semantic-release] › ✖  An error occurred while running semantic-release: { HttpError: Invalid request.

For 'links/2/schema', {"labels"=>["released"]} is not an array.
    at response.text.then.message (/home/circleci/project/node_modules/@octokit/request/lib/request.js:55:27)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
  name: 'HttpError',
  status: 422,
  headers: 
   { 'access-control-allow-origin': '*',
     'access-control-expose-headers': 'ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval',
     connection: 'close',
     'content-length': '209',
     'content-security-policy': 'default-src \'none\'',
     'content-type': 'application/json; charset=utf-8',
     date: 'Fri, 14 Dec 2018 14:15:06 GMT',
     server: 'GitHub.com',
     status: '422 Unprocessable Entity',
     'strict-transport-security': 'max-age=31536000; includeSubdomains',
     'x-accepted-oauth-scopes': '',
     'x-content-type-options': 'nosniff',
     'x-frame-options': 'deny',
     'x-github-enterprise-version': '2.12.22',
     'x-github-media-type': 'github.v3; format=json',
     'x-github-request-id': 'b067d086-6b6f-4824-92d1-c0791379a377',
     'x-oauth-scopes': 'admin:public_key, public_repo, repo:status',
     'x-runtime-rack': '0.023969',
     'x-xss-protection': '1; mode=block' },
  request: 
   { method: 'POST',
     url: 'https://github.enterprise.com/api/v3/repos/ORG/plugin-cli/issues/538/labels',
     headers: 
      { accept: 'application/vnd.github.v3+json',
        'user-agent': 'octokit.js/16.2.0 Node.js/8.14.0 (Linux 3.13; x64)',
        authorization: 'token [secure]',
        'content-type': 'application/json; charset=utf-8' },
     body: '{"labels":["released"]}',
     request: { validate: [Object] } },
  documentation_url: 'https://developer.github.com/enterprise/2.12/v3/issues/labels/#add-labels-to-an-issue',
  attemptNumber: 4,
  retriesLeft: 0,
  pluginName: '@semantic-release/github' }
[14:15:12] [semantic-release] › ✖  An error occurred while running semantic-release: { HttpError: Invalid request.

For 'links/2/schema', {"labels"=>["released"]} is not an array.
    at response.text.then.message (/home/circleci/project/node_modules/@octokit/request/lib/request.js:55:27)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
  name: 'HttpError',
  status: 422,
  headers: 
   { 'access-control-allow-origin': '*',
     'access-control-expose-headers': 'ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval',
     connection: 'close',
     'content-length': '209',
     'content-security-policy': 'default-src \'none\'',
     'content-type': 'application/json; charset=utf-8',
     date: 'Fri, 14 Dec 2018 14:15:09 GMT',
     server: 'GitHub.com',
     status: '422 Unprocessable Entity',
     'strict-transport-security': 'max-age=31536000; includeSubdomains',
     'x-accepted-oauth-scopes': '',
     'x-content-type-options': 'nosniff',
     'x-frame-options': 'deny',
     'x-github-enterprise-version': '2.12.22',
     'x-github-media-type': 'github.v3; format=json',
     'x-github-request-id': 'c63d49e8-b108-43ce-9a88-b616e1fa3281',
     'x-oauth-scopes': 'admin:public_key, public_repo, repo:status',
     'x-runtime-rack': '0.029809',
     'x-xss-protection': '1; mode=block' },
  request: 
   { method: 'POST',
     url: 'https://github.enterprise.com/api/v3/repos/ORG/plugin-cli/issues/539/labels',
     headers: 
      { accept: 'application/vnd.github.v3+json',
        'user-agent': 'octokit.js/16.2.0 Node.js/8.14.0 (Linux 3.13; x64)',
        authorization: 'token [secure]',
        'content-type': 'application/json; charset=utf-8' },
     body: '{"labels":["released"]}',
     request: { validate: [Object] } },
  documentation_url: 'https://developer.github.com/enterprise/2.12/v3/issues/labels/#add-labels-to-an-issue',
  attemptNumber: 4,
  retriesLeft: 0,
  pluginName: '@semantic-release/github' }
[14:15:12] [semantic-release] › ✖  An error occurred while running semantic-release: { HttpError: Invalid request.

For 'links/2/schema', {"labels"=>["released"]} is not an array.
    at response.text.then.message (/home/circleci/project/node_modules/@octokit/request/lib/request.js:55:27)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
  name: 'HttpError',
  status: 422,
  headers: 
   { 'access-control-allow-origin': '*',
     'access-control-expose-headers': 'ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval',
     connection: 'close',
     'content-length': '209',
     'content-security-policy': 'default-src \'none\'',
     'content-type': 'application/json; charset=utf-8',
     date: 'Fri, 14 Dec 2018 14:15:12 GMT',
     server: 'GitHub.com',
     status: '422 Unprocessable Entity',
     'strict-transport-security': 'max-age=31536000; includeSubdomains',
     'x-accepted-oauth-scopes': '',
     'x-content-type-options': 'nosniff',
     'x-frame-options': 'deny',
     'x-github-enterprise-version': '2.12.22',
     'x-github-media-type': 'github.v3; format=json',
     'x-github-request-id': 'bfcc035e-b3a3-4bbb-8ea7-c5207ade3b3d',
     'x-oauth-scopes': 'admin:public_key, public_repo, repo:status',
     'x-runtime-rack': '0.024596',
     'x-xss-protection': '1; mode=block' },
  request: 
   { method: 'POST',
     url: 'https://github.enterprise.com/api/v3/repos/ORG/plugin-cli/issues/541/labels',
     headers: 
      { accept: 'application/vnd.github.v3+json',
        'user-agent': 'octokit.js/16.2.0 Node.js/8.14.0 (Linux 3.13; x64)',
        authorization: 'token [secure]',
        'content-type': 'application/json; charset=utf-8' },
     body: '{"labels":["released"]}',
     request: { validate: [Object] } },
  documentation_url: 'https://developer.github.com/enterprise/2.12/v3/issues/labels/#add-labels-to-an-issue',
  attemptNumber: 4,
  retriesLeft: 0,
  pluginName: '@semantic-release/github' }
{ AggregateError: 
    HttpError: Invalid request.
    For 'links/2/schema', {"labels"=>["released"]} is not an array.
        at response.text.then.message (/home/circleci/project/node_modules/@octokit/request/lib/request.js:55:27)
        at <anonymous>
    HttpError: Invalid request.
    For 'links/2/schema', {"labels"=>["released"]} is not an array.
        at response.text.then.message (/home/circleci/project/node_modules/@octokit/request/lib/request.js:55:27)
        at <anonymous>
    HttpError: Invalid request.
    For 'links/2/schema', {"labels"=>["released"]} is not an array.
        at response.text.then.message (/home/circleci/project/node_modules/@octokit/request/lib/request.js:55:27)
        at <anonymous>
    at /home/circleci/project/node_modules/semantic-release/lib/plugins/pipeline.js:53:11
    at <anonymous> name: 'AggregateError' }error Command failed with exit code 1.
    at <anonymous> name: 'AggregateError' }error Command failed with exit code 1.

My config looks like:

➜ node release.config.js
config : {"prepare":["@semantic-release/npm","@semantic-release/git"],"plugins":["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator","@semantic-release/npm",["@semantic-release/github",{"releasedLabels":false}]]}

Any help or direction on how to fix this would be wonderful. I'm not sure when it started, but it is making it hard to release continuously.

@gr2m
Copy link
Member

gr2m commented Dec 14, 2018

Is this running against GitHub enterprise?

The endpoint to add labels was recently changed. Instead of accepting labels as array in the request body, they are now sent with a "labels" namespace. The change breaks usage with GitHub enterprise, I don’t think they will backport that fix.

I’m not sure how to address this :/ we could workaround it in @semantic-release/github by not using the octokit.issues.addLabels() API, but instead use ocotkit.request('POST /repos/:owner/:repo/issues/:number/labels', {data: ['released']})

For reference

@Aghassi
Copy link
Author

Aghassi commented Dec 14, 2018

@gr2m Yes this is Github Enterprise. Version 2.12. We are moving to 2.14 tomorrow apparently. The odd thing is that other repos with this same setup are not experiencing this issue. It is sort of hit or miss depending on what yarn resolves I think.

@Aghassi
Copy link
Author

Aghassi commented Dec 14, 2018

@gr2m one thought I would have is can you check the version of GHE you are hitting? If below a certain version fallback?

@Aghassi
Copy link
Author

Aghassi commented Dec 14, 2018

For now, what I have gone and done is the following in package.json and updated my yarn.lock

  "resolutions": {
    "semantic-release/@semantic-release/github": "5.2.1"
  },

Not a perfect solution, but it unblocks us until this stuff is figured out. It is interesting because even though I specified that version as a devDependency, semantic-release brings it's own in which is a ^ semver and grabs the latest, which is breaking. Also interesting is that it doesn't use the one I provide, it uses the one it brings in. So even though I thought that I had a pinned version, I really didn't.

@pvdlg
Copy link
Member

pvdlg commented Dec 14, 2018

@gr2m it seems that @octokit/rest.js version 16.0.0 has a minimum version requirement for the GitHub enterprise API version. Is the old version (the one that expect labels as an Array and not an object) of the GitHub Enterprise deprecated?
If it's not deprecated by GitHub, shouldn't @octokit/rest.js support it? Like, I would assume the latest version of @octokit/rest.js to work with every version of the API that GitHub consider supported/not deprecated.

@gr2m
Copy link
Member

gr2m commented Dec 14, 2018

it seems that @octokit/rest.js version 16.0.0 has a minimum version requirement for the GitHub enterprise API version.

The idea of a GHE requirement is something we started to discuss with the Octokit maintainers across the supported languages, we don’t have a conclusion yet.

Is the old version (the one that expect labels as an Array and not an object) of the GitHub Enterprise deprecated?

No the GHE version is still supported

If it's not deprecated by GitHub, shouldn't @octokit/rest.js support it? Like, I would assume the latest version of @octokit/rest.js to work with every version of the API that GitHub consider supported/not deprecated.

Yes, you are right, sorry for the trouble :(

The approach I am taking is that you will be able to load the endpoint methods for a certain enterprise version, which will still work on api.github.com. I only created a plugin for enterprise endpoints this week: https://github.com/octokit/plugin-enterprise-rest.js.

In theory, we should be able to do this:

const Octokit = require('@octokit/rest')
  .plugin(require('@octokit/enterprise-rest/v2.15'))
const octokit = new Octokit({
  baseUrl: 'https://github.acme-inc.com/api/v3'
})

and it will override methods such as .issues.addLabels(). This should all be working, but to be honest I haven’t tested it myself yet. But I can do that now and maybe that’s what we can do?

@pvdlg
Copy link
Member

pvdlg commented Dec 14, 2018

So that mean the @octokit/rest user will have to specify the plugin in order to support the "old" enterprise endpoint?

Shouldn't @octokit/rest just work with any version of the API officially supported? It seems weird to require @octokit/rest users to know about every changes in the enterprise API endpoint.

It's probably a good idea to use a plugin internally to support both the old and new endpoint but I don't think it should have to be defined by the @octokit/rest user. As an @octokit/rest user I don't see myself subscribing to the GitHub changelog and adding/removing plugins in my code every time an endpoint is updated, or an old one becomes unsupported.

Maybe the solution is an internal/default plugin that would be called on errors and:

  • Read the API version from the header
  • If the current call is made to and "old" endpoint, then convert the input to the old format and re-do the call
  • If the error is not related to an endpoint change then throw it

This plugin would have to maintain a list of data transform to insure the compatibility with old endpoint that are not deprecated yet.

@gr2m
Copy link
Member

gr2m commented Dec 14, 2018

I mean that semantic-release can use require('@octokit/enterprise-rest/v2.15') or what ever enterprise version you want to support. I’m aware of the shortcomings of @octokit/rest & enterprise support, we will get there eventually, there is still lots of work ahead. We will probably setup LTS versions that match with respective enterprise versions, not sure yet

@pvdlg
Copy link
Member

pvdlg commented Dec 14, 2018

The thing is I don't know which version I want to support, because I don't know which version of GHE are supported, and what each version deprecate and change. I just want to support all versions that GitHub support.

For now semantic-release users have to specify @semantic-release/github@5.2.1 in their package.json as it's the last version that uses @octokit/rest.js@15. See #138 (comment).
That's not sustainable because @semantic-release/github@5.2.1 will not be compatible with @semantic-release@16.0.0. Plus those users won't get any fix released after @semantic-release/github@5.2.1.

If for now supporting all version of GHE supported by GitHub means reverting to @octokit/rest.js@15 I think that's fine. We can revert to that version and migrate to @octokit/rest.js@16 once a solution is implemented.

@gr2m
Copy link
Member

gr2m commented Dec 15, 2018

I just want to support all versions that GitHub support.

It's not that simple, GitHub is adding new APIs all the time and people want to use it. But these new APIs won’t work on GitHub Enterprise. So in the end you will have to decide which GitHub versions you want to support and pick the right Octokit version that supports the GitHub Enterprise version you need. Hence the LTS approach, we will have maintenance versions that we will keep supporting as long as the respective enterprise versions are supported

@pvdlg
Copy link
Member

pvdlg commented Dec 15, 2018

So that mean in @semantic-release/github we have to choose which we support and we can't have the plugin working for everyone?

For @semantic-release/github I think it's more important to support as many users as possible rather than using the last API. The last API doesn't bring any advantage as far as I can tell which is why I proposed to go back to @octokit/rest.js@15. But maybe I'm wrong to assume it would make @semantic-release/github work for everyone again.

Anyway, you have a better understanding of the situation than me, so you know what's the best solution!

@gr2m
Copy link
Member

gr2m commented Dec 15, 2018

Here is a PR implementing the workaround using ocotkit.request(): #140

That’s the simplest fix right now

@pvdlg
Copy link
Member

pvdlg commented Dec 15, 2018

👍If you think that's the best for now, let's go with that!

@ghost ghost removed the in progress label Dec 15, 2018
@semantic-release-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 5.2.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Aghassi
Copy link
Author

Aghassi commented Dec 15, 2018

Thank you both for taking the time to address this! I'm happy to work with you guys on GHE support long term as we use it. However, moving to 2.14 may change some things so who knows how much use that will be in the future.

@Aghassi
Copy link
Author

Aghassi commented Dec 20, 2018

@pvdlg Just wanted to clarify. It seems it was published to the next tag in NPM. How often does next move to latest?

@pvdlg
Copy link
Member

pvdlg commented Dec 20, 2018

I just added 5.2.7 to @latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants