-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdangerfile-utils.js
More file actions
93 lines (84 loc) · 2.22 KB
/
dangerfile-utils.js
File metadata and controls
93 lines (84 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/// Unified configuration for PR flavors (based on real Sentry usage analysis)
const FLAVOR_CONFIG = [
{
labels: ["feat", "feature", "add", "implement"],
changelog: "Features",
isFeature: true
},
{
labels: ["fix", "bug", "bugfix", "resolve", "correct"],
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",
"update",
"bump",
"cleanup",
"format"
]
}
];
/// Get flavor configuration for a given PR flavor
function getFlavorConfig(prFlavor) {
const normalizedFlavor = prFlavor.toLowerCase().trim();
// Strip scope/context from conventional commit format: "type(scope)" -> "type"
const parenIndex = normalizedFlavor.indexOf('(');
const baseType = parenIndex !== -1 ? normalizedFlavor.substring(0, parenIndex) : normalizedFlavor;
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) {
// Validate input parameters to prevent runtime errors
if (prTitle && typeof prTitle === 'string') {
// First try conventional commit format: "type(scope): description"
const colonParts = prTitle.split(":");
if (colonParts.length > 1) {
return colonParts[0].toLowerCase().trim();
}
// Fallback: try first word for non-conventional titles like "fix memory leak"
const firstWord = prTitle.trim().split(/\s+/)[0];
if (firstWord) {
return firstWord.toLowerCase();
}
}
if (prBranchRef && typeof prBranchRef === 'string') {
const parts = prBranchRef.split("/");
if (parts.length > 1) {
return parts[0].toLowerCase();
}
}
return "";
}
module.exports = {
FLAVOR_CONFIG,
getFlavorConfig,
extractPRFlavor
};