rest.js icon indicating copy to clipboard operation
rest.js copied to clipboard

[BUG]: types for octokit.rest.repos.createInOrg does not accept "internal" as visibility, despite it being valid

Open devjoes opened this issue 1 year ago • 4 comments

What happened?

I upgraded Octokit to version v20 of the API (by upgrading @actions/github to 6.0.0). This removed the internal option for visibility when calling octokit.rest.repos.createInOrg. When trying to call this method with either of the remaining options public or private and creating a repo within an organisation I get the error You need admin access to the organization before adding a repository to it.. If I bypass type checking and forcibly set this option back to internal then it works. This leads me to believe that this is an issue with the generated types.d.ts (or rather the underlying OpenApi spec.)

This is the workaround - notice the cast to any

    await octokit.rest.repos.createInOrg({
      org: repoOrg,
      name: repoName,
      description: productRepoDescription,
      visibility: 'internal'
    } as any);

Versions

@actions/github: 6.0.0 @octokit/openapi-types: 19.0.2 typescript: 5.1.6 node: 20.7.0 npm: 10.1.0

Relevant log output

When using `private`

{
  status: 403,
  response: {
    url: 'https://api.github.com/orgs/REMOVED/repos',
    status: 403,
    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: 'Fri, 17 Nov 2023 11:39:18 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-oauth-scopes': 'public_repo, repo',
      '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': 'D1EE:85F2:3BE93E30:3CA3C8E4:655750E6',
      'x-oauth-scopes': 'repo',
      'x-ratelimit-limit': '5000',
      'x-ratelimit-remaining': '4992',
      'x-ratelimit-reset': '1700224200',
      'x-ratelimit-resource': 'core',
      'x-ratelimit-used': '8',
      'x-xss-protection': '0'
    },
    data: {
      message: 'You need admin access to the organization before adding a repository to it.',
      documentation_url: 'https://docs.github.com/rest/repos/repos#create-an-organization-repository'
    }
  },
  request: {
    method: 'POST',
    url: 'https://api.github.com/orgs/REMOVED/repos',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-rest.js/20.0.2 octokit-core.js/5.0.1 Node.js/20.7.0 (linux; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"name":"joe-test-123","description":"test","visibility":"private"}',
    request: { hook: [Function: bound bound register] }
  }
}

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

devjoes avatar Nov 17 '23 12:11 devjoes