-
-
Notifications
You must be signed in to change notification settings - Fork 8
feat: improve Danger testing and flavor recognition #105
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a845daf
feat: enhance Danger with inline changelog suggestions
vaind c5efc86
Potential fix for code scanning alert no. 22: Workflow does not conta…
vaind 30f76ee
fix: download dangerfile-utils.js in danger workflow
vaind 0b46341
refactor: consolidate skip-changelog flavors into single config
vaind c9b647c
refactor: simplify dangerfile to focus on testing and flavor improvem…
vaind 115b0fb
feat: update flavor config based on real Sentry usage analysis
vaind 87b4e12
feat: improve Danger testing and conventional commit scope handling
vaind dbd642e
refactor: remove unused findChangelogInsertionPoint function and its …
vaind a5c9a66
refactor: remove unrelated function and add input validation
vaind 0a63fca
security: replace ReDoS-vulnerable regex with safe string parsing
vaind 4db5d95
feat: enhance flavor configuration and add tests for non-conventional…
vaind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| /// Unified configuration for PR flavors | ||
| const FLAVOR_CONFIG = [ | ||
| { | ||
| labels: ["feat", "feature"], | ||
| changelog: "Features", | ||
| isFeature: true | ||
| }, | ||
| { | ||
| labels: ["fix", "bug", "bugfix"], | ||
| changelog: "Fixes" | ||
| }, | ||
| { | ||
| labels: ["sec", "security"], | ||
| changelog: "Security" | ||
| }, | ||
| { | ||
| labels: ["perf", "performance"], | ||
| changelog: "Performance" | ||
| }, | ||
| { | ||
| labels: ["docs", "doc"], | ||
| changelog: undefined // Internal documentation changes | ||
| }, | ||
| { | ||
| labels: ["style", "refactor"], | ||
| changelog: undefined // Internal code improvements - no changelog needed | ||
| }, | ||
| { | ||
| labels: ["test"], | ||
| changelog: undefined // Test updates don't need changelog | ||
| }, | ||
| { | ||
| labels: ["build"], | ||
| changelog: undefined // Build system changes | ||
| }, | ||
| { | ||
| labels: ["ci"], | ||
| changelog: undefined // CI changes don't need changelog | ||
| }, | ||
| { | ||
| labels: ["chore"], | ||
| changelog: undefined // General maintenance | ||
| }, | ||
| { | ||
| labels: ["deps", "dep", "chore(deps)", "build(deps)"], | ||
| changelog: undefined // Dependency updates | ||
| } | ||
| ]; | ||
|
|
||
| /// Get flavor configuration for a given PR flavor | ||
| function getFlavorConfig(prFlavor) { | ||
| const normalizedFlavor = prFlavor.toLowerCase().trim(); | ||
vaind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const config = FLAVOR_CONFIG.find(config => | ||
| config.labels.includes(normalizedFlavor) | ||
| ); | ||
|
|
||
| return config || { | ||
| changelog: "Features" // Default to Features | ||
| }; | ||
| } | ||
|
|
||
| /// Find the appropriate line to insert a changelog entry | ||
| function findChangelogInsertionPoint(lines, sectionName) { | ||
| let unreleasedIndex = -1; | ||
| let sectionIndex = -1; | ||
| let insertionLine = -1; | ||
| let isNewSection = false; | ||
|
|
||
| // Find the "## Unreleased" section | ||
| for (let i = 0; i < lines.length; i++) { | ||
| if (lines[i].match(/^##\s+Unreleased/i)) { | ||
| unreleasedIndex = i; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (unreleasedIndex === -1) { | ||
| // No "Unreleased" section found | ||
| return { success: false }; | ||
| } | ||
|
|
||
| // Look for the target section under "Unreleased" | ||
| for (let i = unreleasedIndex + 1; i < lines.length; i++) { | ||
| // Stop if we hit another ## section (next release) | ||
| if (lines[i].match(/^##\s+/)) { | ||
| break; | ||
| } | ||
|
|
||
| // Check if this is our target section | ||
| if (lines[i].match(new RegExp(`^###\\s+${sectionName}`, 'i'))) { | ||
| sectionIndex = i; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (sectionIndex !== -1) { | ||
| // Found the section, find where to insert within it | ||
| for (let i = sectionIndex + 1; i < lines.length; i++) { | ||
| // Stop if we hit another section or end | ||
| if (lines[i].match(/^##[#]?\s+/)) { | ||
| break; | ||
| } | ||
|
|
||
| // Find the first non-empty line after the section header | ||
| if (lines[i].trim() !== '') { | ||
| // Insert before this line if it's not already a bullet point | ||
| insertionLine = lines[i].match(/^-\s+/) ? i + 1 : i; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // If we didn't find a good spot, insert right after the section header | ||
| if (insertionLine === -1) { | ||
| insertionLine = sectionIndex + 2; // +1 for the section, +1 for empty line | ||
| } | ||
| } else { | ||
| // Section doesn't exist, we need to create it | ||
| isNewSection = true; | ||
|
|
||
| // Find where to insert the new section | ||
| // Look for the next section after Unreleased or find a good spot | ||
| for (let i = unreleasedIndex + 1; i < lines.length; i++) { | ||
| if (lines[i].match(/^##\s+/)) { | ||
| // Insert before the next release section | ||
| insertionLine = i - 1; | ||
| break; | ||
| } else if (lines[i].match(/^###\s+/)) { | ||
| // Insert before the first existing section | ||
| insertionLine = i; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // If no good spot found, insert after a reasonable gap from Unreleased | ||
| if (insertionLine === -1) { | ||
| insertionLine = unreleasedIndex + 2; | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| success: true, | ||
| lineNumber: insertionLine + 1, // Convert to 1-based line numbering | ||
| isNewSection: isNewSection, | ||
| sectionHeader: isNewSection ? `### ${sectionName}` : null | ||
| }; | ||
| } | ||
|
|
||
| /// Extract PR flavor from title or branch name | ||
| function extractPRFlavor(prTitle, prBranchRef) { | ||
| if (prTitle) { | ||
vaind marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const parts = prTitle.split(":"); | ||
| if (parts.length > 1) { | ||
| return parts[0].toLowerCase().trim(); | ||
| } | ||
| } | ||
| if (prBranchRef) { | ||
| const parts = prBranchRef.split("/"); | ||
| if (parts.length > 1) { | ||
| return parts[0].toLowerCase(); | ||
| } | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| module.exports = { | ||
| FLAVOR_CONFIG, | ||
| getFlavorConfig, | ||
| findChangelogInsertionPoint, | ||
| extractPRFlavor | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.