Sort GH_AW_RATE_LIMIT_EVENTS alphabetically#15018
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request aims to alphabetically sort the list of events in GH_AW_RATE_LIMIT_EVENTS by ordering the programmaticTriggers map in pkg/workflow/role_checks.go and updating test expectations to reflect this alphabetical ordering. The changes are intended to make the event list more maintainable and predictable.
Changes:
- Alphabetically sorted the
programmaticTriggersmap keys inpkg/workflow/role_checks.go - Updated test expectations in
pkg/workflow/role_checks_test.goto reflect alphabetical order for the "all programmatic triggers" test case - Modified
GH_AW_RATE_LIMIT_EVENTSin.github/workflows/ai-moderator.lock.yml(though not correctly sorted)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/workflow/role_checks.go | Alphabetically sorted the programmaticTriggers map keys |
| pkg/workflow/role_checks_test.go | Updated expected array to reflect alphabetical order of all programmatic triggers |
| .github/workflows/ai-moderator.lock.yml | Attempted to sort GH_AW_RATE_LIMIT_EVENTS (but incorrectly) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| GH_AW_RATE_LIMIT_MAX: "5" | ||
| GH_AW_RATE_LIMIT_WINDOW: "60" | ||
| GH_AW_RATE_LIMIT_EVENTS: "workflow_dispatch,issues,issue_comment" | ||
| GH_AW_RATE_LIMIT_EVENTS: "issue_comment,workflow_dispatch,issues" |
There was a problem hiding this comment.
The events in GH_AW_RATE_LIMIT_EVENTS are not in alphabetical order. The current order is "issue_comment,workflow_dispatch,issues" but it should be "issue_comment,issues,workflow_dispatch" to match the alphabetical sorting pattern applied to the programmaticTriggers map and test expectations.
| GH_AW_RATE_LIMIT_EVENTS: "issue_comment,workflow_dispatch,issues" | |
| GH_AW_RATE_LIMIT_EVENTS: "issue_comment,issues,workflow_dispatch" |
| programmaticTriggers := map[string]string{ | ||
| "workflow_dispatch": "workflow_dispatch", | ||
| "repository_dispatch": "repository_dispatch", | ||
| "issues": "issues", | ||
| "discussion": "discussion", | ||
| "discussion_comment": "discussion_comment", | ||
| "issue_comment": "issue_comment", | ||
| "issues": "issues", | ||
| "pull_request": "pull_request", | ||
| "pull_request_review": "pull_request_review", | ||
| "pull_request_review_comment": "pull_request_review_comment", | ||
| "discussion": "discussion", | ||
| "discussion_comment": "discussion_comment", | ||
| "repository_dispatch": "repository_dispatch", | ||
| "workflow_dispatch": "workflow_dispatch", | ||
| } |
There was a problem hiding this comment.
Alphabetizing the programmaticTriggers map in the source code does not make the events slice deterministically ordered. Go map iteration order is non-deterministic - when iterating over the input 'on' map (lines 227-230 in the full function), events will be appended in random order. The test now expects alphabetical order, but the implementation doesn't sort. You need to add sort.Strings(events) before returning the events slice (after line 244 in the full function) and import the "sort" package.
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
The
GH_AW_RATE_LIMIT_EVENTSenvironment variable in generated workflow lock files had non-deterministic ordering due to Go map iteration. This makes diffs noisy and configuration harder to review.Changes
programmaticTriggersmap inpkg/workflow/role_checks.goalphabetically for code readabilityinferEventsFromTriggers()to ensure inferred events are consistently orderedgenerateMembershipCheck()before serializing to lock filesElementsMatchExample
Before:
After:
All workflow lock files now emit rate limit events in alphabetical order regardless of source (explicit config or inferred from triggers).
💡 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.