feat: Add environment variable branch support and enhanced pattern ma…#844
Open
jamengual wants to merge 4 commits intogithub:main-enterprisefrom
Open
feat: Add environment variable branch support and enhanced pattern ma…#844jamengual wants to merge 4 commits intogithub:main-enterprisefrom
jamengual wants to merge 4 commits intogithub:main-enterprisefrom
Conversation
…tching - Add support for environment variables in syncInstallation (SAFE_SETTINGS_BRANCH, GITHUB_HEAD_REF, GITHUB_REF_NAME, GITHUB_REF) - Enhance Glob class to support both regex and glob patterns with intelligent detection - Fix backwards compatibility issues for GitHub Actions environment: Handle undefined payload.installation gracefully, Only update check runs/PR comments when in webhook context, Add defensive checks for undefined repo properties, Handle both string and object repository owner formats These changes enable safe-settings to work properly in GitHub Actions while maintaining full backwards compatibility.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for configurable branch references via environment variables, improves glob pattern handling by detecting regex usage and falling back on glob matching, and hardens the Settings class with safer defaults and scoped webhook updates.
- Branch Reference Handling: derive and normalize
reffrom various environment variables, defaulting to main. - Glob Matching: detect regex-like patterns in
Glob.test, try aRegExp, and fallback tominimatchif parsing fails. - Settings Fallbacks: use optional chaining for installation and repo IDs, guard PR comment/check-run code to webhook context.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| index.js | Added logic to compute ref from env vars, normalize it, log, and pass to syncAllSettings |
| lib/glob.js | Added isRegexPattern helper; updated test to try regex then fallback to glob |
| lib/settings.js | Made installation_id and repo fields null-safe, scoped PR comment/check-run updates to webhook payload, and handled mixed owner formats |
Comments suppressed due to low confidence (4)
lib/glob.js:11
- Consider adding unit tests for both regex paths and glob fallback, including invalid regex patterns that trigger the fallback branch.
if (this.isRegexPattern(this.pattern)) {
index.js:239
- Add tests for the branch-detection logic covering scenarios with different environment variable combinations and
refs/prefixes.
let ref = process.env.SAFE_SETTINGS_BRANCH || process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || process.env.GITHUB_REF
index.js:238
- [nitpick] It might help to explicitly log or document which branch is assumed when no
refenv vars are set (e.g., defaulting tomain).
// Use environment variable for branch reference, fallback to undefined (main branch)
lib/settings.js:172
- The variable
payloadis not defined in this scope. Usethis.context.payloador destructureconst { payload } = this.contextbefore referencing it.
if (!payload || !payload.check_run) {
…nhanced pattern matching
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Author
|
@dmosyan do you have time to review this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several updates to improve code robustness, handle edge cases, and enhance functionality. The most significant changes include better handling of branch references, improved regex detection in glob patterns, and enhanced error handling and fallback mechanisms in the
Settingsclass.Branch Reference Handling:
index.js: Added logic to dynamically determine and validate branch references using environment variables, with fallback to the main branch if undefined.Glob Pattern Matching:
lib/glob.js: Introduced regex detection for patterns and fallback to glob matching if regex parsing fails. Added a helper methodisRegexPatternto identify regex-specific characters.Enhanced Error Handling and Fallbacks:
lib/settings.js: UpdatedSettingsclass to handle optional chaining forinstallation_idand repository owner/repo fields, avoiding undefined errors. [1] [2] [3] [4]lib/settings.js: Added checks to ensure PR comment and check run updates are only performed in webhook context.lib/settings.js: Improved logic for creating PR comments by verifying the presence of pull requests in the webhook payload.