Skip to content

Deployment policy 404 when protected branches is enabled #746

@wernerb

Description

@wernerb

Problem Description

Using the latest environment.js code in the repo.
In settings.yml when wanting to create an environment when the same name environment is already there. We get a 404 during PR mode which crashes the app. Possibly also happens on main.

What is actually happening

What happens is that the existing environment has protected_branches: true which is mutually exclusive with deployment-branch-policies.
In PR mode a 404 then happens because it wrongly requests to list the custom branch policies. This results in a crash of the app.

The environment we want to update has custom deployment branch policies setup:

environments:
  - name: release
    deployment_branch_policy:
      protected_branches: false
      custom_branch_policies:
        - "main"
        - "release/*"
        - "hotfix/*.*.*"

What is the expected behavior

When you get the environment you see if it has protected_branches set to true. If false, only then do you try to retrieve custom_branch_policies.

Error output, if available

{"level":20,"time":1737568096854,"pid":25,"hostname":"safe-settings-cf64dd6bd-4dsrv","name":"probot","name":"probot","name":"octokit","msg":"GitHub request: GET https://api.github.com/repos/x/x/environments/release/deployment-branch-policies - 404"}
/opt/safe-settings/node_modules/probot/node_modules/@octokit/request/dist-node/index.js:86
      const error = new requestError.RequestError(toErrorMessage(data), status, {
                    ^

RequestError [HttpError]: Not Found
    at /opt/safe-settings/node_modules/probot/node_modules/@octokit/request/dist-node/index.js:86:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async sendRequestWithRetries (/opt/safe-settings/node_modules/octokit-auth-probot/node_modules/@octokit/auth-app/dist-node/index.js:398:12)
    at async Job.doExecute (/opt/safe-settings/node_modules/bottleneck/light.js:405:18) {
  status: 404,
  response: {
    url: 'https://api.github.com/repos/x/x/environments/release/deployment-branch-policies',
    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-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
      'content-encoding': 'gzip',
      'content-security-policy': "default-src 'none'",
      'content-type': 'application/json; charset=utf-8',
      date: 'Wed, 22 Jan 2025 17:48:16 GMT',
      'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
      server: 'github.com',
      'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
      'transfer-encoding': 'chunked',
      vary: 'Accept-Encoding, Accept, X-Requested-With',
      'x-accepted-github-permissions': 'actions=read',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'deny',
      'x-github-api-version-selected': '2022-11-28',
      'x-github-media-type': 'github.v3; format=json',
      'x-github-request-id': '0C43:11797C:DBF949:E1D473:67912F60',
      'x-ratelimit-limit': '15000',
      'x-ratelimit-remaining': '14457',
      'x-ratelimit-reset': '1737569696',
      'x-ratelimit-resource': 'core',
      'x-ratelimit-used': '543',
      'x-xss-protection': '0'
    },
    data: {
      message: 'Not Found',
      documentation_url: 'https://docs.github.com/rest/deployments/branch-policies#list-deployment-branch-policies',
      status: '404'
    }
  },
  request: {
    method: 'GET',
    url: 'https://api.github.com/repos/x/environments/release/deployment-branch-policies',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'probot/12.3.4 octokit-core.js/3.6.0 Node.js/20.18.1 (linux; x64)',
      authorization: 'token [REDACTED]'
    },
    request: { hook: [Function: bound bound register] }
  }
}

Context

Are you using the hosted instance of probot/settings or running your own?

If running your own instance, are you using it with github.com or GitHub Enterprise?

Version of probot/settings

Version of GitHub Enterprise

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions