Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 3, 2025

❔What, Why & How

Contributors updating RELEASENOTES.md need to be notified when a new AL-Go version is released so they can move their changes above the new version section to maintain proper changelog structure.

Solution:

  • PowerShell Script (Internal/Scripts/CommentOnExistingReleaseNotesPrs.ps1): Manual script using GitHub CLI to add review comments directly on RELEASENOTES.md file changes in open PRs
  • Automatic Version Detection: Script automatically detects the current version from RELEASENOTES.md using multiline regex pattern that supports vX.Y format only
  • Inline Documentation: Complete usage instructions and implementation details in the script header

Usage:

# Recommended: Use gh auth login for secure authentication
gh auth login

# Or set token as environment variable (may be visible in shell history)
$env:GH_TOKEN = "your-token-here"
# or
$env:GITHUB_TOKEN = "your-token-here"

# Run the script
pwsh Internal/Scripts/CommentOnExistingReleaseNotesPrs.ps1

Key Features:

  • GitHub CLI Integration: Uses gh commands for better readability and maintainability
  • Review Comments on File Changes: Adds comments directly on RELEASENOTES.md file in the "Files changed" tab at line 1, not as general PR comments
  • Version Release Notification: Informs contributors that a new AL-Go version has been released and their changes need to be moved
  • Automatic Version Detection: No manual updates needed when releasing new versions (supports vX.Y format only)
  • Fail-fast Error Handling: Errors out if version cannot be detected (no fallback defaults)
  • Version-Specific Comment Checking: Verifies if review comments for the current version exist on RELEASENOTES.md before adding new ones, allowing re-commenting when version changes
  • Comprehensive Reporting: Detailed summary with success/skip/fail counts and failed PR list
  • Robust Error Handling: Handles edge cases (empty PR lists, null results, API failures) with proper array checking
  • Secure Authentication: Recommends gh auth login with warnings about shell history exposure
  • Resource Cleanup: Finally block ensures temporary files are always removed
  • Exit Codes: Returns 0 for success, 1 for failures
  • Idiomatic PowerShell: Uses @() array operator for clean, simple array handling
  • Self-Documenting: All documentation is in the script header for easy maintenance
  • Code Quality: UTF-8 with BOM encoding, passes all pre-commit checks and PSScriptAnalyzer validation with zero alerts
  • Scalability: Supports up to 1000 open PRs (maximum limit for gh CLI)
  • Progress Suppression: Includes $ProgressPreference = "SilentlyContinue" for cleaner output in automated scenarios
  • Naming Convention: Script follows PascalCase naming convention consistent with other PowerShell scripts in the repository

Comment Message:

A new version of AL-Go (vX.Y) has been released.

Please move your release notes changes to above the ## vX.Y section in the RELEASENOTES.md file.

This ensures your changes are included in the next release rather than being listed under an already-released version.

Implementation Details:

  • Uses multiline regex (?m)^##\s*v(\d+\.\d+) for version detection (major.minor format only)
  • Creates review comments using GitHub API endpoint /repos/{owner}/{repo}/pulls/{pr}/comments with required line: 1 field
  • Review comments include path: "RELEASENOTES.md", line: 1, and the PR's head commit SHA
  • Checks for existing review comments on RELEASENOTES.md file with version-specific text: "A new version of AL-Go (vX.Y) has been released."
  • Version-specific checking prevents false positives from comments about different versions and allows re-commenting when a new version is released
  • Properly validates empty arrays using @($existingReviewComments).Count -gt 0 check
  • Uses Write-Host with error indicators (✗) for consistent error reporting instead of Write-Warning
  • Tracks success, skip, and fail counts separately
  • Lists specific PR numbers that failed for manual review
  • Uses @() array operator for simplified null-safe array handling
  • Properly escapes $searchText to prevent issues with special characters in jq filters
  • Fetches up to 1000 open PRs (maximum for gh CLI) with documentation note about limitation
  • Suppresses progress bars with $ProgressPreference = "SilentlyContinue" for consistency with other scripts in the repository
  • Discards API response output using Out-Null to avoid unused variable warnings
  • Script is located in Internal/Scripts/ alongside other internal utility scripts
  • File encoded with UTF-8 with BOM for PSScriptAnalyzer compliance
  • Code follows repository standards with no trailing whitespace
  • File name uses PascalCase (CommentOnExistingReleaseNotesPrs.ps1) to match repository conventions (e.g., GetOwnerForE2ETests.ps1, RemoveTempRepos.ps1)

Requirements:

  • GitHub CLI (gh) installed: https://cli.github.com/
  • GitHub authentication (via gh auth login or token)
  • PowerShell 7 or later

Related to issue: #

✅ Checklist

  • Add tests (E2E, unit tests)
  • Update RELEASENOTES.md
  • Update documentation (e.g. for new settings or scenarios)
  • Add telemetry
Original prompt

Go through all open PRs that change the release notes and add a comment that it needs to be moved above the new version section.


💡 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 changed the title [WIP] Add comment to release notes PRs Automate reminder comments on PRs modifying release notes Dec 3, 2025
Copilot AI requested a review from mazhelez December 3, 2025 10:46
@mazhelez
Copy link
Collaborator

mazhelez commented Dec 3, 2025

@copilot Great work! But I expected you to add the comments to the PRs yourself. Can you do it?

Copy link
Contributor Author

Copilot AI commented Dec 3, 2025

@copilot Great work! But I expected you to add the comments to the PRs yourself. Can you do it?

I've analyzed all 14 open PRs that modify RELEASENOTES.md (PRs #2056, #2049, #2048, #2047, #2041, #2033, #2031, #2029, #2010, #1994, #1882, #1828, #1824, #1795).

However, I don't have direct API access to add comments to other users' PRs. The workflow I created (.github/workflows/check-release-notes-prs.yml) will automatically add the reminder comment to new PRs going forward when they modify RELEASENOTES.md.

For the existing PRs, you'll need to either:

  1. Run the PowerShell script .github/scripts/comment-on-existing-release-notes-prs.ps1 with a GitHub token that has PR comment permissions
  2. Manually trigger a workflow run with appropriate permissions

Would you like me to create a manual workflow that you can trigger to add comments to existing PRs?

Copy link
Contributor Author

Copilot AI commented Dec 4, 2025

@copilot the PSScriptAnalyzer is failing. The error is related to the file encoding. Please make sure it's UTF-8 with BOM.

Fixed in commit 0f405e7. Added UTF-8 BOM (EF BB BF) to the script file to comply with PSScriptAnalyzer requirements.

@mazhelez
Copy link
Collaborator

mazhelez commented Dec 8, 2025

@copilot please fix the open comments on the PR

Copy link
Contributor Author

Copilot AI commented Dec 8, 2025

@copilot please fix the open comments on the PR

Fixed in commit e26d8d6. All open PR review comments have been addressed:

  1. Added line = 1 field to review comment payload (required by GitHub API)
  2. Fixed empty array check using @($existingReviewComments).Count -gt 0
  3. Changed Write-Warning to Write-Host for consistency in error messages
  4. Increased PR limit from 100 to 1000 with documentation note
  5. Added $ProgressPreference = "SilentlyContinue" for consistency with other scripts
  6. Added proper escaping for $searchText to prevent special character issues

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI requested a review from mazhelez December 9, 2025 10:04
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.

2 participants