Skip to content

octokit instance from README examples doesn't work #545

Description

@mutantcornholio

Simple examples like this

            const script = require('./path/to/script.js')
            console.log(script({octokit, context}))

lead to

ReferenceError: octokit is not defined
    at eval (eval at callAsyncFunction (/Users/runner/work/_actions/actions/github-script/v7/dist/index.js:35424:16), <anonymous>:5:3)
    at callAsyncFunction (/Users/runner/work/_actions/actions/github-script/v7/dist/index.js:35425:12)
    at main (/Users/runner/work/_actions/actions/github-script/v7/dist/index.js:355[22](https://github.com/paritytech/revive-workflow-test/actions/runs/13367697259/job/37329093073#step:3:23):26)
    at /Users/runner/work/_actions/actions/github-script/v7/dist/index.js:35497:1
    at /Users/runner/work/_actions/actions/github-script/v7/dist/index.js:35553:3
    at Object.<anonymous> (/Users/runner/work/_actions/actions/github-script/v7/dist/index.js:35556:12)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
Error: Unhandled error: ReferenceError: octokit is not defined

Replacing octokit with github works. Is the README wrong and should be changed to github only, or is it a bug?

Activity

  1. juwens commented on Feb 26, 2025

    @juwens

    Until a month ago, and i guess still in the stable/release branch, this variable does not exist. I dunny, if they will release it with v8 or patch v7.

    your code is called like this:

    const result = await callAsyncFunction(
      {
        require: wrapRequire,
        __original_require__: __non_webpack_require__,
        github,
        context,
        core,
        exec,
        glob,
        io
      },
      script
    )
    

    Then octokit was added as an alias for github:

    4024541
    #508

          require: wrapRequire,
          __original_require__: __non_webpack_require__,
          github,
    +      octokit: github,
          context,
          core,
          exec,
    

    But when you console.log(github) it's an Octokit object

        '2': NewOctokit {
          request: [Function],
          graphql: [Function],
          log: [Object],
          hook: [Function],
          auth: [AsyncFunction],
          rest: [Object],
          paginate: [Function],
          retry: [Object]
        },
    

    Summary: octokit variable was introduced as an alias to the github variable, and github itself is actually octokit object. So we have an alias with the right name, created from a variable with the wrong name, and in the end pointing to the right object 💫

  2. mutantcornholio commented on Feb 26, 2025

    @mutantcornholio
    Author

    But when you console.log(github) it's an Octokit object

    and in the end pointing to the right object 💫

    github points to the right object, but not octokit

  3. self-assigned this
    on Feb 26, 2025
  4. joshmgross commented on Feb 26, 2025

    @joshmgross
    Contributor

    👋 Sorry about that, we're not ready to release a new major version of this action with the changes in #508 so the README updates were premature.

    #557 will fix the README examples.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions