feat: implement license section generation with GitHub API integration and core license service#34
feat: implement license section generation with GitHub API integration and core license service#34
Conversation
|
@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>
| // Fallback to reading license file directly if no license info from GitHub | ||
| if (!licenseInfo) { | ||
| licenseInfo = this.getLicenseFromFile(); | ||
| } |
There was a problem hiding this comment.
Fallback must implemented in packages/repository/github/src/github-repository.provider.ts
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Move this to a core license service
There was a problem hiding this comment.
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>
Fixed both feedback items:
All changes tested and compiled successfully. Commit c77e28a. |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Improve tests for asserting license behavior
There was a problem hiding this comment.
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>
Addressed all feedback items:
All changes maintain the existing license detection workflow while improving error handling and test coverage. Commit 0d03318. |
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
GitHubRepositoryProviderEnhanced License Section Output
SPDX-License-Identifier: Apache-2.0)Core License Service Architecture
LicenseServicein core package for license detection logicGitHubRepositoryProviderto dedicated serviceSmart Fallback System
LICENSE,LICENSE.txt,LICENSE.md, etc.)Example Output
With GitHub API License:
With Local License File:
No License Information:
No license section is generated when no license information is available from either GitHub API or local files.
Implementation Details
Repositorytype to include optional license informationGitHubRepositoryProviderwithgetLicenseInfo()method using GraphQLLicenseServicein core package for reusable license detectionLicenseSectionGeneratorto use repository license data without fallbacksFixes #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.