Skip to content

Add support for enterprise level GitHub Apps #263

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

theztefan
Copy link

This pull request introduces support for generating GitHub App tokens for enterprise-level installations. It includes updates to the main logic, input validation, and new tests to ensure functionality and edge case handling.

Code Changes

  • action.yml: Added enterprise input with proper description and validation hints.
  • main.js: Added enterprise input reading and parameter passing.
  • lib/main.js:
    • Added enterprise parameter to function signature.
    • Added input validation for mutual exclusivity.
    • Added enterprise branch in the token generation logic.
    • Added getTokenFromEnterprise function following existing patterns but with difference on how we get the installation. Currently we do not have a way to get the installation for an enterprise directly, so the implementation lists all installations and filter for the enterprise one to take the id. This works fine for now as the Enterprise GitHub Apps cannot be installed on multiple enterprises but something to potentially change when we get dedicated API.
  • package.json: bumped the version.

Documentation

  • Updated README.md to include instructions for using the new enterprise input.

Tests

  • Added multiple tests in the tests/ directory to verify the behavior of the enterprise input:
    • Tests for mutual exclusivity with owner and repositories.
    • Tests for successful token generation with and without permissions.
    • Test for handling scenarios where no enterprise installation is found.
  • All existing functionality remains unchanged. The enterprise feature is additive and does not affect existing users, so all previous tests pass as well.

Refs:

@Copilot Copilot AI review requested due to automatic review settings July 8, 2025 15:24
@theztefan theztefan requested a review from a team as a code owner July 8, 2025 15:24
Copilot

This comment was marked as outdated.

@parkerbxyz parkerbxyz requested a review from Copilot July 11, 2025 19:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds support for generating GitHub App tokens for enterprise-level installations, allowing GitHub Apps to authenticate with enterprise management APIs. The implementation includes comprehensive input validation to ensure mutual exclusivity with existing repository-scoped functionality.

Key changes include:

  • Added enterprise input parameter with validation for mutual exclusivity with owner and repositories
  • Implemented enterprise installation discovery by listing all installations and filtering for enterprise type
  • Added comprehensive test coverage for success scenarios, error cases, and input validation

Reviewed Changes

Copilot reviewed 13 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
action.yml Added enterprise input definition
main.js Added enterprise parameter reading and passing
lib/main.js Core logic for enterprise token generation and validation
package.json Version bump to 2.0.7
README.md Documentation for enterprise usage
tests/*.js Comprehensive test suite for enterprise functionality
tests/snapshots/index.js.md Test output snapshots for verification
Comments suppressed due to low confidence (1)

// Find the enterprise installation
const enterpriseInstallation = response.data.find(
installation => installation.target_type === "Enterprise" &&
installation.account?.slug === enterprise
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

The comparison uses installation.account?.slug but the test snapshots show installation.account.login being used. Based on the test data structure, this should be installation.account?.login === enterprise to match the enterprise name correctly.

Suggested change
installation.account?.slug === enterprise
installation.account?.login === enterprise

Copilot uses AI. Check for mistakes.

`Inputs 'owner' and 'repositories' are not set. Creating token for this repository (${owner}/${repo}).`
);
}
skipTokenRevoke,

Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

[nitpick] The trailing comma followed by an empty line and then the closing parenthesis creates inconsistent formatting. Either move the closing parenthesis to the same line or remove the empty line.

Suggested change

Copilot uses AI. Check for mistakes.

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.

1 participant