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

HttpError: Validation Failed on trying to update branch protection #1007

Open
denang1 opened this issue Sep 6, 2019 · 11 comments

Comments

@denang1
Copy link

commented Sep 6, 2019

Bug Report

Current Behavior
Trying to update branch protection through context.github fails with validation failed error message.

 try  {
      await context.github.repos.updateBranchProtection({
        owner,
        repo,
        branch,
        required_status_checks,
        enforce_admins,
        required_pull_request_reviews,
        restrictions,
        headers
      })
    } catch (e) {
        context.log.warn(e, `Failed to update branch protection rule on ${branch}`)
    }
}
const headers = {
    "accept": 'application/vnd.github.hellcat-preview+json,application/vnd.github.luke-cage-preview+json,application/vnd.github.zzzax-preview+json'
  }

I am using the above preview header in the request

Expected behavior/code
Branch protection rule to be updated appropriately

Environment

  • Probot version(s): 9.3.2
  • Node/npm version: Node 10.16.0 npm 6.9.0
  • OS: OSX 10.14.5
@welcome

This comment has been minimized.

Copy link

commented Sep 6, 2019

Thanks for opening this issue. A contributor should be by to give feedback soon. In the meantime, please check out the contributing guidelines and explore other ways you can get involved.

@issue-label-bot issue-label-bot bot added the bug 🐞 label Sep 6, 2019

@issue-label-bot

This comment has been minimized.

Copy link

commented Sep 6, 2019

Issue-Label Bot is automatically applying the label bug 🐞 to this issue, with a confidence of 0.97. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@denang1

This comment has been minimized.

Copy link
Author

commented Sep 6, 2019

Forgot to add my permissions for the app:
repository metadata: read
repository administration: read/write
repository contents: read

@gr2m

This comment has been minimized.

Copy link
Contributor

commented Sep 7, 2019

Can you paste the full error? Can you make sure you are using the latest probot and @octokit/rest version?

WIth the latest version, you can set preview headers more easily:

    mediaType: { previews: ['hellcat', 'luke-cage', 'zzzax'] }
@denang1

This comment has been minimized.

Copy link
Author

commented Sep 9, 2019

@gr2m I tried running my app with latest probot (v9.3.3) and octokit/rest (16.28.9) but it still fails. Here is the error.
Screen Shot 2019-09-09 at 9 58 37 AM

@gr2m

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2019

is there more information on the error? The error has a .request property, that's what we need to better understand the cause of your problem

@denang1

This comment has been minimized.

Copy link
Author

commented Sep 9, 2019

@gr2m

17:37:29.072Z  WARN event: Failed to update branch protection rule on master (id=75cd9270-d328-11e9-8411-4994023d34d1, method=PUT)
  url: https://api.github.com/repos/denang1/mergemate-test/branches/master/protection
  --
  headers: {
    "accept": "application/vnd.github.luke-cage-preview+json",
    "user-agent": "octokit.js/16.28.9 Node.js/10.16.0 (macOS Mojave; x64)",
    "authorization": "token [REDACTED]",
    "content-type": "application/json; charset=utf-8"
  }
  --
  body: {"required_status_checks":{"strict":true,"contexts":["ci/circleci: build"]},"enforce_admins":true,"required_pull_request_reviews":{"required_approving_review_count":1,"dismiss_stale_reviews":true,"require_code_owner_reviews":true,"dismissal_restrictions":{"users":[],"teams":[]}},"restrictions":{"users":[],"teams":[]}}
  --
  request: {
    "validate": {
      "branch": {
        "required": true,
        "type": "string"
      },
      "enforce_admins": {
        "allowNull": true,
        "required": true,
        "type": "boolean"
      },
      "owner": {
        "required": true,
        "type": "string"
      },
      "repo": {
        "required": true,
        "type": "string"
      },
      "required_pull_request_reviews": {
        "allowNull": true,
        "required": true,
        "type": "object"
      },
      "required_pull_request_reviews.dismiss_stale_reviews": {
        "type": "boolean"
      },
      "required_pull_request_reviews.dismissal_restrictions": {
        "type": "object"
      },
      "required_pull_request_reviews.dismissal_restrictions.teams": {
        "type": "string[]"
      },
      "required_pull_request_reviews.dismissal_restrictions.users": {
        "type": "string[]"
      },
      "required_pull_request_reviews.require_code_owner_reviews": {
        "type": "boolean"
      },
      "required_pull_request_reviews.required_approving_review_count": {
        "type": "integer"
      },
      "required_status_checks": {
        "allowNull": true,
        "required": true,
        "type": "object"
      },
      "required_status_checks.contexts": {
        "required": true,
        "type": "string[]"
      },
      "required_status_checks.strict": {
        "required": true,
        "type": "boolean"
      },
      "restrictions": {
        "allowNull": true,
        "required": true,
        "type": "object"
      },
      "restrictions.teams": {
        "type": "string[]"
      },
      "restrictions.users": {
        "type": "string[]"
      }
    }
  }
@gr2m

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2019

Thanks, that might in fact be a bug with https://github.com/octokit/request.js/

For the time being, you should be able to do this

octokit.request('PUT /repos/:owner/:repo/branches/:branch/protection', {
        owner,
        repo,
        branch,
        required_status_checks,
        enforce_admins,
        required_pull_request_reviews,
        restrictions,
        mediaType: {
                previews: ['luke-cage']
        }
})

Could you please check if that works for you?

GitHub
Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node - octokit/request.js

@gr2m gr2m self-assigned this Sep 9, 2019

@denang1

This comment has been minimized.

Copy link
Author

commented Sep 9, 2019

@gr2m Yep that works! Thanks so much for the help!

@denang1

This comment has been minimized.

Copy link
Author

commented Sep 13, 2019

@gr2m I got the create branch protection working but when I do an update I get a 200 response with no changes to the repo. Do you have any suggestions? Thanks!

@gr2m

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2019

Can you share your code? I had a typo in my code above, I missed the PUT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.