Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 2, 2025

Overview

This PR migrates the GitHub API client from @octokit/action to @octokit/core to improve maintainability and follow official Octokit recommendations. The @octokit/action package is designed specifically for direct JavaScript usage in GitHub Actions workflows, while @octokit/core provides a more general and future-proof approach.

Changes Made

Dependencies

  • Removed: @octokit/action@^6.0.7
  • Added: @octokit/core@^7.0.2 and @octokit/plugin-rest-endpoint-methods@^16.0.0

Code Changes

  • Updated src/install.ts to use @octokit/core with explicit GITHUB_TOKEN authentication
  • Enhanced error handling to throw a clear error message when GITHUB_TOKEN is missing
  • Modified the findLatestVersion() function to explicitly check for and require GITHUB_TOKEN

Testing Improvements

  • Added Jest mocks to handle ES module compatibility with the new Octokit packages
  • Enhanced test coverage with a new test case for missing GITHUB_TOKEN scenario
  • Updated Jest configuration to properly handle the new dependencies

Configuration Updates

  • Updated ESLint configuration to handle the new package imports
  • Minor README update to use current GitHub API documentation links

Behavior Changes

Before

// Automatic token handling - would fail silently in some cases
const octokit = new Octokit()
const response = await octokit.repos.getLatestRelease({...})

After

// Explicit token handling with clear error messages
const token = process.env.GITHUB_TOKEN
if (!token) {
  throw new Error('GITHUB_TOKEN environment variable is required to fetch the latest version')
}
const MyOctokit = Octokit.plugin(restEndpointMethods)
const octokit = new MyOctokit({ auth: token })
const response = await octokit.rest.repos.getLatestRelease({...})

Backward Compatibility

Fully backward compatible - No breaking changes to the public API. Users will continue to use the action exactly as before, but will now receive clearer error messages when GITHUB_TOKEN is missing.

Testing

All existing tests pass, plus new test coverage for:

  • ✅ Latest version installation with GITHUB_TOKEN provided
  • ✅ Clear error message when GITHUB_TOKEN is missing
  • ✅ All existing version-specific installations continue to work

Benefits

  1. Better maintainability: Using the officially recommended Octokit approach
  2. Clearer error messages: Users now get explicit feedback when GITHUB_TOKEN is missing
  3. Future-proof: Easier to update and maintain with future Octokit releases
  4. Better testing: Improved test coverage with proper mocking strategy

The migration ensures that the action continues to work exactly as expected while providing a more robust foundation for future development.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] @octokit/actionから@octokit/coreへの移行と認証処理の明示化 Migrate from @octokit/action to @octokit/core for better maintainability Jun 2, 2025
@Copilot Copilot AI requested a review from KengoTODA June 2, 2025 04:27
Copilot finished work on behalf of KengoTODA June 2, 2025 04:27
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
"@typescript-eslint/unbound-method": "error",
"import/no-unresolved": ["error", { "ignore": ["@octokit/core", "@octokit/plugin-rest-endpoint-methods"] }]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot why this change is necessary for this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ESLint rule change is necessary because the new @octokit/core and @octokit/plugin-rest-endpoint-methods packages are ES modules (they have "type": "module" in their package.json), which causes ESLint's import/no-unresolved rule to fail to resolve their imports. Without this ignore rule, ESLint throws errors like "Unable to resolve path to module '@octokit/core'". The rule specifically ignores these two packages while maintaining import resolution checking for all other dependencies. Commit: 53879e5

Copilot finished work on behalf of KengoTODA June 3, 2025 01:55
@KengoTODA KengoTODA marked this pull request as ready for review June 3, 2025 02:24
@KengoTODA KengoTODA merged commit 4029b4a into main Jun 3, 2025
7 checks passed
@KengoTODA KengoTODA deleted the copilot/fix-b972a9c2-efd5-42f8-bee2-e070265e19d7 branch June 3, 2025 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants