Skip to content

TypeError: github.repos.createOrUpdateEnvironment is not a function - Octokit.js Support up-to-date? #133

Description

@phonomenal

Is your feature request related to a problem? Please describe.
Trying to use github-script for environments but getting this error message:
TypeError: github.repos.createOrUpdateEnvironment is not a function

Describe the solution you'd like
Would you all be able to update the version of Octokit.js that supports Repo Environments

Describe alternatives you've considered
Using actions to post the HTTP response for environment creation

Additional context
Add any other context or screenshots about the feature request here.
image

Activity

  1. github-actions commented on Jun 12, 2021

    @github-actions

    This issue is stale because it has been open for 60 days with no activity. Remove the "Stale" label or comment on the issue, or it will be closed in 7 days.

  2. Simran-B commented on Jun 13, 2021

    @Simran-B

    Just ran into a similar issue:
    Error: Unhandled error: TypeError: github.actions.getEnvironmentPublicKey is not a function

    Several functions were added to Octokit here: octokit/octokit.js#2025
    I suppose github-script needs to bump its dependencies?

  3. Simran-B commented on Jun 25, 2021

    @Simran-B

    I got it to work with a modified version of this action (bumped deps):

    name: Secrets
    
    on:
      push:
        branches:
          - main
    
    jobs:
      set-secret:
        name: Create or update environment secret
        runs-on: ubuntu-latest
        steps:
          - name: Install tweetsodium
            run: |
              npm install tweetsodium
          - uses: Simran-B/github-script@main # has updated dependencies (for testing only!)
            id: update-secret
            with:
              github-token: ${{ secrets.PAT }} # Personal access token required
              # (also for retrieving the env public key, despite what the documentation claims)
              script: |
                const sodium = require('tweetsodium')
    
                const envName = "prod"
                const secretName = "MY_SECRET"
                const value = "New secret value"
    
                const pkey = await github.rest.actions.getEnvironmentPublicKey({
                  repository_id: context.payload.repository.id,
                  environment_name: envName,
                })
    
                const messageBytes = Buffer.from(value)
                const keyBytes = Buffer.from(pkey.data.key, "base64")
                const encryptedBytes = sodium.seal(messageBytes, keyBytes)
                const encrypted = Buffer.from(encryptedBytes).toString("base64")
    
                const result = await github.rest.actions.createOrUpdateEnvironmentSecret({
                  repository_id: context.payload.repository.id,
                  environment_name: envName,
                  secret_name: secretName,
                  encrypted_value: encrypted,
                  key_id: pkey.data.key_id,
                })
                console.log(result.status)
  4. dcousineau-godaddy commented on Jul 15, 2021

    @dcousineau-godaddy

    We're dealing with a similar issue, where we get a TypeError: github.repos.deleteAnEnvironment is not a function (but github.repos.createDeploymentStatus in the immediately prior job step succeeds)

  5. github-actions commented on Sep 18, 2021

    @github-actions

    This issue is stale because it has been open for 60 days with no activity. Remove the "Stale" label or comment on the issue, or it will be closed in 7 days.

  6. IronSean commented on Sep 21, 2021

    @IronSean

    Hello I'm also experiencing this issues with "github.repos.deleteAnEnvironment is not a function", which is frustrating as we're trying to clean up environments we create per PR.

  7. IronSean commented on Sep 22, 2021

    @IronSean

    I dug into it and saw that the oktokit versions in this action were very out of date, meaning they didn't expose many newer REST edpoints. I've bumped them up in #191 as far as they can go without breaking changes, and anyone can test it with action ironsean/github-script@v-test for now if they'd like.

  8. joshmgross commented on Sep 24, 2021

    @joshmgross
    Contributor

    👋 This should now be fixed in v5 of this action - https://github.com/actions/github-script/releases/tag/v5.0.0

    You'll need to use github.rest.repos.createOrUpdateEnvironment due to breaking changes in Octokit, see https://github.com/actions/github-script#breaking-changes-in-v5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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