Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 21, 2025

This PR adds comprehensive support for GitHub App installation tokens at the enterprise level, addressing the limitation that there is no direct API endpoint to retrieve enterprise installation IDs.

🚀 Key Features

Enterprise Account Type Support

  • Added enterprise as a new account type option alongside existing org and user types
  • Enterprise installations use pagination through /app/installations API as a workaround for the missing direct endpoint
  • Automatic enterprise filtering by target_type === "Enterprise" with case-insensitive name matching

Intelligent Rate Limiting

  • Handles GitHub API rate limits during pagination with smart retry logic
  • Waits automatically if rate limit reset is within 5 minutes
  • Fails gracefully with clear error messages if rate limit exceeded for longer periods

Enterprise-Specific Validations

  • Owner field mandatory for enterprise account type (must specify enterprise slug/name)
  • Repository scoping not allowed - enterprise tokens are inherently enterprise-scoped
  • forceRepoScope not allowed in service connections for enterprise account type
  • Clear, actionable error messages for all validation failures

📋 Usage Examples

Basic Enterprise Token Generation

steps:
- task: create-github-app-token@1
  inputs:
    githubAppConnection: 'MyGitHubAppConnection'
    accountType: 'enterprise'
    owner: 'my-enterprise'  # Required for enterprise

Enterprise with Direct Certificate

steps:
- task: create-github-app-token@1
  inputs:
    accountType: 'enterprise'
    owner: 'my-enterprise'
    appClientId: 'lv2313qqwqeqweqw'
    certificate: '$(githubAppPem)'
    # Note: repositories input not allowed for enterprise

🔧 Technical Implementation

Core Infrastructure Changes

  • New constant: ACCOUNT_TYPE_ENTERPRISE = 'enterprise'
  • Enhanced validation: Updated validateAccountType() to include enterprise
  • Pagination method: getEnterpriseInstallationId() with comprehensive error handling
  • Updated method signature: getInstallationId() now accepts accountType string instead of boolean isOrg

Configuration Updates

  • task.json: Added enterprise option to accountType field with updated help text
  • vss-extension.json: Enhanced forceRepoScope description to clarify enterprise restrictions
  • README.md: Comprehensive documentation with usage examples and troubleshooting guide

🧪 Testing & Quality

  • 127 tests passing (16 new enterprise-specific tests added)
  • 98.47% code coverage with comprehensive edge case testing
  • Enterprise scenarios covered:
    • Multi-page pagination
    • Rate limiting and retry logic
    • Authentication and permission errors
    • Multiple enterprise installations
    • Validation failures with clear error messages

📚 Documentation

Updated Input Parameters

Parameter Enterprise Support
accountType Now accepts enterprise option
owner Required for enterprise (enterprise slug/name)
repositories Not allowed for enterprise account type
forceRepoScope Not allowed for enterprise account type

Enterprise vs Organization/User Comparison

Feature Organization User Enterprise
Repository scoping ✅ Supported ✅ Supported ❌ Not supported
forceRepoScope ✅ Supported ✅ Supported ❌ Not supported
Owner parameter Optional* Optional* Required
Direct API lookup ✅ Yes ✅ Yes ❌ Uses pagination workaround

*Owner is optional for org/user if using GitHub repository provider (auto-extracted from Build.Repository.Name)

Troubleshooting Guide

  • Enterprise installation lookup issues
  • Multiple enterprise installations handling
  • Rate limiting during pagination
  • Enterprise account type restrictions

⚠️ Important Notes

  • Workaround Implementation: Enterprise installation ID lookup uses pagination through all app installations since GitHub provides no direct API endpoint for enterprise installations (unlike organizations and repositories)
  • Backward Compatibility: All existing functionality for org and user account types remains unchanged
  • API Rate Limits: Enterprise installations consume more API calls due to pagination but include intelligent rate limiting and retry logic

Fixes #9.


💡 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 AI and others added 4 commits July 21, 2025 15:36
Co-authored-by: tspascoal <7847935+tspascoal@users.noreply.github.com>
Co-authored-by: tspascoal <7847935+tspascoal@users.noreply.github.com>
Co-authored-by: tspascoal <7847935+tspascoal@users.noreply.github.com>
Co-authored-by: tspascoal <7847935+tspascoal@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for enterprise installation tokens Add support for enterprise installation tokens Jul 21, 2025
Copilot AI requested a review from tspascoal July 21, 2025 15:53
Fix implementation. App was incorrectly searched in the enterprise and not looking at the actual app.

- Fix pagination
- Improved rate limit support
- Improved inputs validation
- Bumped extension and task version
@tspascoal tspascoal requested a review from Copilot July 26, 2025 22:44
Copy link
Contributor

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 PR adds comprehensive support for GitHub App installation tokens at the enterprise level, addressing the limitation that there is no direct API endpoint to retrieve enterprise installation IDs. The implementation uses pagination through the /app/installations API as a workaround and includes intelligent rate limiting and enterprise-specific validations.

  • Adds enterprise as a new account type option with mandatory owner field requirement
  • Implements pagination-based enterprise installation lookup with rate limiting protection
  • Adds comprehensive validation for enterprise-specific restrictions (no repository scoping, no forceRepoScope)

Reviewed Changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vss-extension.json Updates version and enhances forceRepoScope description for enterprise restrictions
create-github-app-token/task.json Adds enterprise option to accountType field and updates help text
create-github-app-token/src/utils/constants.ts Adds ACCOUNT_TYPE_ENTERPRISE constant and JWT_CLOCK_DRIFT_SECONDS
create-github-app-token/src/utils/validation.ts Updates validation to include enterprise account type
create-github-app-token/src/tasks/run.ts Implements enterprise-specific validation logic and error handling
create-github-app-token/src/core/github-service.ts Adds getEnterpriseInstallationId method with pagination and rate limiting
create-github-app-token/package.json Updates axios dependency version
README.md Adds comprehensive enterprise documentation and usage examples
test files Extensive test coverage for enterprise functionality
Files not reviewed (1)
  • create-github-app-token/package-lock.json: Language not supported
Comments suppressed due to low confidence (2)

create-github-app-token/package.json:17

  • Axios version 1.11.0 does not exist. As of my knowledge cutoff in January 2025, the latest axios version was around 1.7.x. Please verify this version exists or use a valid version.
    "axios": "^1.11.0",

@github-actions
Copy link

github-actions bot commented Jul 26, 2025

File Coverage Lines Branches
All files 95% 97% 93%
github-service.ts 97% 98% 96%
proxy-config.ts 93% 96% 90%
post.ts 81% 96% 66%
run.ts 96% 97% 94%

Minimum allowed coverage is 80%

Generated by 🐒 cobertura-action against 960bd7e

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tspascoal tspascoal marked this pull request as ready for review July 26, 2025 22:46
@tspascoal tspascoal merged commit 752d83b into main Jul 26, 2025
6 checks passed
@tspascoal tspascoal deleted the copilot/fix-9 branch July 26, 2025 23:01
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.

Add support for enterprise installation tokens

2 participants