Skip to content

feat: implement license section generation with GitHub API integration and core license service#34

Merged
neilime merged 5 commits intomainfrom
copilot/fix-33
Aug 7, 2025
Merged

feat: implement license section generation with GitHub API integration and core license service#34
neilime merged 5 commits intomainfrom
copilot/fix-33

Conversation

Copy link
Contributor

Copilot AI commented Aug 7, 2025

This PR implements automatic license section generation that fetches actual license information from the GitHub API, replacing the previous hardcoded MIT license approach.

Key Features

GitHub API Integration

  • Fetches license information using GitHub's GraphQL API via existing Octokit infrastructure
  • Retrieves license name, SPDX identifier, and API URL
  • Integrates seamlessly with the existing GitHubRepositoryProvider

Enhanced License Section Output

  • Displays actual license name (e.g., "Apache License 2.0", "MIT License")
  • Includes SPDX identifier for compliance (e.g., SPDX-License-Identifier: Apache-2.0)
  • Links to official GitHub license API endpoints
  • Uses repository owner as fallback author when manifest author is unavailable

Core License Service Architecture

  • Created reusable LicenseService in core package for license detection logic
  • Moved license file detection from GitHubRepositoryProvider to dedicated service
  • Enables license detection to be shared across different repository providers
  • Clean separation of concerns following the existing architectural patterns

Smart Fallback System

  • Falls back to local license file detection when GitHub API is unavailable
  • Supports common license file names (LICENSE, LICENSE.txt, LICENSE.md, etc.)
  • Intelligent license type detection for MIT, Apache 2.0, GPL, BSD, and ISC licenses
  • No default license generation - returns empty section when no license information is found

Example Output

With GitHub API License:

## License
This project is licensed under the Apache License 2.0.

SPDX-License-Identifier: Apache-2.0

Copyright © 2025 Apache Foundation

For more details, see the [license](https://api.github.com/licenses/apache-2.0).

With Local License File:

## License
This project is licensed under the MIT License.

SPDX-License-Identifier: MIT

Copyright © 2025 Repository Owner

See the [LICENSE](LICENSE) file for full license text.

No License Information:
No license section is generated when no license information is available from either GitHub API or local files.

Implementation Details

  • Extended core Repository type to include optional license information
  • Enhanced GitHubRepositoryProvider with getLicenseInfo() method using GraphQL
  • Created dedicated LicenseService in core package for reusable license detection
  • Updated LicenseSectionGenerator to use repository license data without fallbacks
  • Added comprehensive test coverage for all scenarios
  • Maintains backward compatibility and follows existing code patterns

Fixes #33.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Contributor Author

Copilot AI commented Aug 7, 2025

@neilime 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
Copilot AI changed the title [WIP] feat: implement "license" section generation feat: implement license section generation with GitHub API integration Aug 7, 2025
Copilot AI requested a review from neilime August 7, 2025 08:12
@neilime neilime marked this pull request as ready for review August 7, 2025 08:21
Copy link
Member

@neilime neilime left a comment

Choose a reason for hiding this comment

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

@copilot Handle feedback

Comment on lines +30 to +33
// Fallback to reading license file directly if no license info from GitHub
if (!licenseInfo) {
licenseInfo = this.getLicenseFromFile();
}
Copy link
Member

Choose a reason for hiding this comment

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

Fallback must implemented in packages/repository/github/src/github-repository.provider.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the fallback logic to GitHubRepositoryProvider.getLicenseInfo() as requested. The repository provider now handles both GitHub API fetching and local file fallback, while the LicenseSectionGenerator is simplified to only use the repository license data. Commit aa0e1bb.

Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
Copilot AI requested a review from neilime August 7, 2025 08:39
Copy link
Member

@neilime neilime left a comment

Choose a reason for hiding this comment

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

@copilot Fix feedbacks

Copy link
Member

Choose a reason for hiding this comment

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

Do not define default license

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the default license fallback. The license section generator now returns an empty buffer when no license information is available instead of defaulting to MIT license. Commit c77e28a.

return this.getLicenseFromFile();
}

private getLicenseFromFile(): { name: string; spdxId: string | null; url: string | null } | undefined {
Copy link
Member

Choose a reason for hiding this comment

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

Move this to a core license service

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved license detection logic to a new LicenseService in the core package. The GitHubRepositoryProvider now uses this service instead of implementing its own license detection. This creates a reusable service that can be used by other repository providers. Commit c77e28a.

…o core service

Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 7, 2025

@copilot Fix feedbacks

Fixed both feedback items:

  1. Removed default license fallback - license section generator now returns empty buffer when no license info is available
  2. Moved license detection logic to new core LicenseService for better architecture

All changes tested and compiled successfully. Commit c77e28a.

Copilot AI changed the title feat: implement license section generation with GitHub API integration feat: implement license section generation with GitHub API integration and core license service Aug 7, 2025
Copilot AI requested a review from neilime August 7, 2025 08:59
Copy link
Member

@neilime neilime left a comment

Choose a reason for hiding this comment

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

@copilot handle feedbacks

Copy link
Member

Choose a reason for hiding this comment

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

Add test for this new service

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comprehensive tests for the LicenseService in packages/core/src/repository/license.service.spec.ts. The tests cover license file detection, content parsing for all supported license types (MIT, Apache 2.0, GPL v2/v3, BSD 2/3-Clause, ISC), SPDX ID mapping, and error handling scenarios. Commit 0d03318.

}

private async getLicenseInfo(repositoryInfo: Repository): Promise<{ name: string; spdxId: string | null; url: string | null } | undefined> {
try {
Copy link
Member

Choose a reason for hiding this comment

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

Do not try catch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the try-catch block from the getLicenseInfo method. GitHub API errors will now bubble up naturally while maintaining the fallback to local license file detection when the API returns no license information. Commit 0d03318.

Copy link
Member

Choose a reason for hiding this comment

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

Improve tests for asserting license behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enhanced the GitHubRepositoryProvider tests with comprehensive license behavior scenarios including GitHub API license fetching, fallback to LicenseService, error propagation, and edge cases like missing repository data. The tests now properly mock and validate the complete license detection workflow. Commit 0d03318.

…rvice tests, improve GitHubRepositoryProvider license tests

Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 7, 2025

@copilot handle feedbacks

Addressed all feedback items:

  1. ✅ Removed try-catch from getLicenseInfo() method - errors now bubble up naturally
  2. ✅ Added comprehensive test suite for LicenseService covering all license types and edge cases
  3. ✅ Enhanced GitHubRepositoryProvider tests with detailed license behavior validation

All changes maintain the existing license detection workflow while improving error handling and test coverage. Commit 0d03318.

Copilot AI requested a review from neilime August 7, 2025 09:14
@neilime neilime merged commit 0670e4e into main Aug 7, 2025
13 of 15 checks passed
@neilime neilime deleted the copilot/fix-33 branch August 7, 2025 13:59
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.

feat: implement "license" section generation

2 participants