-
-
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 8 commits
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
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,79 @@ | ||
| /// Unified configuration for PR flavors (based on real Sentry usage analysis) | ||
| 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" | ||
| }, | ||
| { | ||
| // Internal changes - no changelog needed | ||
| changelog: undefined, | ||
| labels: [ | ||
| "docs", | ||
| "doc", | ||
| "style", | ||
| "ref", | ||
| "refactor", | ||
| "tests", | ||
| "test", | ||
| "build", | ||
| "ci", | ||
| "chore", | ||
| "meta", | ||
| "deps", | ||
| "dep" | ||
| ] | ||
| } | ||
| ]; | ||
|
|
||
| /// 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
|
||
|
|
||
| // Strip scope/context from conventional commit format: "type(scope)" -> "type" | ||
| const baseType = normalizedFlavor.replace(/\([^)]*\)/, ''); | ||
vaind marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const config = FLAVOR_CONFIG.find(config => | ||
| config.labels.includes(normalizedFlavor) || config.labels.includes(baseType) | ||
| ); | ||
|
|
||
| return config || { | ||
| changelog: "Features" // Default to Features | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| /// 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, | ||
| extractPRFlavor | ||
| }; | ||
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,184 @@ | ||
| const { describe, it } = require('node:test'); | ||
| const assert = require('node:assert'); | ||
| const { getFlavorConfig, extractPRFlavor, FLAVOR_CONFIG } = require('./dangerfile-utils.js'); | ||
|
|
||
| describe('dangerfile-utils', () => { | ||
| describe('getFlavorConfig', () => { | ||
| it('should return config for features with isFeature true', () => { | ||
| const featConfig = getFlavorConfig('feat'); | ||
| assert.strictEqual(featConfig.changelog, 'Features'); | ||
| assert.strictEqual(featConfig.isFeature, true); | ||
|
|
||
| const featureConfig = getFlavorConfig('feature'); | ||
| assert.strictEqual(featureConfig.changelog, 'Features'); | ||
| assert.strictEqual(featureConfig.isFeature, true); | ||
| }); | ||
|
|
||
| it('should return config for fixes without isFeature', () => { | ||
| const fixConfig = getFlavorConfig('fix'); | ||
| assert.strictEqual(fixConfig.changelog, 'Fixes'); | ||
| assert.strictEqual(fixConfig.isFeature, undefined); | ||
|
|
||
| const bugConfig = getFlavorConfig('bug'); | ||
| assert.strictEqual(bugConfig.changelog, 'Fixes'); | ||
| assert.strictEqual(bugConfig.isFeature, undefined); | ||
|
|
||
| const bugfixConfig = getFlavorConfig('bugfix'); | ||
| assert.strictEqual(bugfixConfig.changelog, 'Fixes'); | ||
| assert.strictEqual(bugfixConfig.isFeature, undefined); | ||
| }); | ||
|
|
||
| it('should return config with undefined changelog for skipped flavors', () => { | ||
| const skipFlavors = ['docs', 'doc', 'ci', 'tests', 'test', 'style', 'refactor', 'build', 'chore', 'meta', 'deps', 'dep', 'chore(deps)', 'build(deps)']; | ||
|
|
||
| skipFlavors.forEach(flavor => { | ||
| const config = getFlavorConfig(flavor); | ||
| assert.strictEqual(config.changelog, undefined, `${flavor} should have undefined changelog`); | ||
| assert.strictEqual(config.isFeature, undefined, `${flavor} should have undefined isFeature`); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return default config for unknown flavors', () => { | ||
| const unknownConfig = getFlavorConfig('unknown'); | ||
| assert.strictEqual(unknownConfig.changelog, 'Features'); | ||
| assert.strictEqual(unknownConfig.isFeature, undefined); | ||
|
|
||
| const emptyConfig = getFlavorConfig(''); | ||
| assert.strictEqual(emptyConfig.changelog, 'Features'); | ||
| assert.strictEqual(emptyConfig.isFeature, undefined); | ||
| }); | ||
|
|
||
| it('should be case-insensitive and handle whitespace', () => { | ||
| const config1 = getFlavorConfig('FEAT'); | ||
| assert.strictEqual(config1.changelog, 'Features'); | ||
|
|
||
| const config2 = getFlavorConfig(' fix '); | ||
| assert.strictEqual(config2.changelog, 'Fixes'); | ||
| }); | ||
|
|
||
| it('should handle all security-related flavors', () => { | ||
| const secConfig = getFlavorConfig('sec'); | ||
| assert.strictEqual(secConfig.changelog, 'Security'); | ||
|
|
||
| const securityConfig = getFlavorConfig('security'); | ||
| assert.strictEqual(securityConfig.changelog, 'Security'); | ||
| }); | ||
|
|
||
| it('should handle all performance-related flavors', () => { | ||
| const perfConfig = getFlavorConfig('perf'); | ||
| assert.strictEqual(perfConfig.changelog, 'Performance'); | ||
|
|
||
| const performanceConfig = getFlavorConfig('performance'); | ||
| assert.strictEqual(performanceConfig.changelog, 'Performance'); | ||
| }); | ||
|
|
||
| it('should handle ref flavor (internal changes - no changelog)', () => { | ||
| const refConfig = getFlavorConfig('ref'); | ||
| assert.strictEqual(refConfig.changelog, undefined); | ||
| assert.strictEqual(refConfig.isFeature, undefined); | ||
| }); | ||
|
|
||
| it('should handle scoped flavors by stripping scope', () => { | ||
| const scopedFeat = getFlavorConfig('feat(core)'); | ||
| assert.strictEqual(scopedFeat.changelog, 'Features'); | ||
| assert.strictEqual(scopedFeat.isFeature, true); | ||
|
|
||
| const scopedFix = getFlavorConfig('fix(browser)'); | ||
| assert.strictEqual(scopedFix.changelog, 'Fixes'); | ||
| assert.strictEqual(scopedFix.isFeature, undefined); | ||
|
|
||
| const scopedChore = getFlavorConfig('chore(deps)'); | ||
| assert.strictEqual(scopedChore.changelog, undefined); | ||
| }); | ||
| }); | ||
|
|
||
| describe('extractPRFlavor', () => { | ||
| it('should extract flavor from PR title with colon', () => { | ||
| const flavor = extractPRFlavor('feat: add new feature', null); | ||
| assert.strictEqual(flavor, 'feat'); | ||
|
|
||
| const flavor2 = extractPRFlavor('Fix: resolve bug in authentication', null); | ||
| assert.strictEqual(flavor2, 'fix'); | ||
|
|
||
| const flavor3 = extractPRFlavor('Docs: Update readme', null); | ||
| assert.strictEqual(flavor3, 'docs'); | ||
| }); | ||
|
|
||
| it('should extract flavor from branch name with slash', () => { | ||
| const flavor = extractPRFlavor(null, 'feature/new-api'); | ||
| assert.strictEqual(flavor, 'feature'); | ||
|
|
||
| const flavor2 = extractPRFlavor(null, 'ci/update-workflows'); | ||
| assert.strictEqual(flavor2, 'ci'); | ||
|
|
||
| const flavor3 = extractPRFlavor(null, 'fix/auth-bug'); | ||
| assert.strictEqual(flavor3, 'fix'); | ||
| }); | ||
|
|
||
| it('should prefer title over branch if both available', () => { | ||
| const flavor = extractPRFlavor('feat: add feature', 'ci/update-workflows'); | ||
| assert.strictEqual(flavor, 'feat'); | ||
| }); | ||
|
|
||
| it('should return empty string if no flavor found', () => { | ||
| const flavor1 = extractPRFlavor('Simple title', null); | ||
| assert.strictEqual(flavor1, ''); | ||
|
|
||
| const flavor2 = extractPRFlavor(null, 'simple-branch'); | ||
| assert.strictEqual(flavor2, ''); | ||
|
|
||
| const flavor3 = extractPRFlavor(null, null); | ||
| assert.strictEqual(flavor3, ''); | ||
| }); | ||
|
|
||
| it('should handle edge cases', () => { | ||
| const flavor1 = extractPRFlavor(':', null); | ||
| assert.strictEqual(flavor1, ''); | ||
|
|
||
| const flavor2 = extractPRFlavor(null, '/'); | ||
| assert.strictEqual(flavor2, ''); | ||
|
|
||
| const flavor3 = extractPRFlavor('title: with: multiple: colons', null); | ||
| assert.strictEqual(flavor3, 'title'); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| describe('FLAVOR_CONFIG integrity', () => { | ||
| it('should have unique labels across all configs', () => { | ||
| const allLabels = []; | ||
| FLAVOR_CONFIG.forEach(config => { | ||
| config.labels.forEach(label => { | ||
| assert.ok(!allLabels.includes(label), `Duplicate label found: ${label}`); | ||
| allLabels.push(label); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it('should have proper structure for all configs', () => { | ||
| FLAVOR_CONFIG.forEach((config, index) => { | ||
| assert.ok(Array.isArray(config.labels), `Config ${index} should have labels array`); | ||
| assert.ok(config.labels.length > 0, `Config ${index} should have at least one label`); | ||
| assert.ok(config.hasOwnProperty('changelog'), `Config ${index} should have changelog property`); | ||
|
|
||
| // changelog should be either a string or undefined | ||
| if (config.changelog !== undefined) { | ||
| assert.strictEqual(typeof config.changelog, 'string', `Config ${index} changelog should be string or undefined`); | ||
| } | ||
|
|
||
| // isFeature should be true or undefined (not false) | ||
| if (config.hasOwnProperty('isFeature')) { | ||
| assert.strictEqual(config.isFeature, true, `Config ${index} isFeature should be true or undefined`); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it('should have only Features configs with isFeature true', () => { | ||
| FLAVOR_CONFIG.forEach(config => { | ||
| if (config.isFeature === true) { | ||
| assert.strictEqual(config.changelog, 'Features', 'Only Features configs should have isFeature true'); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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
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.