-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance license header script and update README #2
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
Conversation
README.md was streamlined for clarity, removing redundant sections and updating setup instructions. Add-LicenseHeaders.ps1 now supports more file types, auto-detects author metadata from Git config, and generates dynamic license headers with customizable fields. Header detection logic was improved for broader compatibility.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this 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 enhances the license header automation script to be more generic and reusable while cleaning up the documentation. The main goal is to remove hardcoded author/organization references and make the tooling applicable across different projects and users.
- Enhanced
Add-LicenseHeaders.ps1with parameterized metadata injection and auto-detection from Git config - Updated license header templates to use generic placeholders instead of hardcoded VA-specific information
- Cleaned up README.md by removing hardcoded copyright blocks and streamlining setup instructions
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| copilot-instructions/Add-LicenseHeaders.ps1 | Added metadata parameters, auto-detection logic, and genericized license templates |
| README.md | Removed hardcoded copyright header and simplified quick start instructions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| # Auto-detect metadata if not provided | ||
| if (-not $AuthorName -or [string]::IsNullOrWhiteSpace($AuthorName)) { $AuthorName = (Get-GitConfigValue 'user.name'); if (-not $AuthorName) { $AuthorName = $env:USERNAME } } | ||
| if (-not $Email -or [string]::IsNullOrWhiteSpace($Email)) { $Email = (Get-GitConfigValue 'user.email'); if (-not $Email) { $Email = '' } } | ||
| if (-not $Organization) { $Organization = '' } | ||
| if (-not $Team) { $Team = '' } | ||
| if (-not $ProjectName -or [string]::IsNullOrWhiteSpace($ProjectName)) { $ProjectName = Split-Path -Leaf (Split-Path -Parent $ScriptPath) } | ||
| if (-not $LicenseType) { $LicenseType = 'Apache-2.0' } | ||
| if (-not $ComplianceNote) { $ComplianceNote = 'Internal Use Only' } |
Copilot
AI
Aug 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These auto-detection lines are difficult to read and maintain due to complex nested conditionals on single lines. Consider refactoring into a helper function or breaking into multiple lines for better readability.
| # Auto-detect metadata if not provided | |
| if (-not $AuthorName -or [string]::IsNullOrWhiteSpace($AuthorName)) { $AuthorName = (Get-GitConfigValue 'user.name'); if (-not $AuthorName) { $AuthorName = $env:USERNAME } } | |
| if (-not $Email -or [string]::IsNullOrWhiteSpace($Email)) { $Email = (Get-GitConfigValue 'user.email'); if (-not $Email) { $Email = '' } } | |
| if (-not $Organization) { $Organization = '' } | |
| if (-not $Team) { $Team = '' } | |
| if (-not $ProjectName -or [string]::IsNullOrWhiteSpace($ProjectName)) { $ProjectName = Split-Path -Leaf (Split-Path -Parent $ScriptPath) } | |
| if (-not $LicenseType) { $LicenseType = 'Apache-2.0' } | |
| if (-not $ComplianceNote) { $ComplianceNote = 'Internal Use Only' } | |
| # Helper: Get metadata value with fallback logic | |
| function Get-MetadataValue { | |
| param( | |
| [Parameter(Mandatory=$true)][string]$CurrentValue, | |
| [Parameter(Mandatory=$true)][ScriptBlock]$Fallback | |
| ) | |
| if (-not $CurrentValue -or [string]::IsNullOrWhiteSpace($CurrentValue)) { | |
| return & $Fallback | |
| } | |
| return $CurrentValue | |
| } | |
| # Auto-detect metadata if not provided | |
| $AuthorName = Get-MetadataValue $AuthorName { | |
| $name = Get-GitConfigValue 'user.name' | |
| if ($name) { return $name } | |
| return $env:USERNAME | |
| } | |
| $Email = Get-MetadataValue $Email { | |
| $email = Get-GitConfigValue 'user.email' | |
| if ($email) { return $email } | |
| return '' | |
| } | |
| $Organization = Get-MetadataValue $Organization { return '' } | |
| $Team = Get-MetadataValue $Team { return '' } | |
| $ProjectName = Get-MetadataValue $ProjectName { Split-Path -Leaf (Split-Path -Parent $ScriptPath) } | |
| $LicenseType = Get-MetadataValue $LicenseType { return 'Apache-2.0' } | |
| $ComplianceNote = Get-MetadataValue $ComplianceNote { return 'Internal Use Only' } |
| $ContentText -match '(^/\*.*?(Licensed under|Copyright).*?\*/)' -or # block comment with license | ||
| $ContentText -match '(^<#.*?(Licensed under|Copyright).*?#>)' # ps1 block comment with license |
Copilot
AI
Aug 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex patterns use ^ anchor which matches start of string, but $ContentText is a multiline string joined with newlines. These patterns will only match if the license header is at the very beginning of the file. Consider using multiline mode (?m)^ or \n to match line starts within the content.
| $ContentText -match '(^/\*.*?(Licensed under|Copyright).*?\*/)' -or # block comment with license | |
| $ContentText -match '(^<#.*?(Licensed under|Copyright).*?#>)' # ps1 block comment with license | |
| $ContentText -match '(?m)^/\*.*?(Licensed under|Copyright).*?\*/' -or # block comment with license | |
| $ContentText -match '(?m)^<#.*?(Licensed under|Copyright).*?#>' # ps1 block comment with license |
This pull request updates the repository to improve license header automation, metadata handling, and documentation clarity. The main focus is on making the license header script more flexible and generic so it can be reused across projects and by different users, while also cleaning up and streamlining the setup guide.
License Header Automation Improvements:
Add-LicenseHeaders.ps1script now supports additional file types (md,txt,bat,psm,json) and allows users to inject custom metadata such as author name, email, organization, team, project name, license type, and compliance note. Metadata is auto-detected from Git config or environment variables if not provided. [1] [2]Documentation and Setup Guide Updates:
README.mdhas been cleaned up to remove hardcoded copyright/license blocks, clarify the quick start and local setup instructions, and streamline guidance for accessing the interactive and printable guides. [1] [2] [3] [4]Versioning:
1.0.1to reflect these improvements.