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

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

Closed
phonomenal opened this issue Apr 12, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@phonomenal
Copy link

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

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label Jun 12, 2021
@Simran-B
Copy link

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?

@Simran-B
Copy link

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)

@joshmgross joshmgross added the bug Something isn't working label Jun 28, 2021
@dcousineau-godaddy
Copy link

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)

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label Sep 18, 2021
@IronSean
Copy link

IronSean commented Sep 21, 2021

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.

@IronSean
Copy link

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.

@joshmgross
Copy link
Member

👋 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
Labels
bug Something isn't working
Projects
None yet
6 participants
@IronSean @Simran-B @joshmgross @phonomenal @dcousineau-godaddy and others