Skip to content

Commit 672dd4d

Browse files
vaindclaudegithub-advanced-security[bot]
authored
feat: improve Danger testing and flavor recognition (#105)
* feat: enhance Danger with inline changelog suggestions - Implement inline changelog suggestions instead of generic instructions - Add unified flavor configuration with grouped labels - Extract testable functions into dangerfile-utils.js module - Add comprehensive test suite with 21 test cases - Integrate JavaScript testing into CI workflow 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Potential fix for code scanning alert no. 22: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix: download dangerfile-utils.js in danger workflow The dangerfile now requires the utils module, so both files need to be downloaded. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: consolidate skip-changelog flavors into single config Merge all internal change flavors (docs, style, refactor, test, build, ci, chore, deps) into one configuration entry since they all have the same behavior (skip changelog). This reduces the config from 7 separate entries to 1, making it more maintainable. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: simplify dangerfile to focus on testing and flavor improvements Remove inline suggestions functionality to focus this PR on: - Improved flavor recognition and configuration - Testing infrastructure additions - Consolidating skip-changelog flavors The inline suggestions feature will be implemented in a separate PR. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: update flavor config based on real Sentry usage analysis Based on analysis of 60 recent PRs from top Sentry repositories: **Key findings:** - 'ref' is very common (14 occurrences) but missing from our config - 'tests' is used (5 occurrences) and should skip changelog - 'meta' is used for repository maintenance - 'Bug Fixes' is more standard than 'Fixes' for changelog sections **Changes made:** - Add 'ref' flavor mapping to 'Changes' section - Add 'meta' and 'tests' to skip-changelog group - Change 'Fixes' to 'Bug Fixes' (aligns with sentry-javascript) - Update tests and documentation This makes our configuration reflect actual usage patterns in Sentry repositories. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: improve Danger testing and conventional commit scope handling - Add comprehensive testing infrastructure with 23 test cases - Fix scope handling for conventional commits (feat(core): -> feat) - Properly classify ref commits as internal changes - Add modular architecture with testable functions - Include CI integration for JavaScript testing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: remove unused findChangelogInsertionPoint function and its tests * refactor: remove unrelated function and add input validation - Remove findChangelogInsertionPoint function (unrelated to flavor recognition) - Add type validation to extractPRFlavor to prevent runtime errors - Add comprehensive tests for input validation - Reduce test count from 23 to 18 focused tests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * security: replace ReDoS-vulnerable regex with safe string parsing - Replace regex `/\([^)]*\)/` with indexOf/substring approach - Prevents potential ReDoS attacks with nested parentheses - Improves performance and readability - Add comprehensive edge case tests for malformed scope inputs 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: enhance flavor configuration and add tests for non-conventional PR titles --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 06ba389 commit 672dd4d

File tree

6 files changed

+414
-22
lines changed

6 files changed

+414
-22
lines changed

.github/workflows/danger.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ jobs:
2222
with:
2323
fetch-depth: 0
2424

25-
- name: Download dangerfile.js
26-
run: wget https://raw.githubusercontent.com/getsentry/github-workflows/${{ inputs._workflow_version }}/danger/dangerfile.js -P ${{ runner.temp }}
25+
- name: Download dangerfile.js and utilities
26+
run: |
27+
wget https://raw.githubusercontent.com/getsentry/github-workflows/${{ inputs._workflow_version }}/danger/dangerfile.js -P ${{ runner.temp }}
28+
wget https://raw.githubusercontent.com/getsentry/github-workflows/${{ inputs._workflow_version }}/danger/dangerfile-utils.js -P ${{ runner.temp }}
2729
2830
# Using a pre-built docker image in GitHub container registry instaed of NPM to reduce possible attack vectors.
2931
- name: Run DangerJS

.github/workflows/script-tests.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This isn't a reusable workflow but a CI action for this repo itself - testing the contained workflows & scripts.
22
name: Script Tests
3+
permissions:
4+
contents: read
35

46
on:
57
push:
@@ -23,3 +25,21 @@ jobs:
2325
- run: Invoke-Pester
2426
working-directory: updater
2527
shell: pwsh
28+
29+
danger:
30+
name: Danger JS Tests
31+
runs-on: ubuntu-latest
32+
defaults:
33+
run:
34+
working-directory: danger
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- uses: actions/setup-node@v4
39+
with:
40+
node-version: '18'
41+
42+
- run: node --test
43+
44+
- name: Check syntax
45+
run: node -c dangerfile.js

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Danger - Improve conventional commit scope handling, and non-conventional PR title support ([#105](https://github.com/getsentry/github-workflows/pull/105))
78
- Add Proguard artifact endpoint for Android builds in sentry-server ([#100](https://github.com/getsentry/github-workflows/pull/100))
89

910
### Security

danger/dangerfile-utils.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/// Unified configuration for PR flavors (based on real Sentry usage analysis)
2+
const FLAVOR_CONFIG = [
3+
{
4+
labels: ["feat", "feature", "add", "implement"],
5+
changelog: "Features",
6+
isFeature: true
7+
},
8+
{
9+
labels: ["fix", "bug", "bugfix", "resolve", "correct"],
10+
changelog: "Fixes"
11+
},
12+
{
13+
labels: ["sec", "security"],
14+
changelog: "Security"
15+
},
16+
{
17+
labels: ["perf", "performance"],
18+
changelog: "Performance"
19+
},
20+
{
21+
// Internal changes - no changelog needed
22+
changelog: undefined,
23+
labels: [
24+
"docs",
25+
"doc",
26+
"style",
27+
"ref",
28+
"refactor",
29+
"tests",
30+
"test",
31+
"build",
32+
"ci",
33+
"chore",
34+
"meta",
35+
"deps",
36+
"dep",
37+
"update",
38+
"bump",
39+
"cleanup",
40+
"format"
41+
]
42+
}
43+
];
44+
45+
/// Get flavor configuration for a given PR flavor
46+
function getFlavorConfig(prFlavor) {
47+
const normalizedFlavor = prFlavor.toLowerCase().trim();
48+
49+
// Strip scope/context from conventional commit format: "type(scope)" -> "type"
50+
const parenIndex = normalizedFlavor.indexOf('(');
51+
const baseType = parenIndex !== -1 ? normalizedFlavor.substring(0, parenIndex) : normalizedFlavor;
52+
53+
const config = FLAVOR_CONFIG.find(config =>
54+
config.labels.includes(normalizedFlavor) || config.labels.includes(baseType)
55+
);
56+
57+
return config || {
58+
changelog: "Features" // Default to Features
59+
};
60+
}
61+
62+
63+
/// Extract PR flavor from title or branch name
64+
function extractPRFlavor(prTitle, prBranchRef) {
65+
// Validate input parameters to prevent runtime errors
66+
if (prTitle && typeof prTitle === 'string') {
67+
// First try conventional commit format: "type(scope): description"
68+
const colonParts = prTitle.split(":");
69+
if (colonParts.length > 1) {
70+
return colonParts[0].toLowerCase().trim();
71+
}
72+
73+
// Fallback: try first word for non-conventional titles like "fix memory leak"
74+
const firstWord = prTitle.trim().split(/\s+/)[0];
75+
if (firstWord) {
76+
return firstWord.toLowerCase();
77+
}
78+
}
79+
80+
if (prBranchRef && typeof prBranchRef === 'string') {
81+
const parts = prBranchRef.split("/");
82+
if (parts.length > 1) {
83+
return parts[0].toLowerCase();
84+
}
85+
}
86+
return "";
87+
}
88+
89+
module.exports = {
90+
FLAVOR_CONFIG,
91+
getFlavorConfig,
92+
extractPRFlavor
93+
};

0 commit comments

Comments
 (0)