@hero-design/snowflake-guard 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/index.js +30 -5
- package/package.json +1 -1
package/lib/src/index.js
CHANGED
|
@@ -20,13 +20,18 @@ const getDiffLocs_1 = require("./utils/getDiffLocs");
|
|
|
20
20
|
const WEB_REGEX = /\.tsx$/;
|
|
21
21
|
const MOBILE_REGEX = /\.(tsx|jsx|js)$/;
|
|
22
22
|
const TEST_REGEX = /__tests__/;
|
|
23
|
-
const
|
|
23
|
+
const SNOWFLAKE_COMMENTS_WEB = {
|
|
24
24
|
style: 'Snowflake detected! A component is customized using inline styles. Make sure to not use [prohibited CSS properties](https://docs.google.com/spreadsheets/d/1Dj8vqLdFaf-CSaSVoYqyYZIkGqF6OoyP7K4G1_9L62U/edit?usp=sharing).',
|
|
25
25
|
sx: 'Snowflake detected! A component is customized via sx prop. Make sure to not use [prohibited CSS properties](https://docs.google.com/spreadsheets/d/1Dj8vqLdFaf-CSaSVoYqyYZIkGqF6OoyP7K4G1_9L62U/edit?usp=sharing).',
|
|
26
26
|
'styled-component': 'Please do not use styled-component to customize this component, use sx prop or inline style instead.',
|
|
27
27
|
className: `Please make sure that this className is not used as a CSS classname for component customization purposes, use sx prop or inline style instead. In case this is none-css classname, please flag it with this comment \`${constants_1.APPROVED_CLASSNAME_COMMENT}\`.`,
|
|
28
28
|
};
|
|
29
|
+
const SNOWFLAKE_COMMENTS_MOBILE = {
|
|
30
|
+
style: 'Snowflake detected! A component is customized using inline styles. Make sure to not use [prohibited CSS properties](https://docs.google.com/spreadsheets/d/1Dj8vqLdFaf-CSaSVoYqyYZIkGqF6OoyP7K4G1_9L62U/edit?gid=1761479144#gid=1761479144).',
|
|
31
|
+
'styled-component': 'Please do not use styled-component to customize this component.',
|
|
32
|
+
};
|
|
29
33
|
const MOBILE_REPO_NAMES = JSON.parse(process.env.MOBILE_REPO_NAMES || '[]');
|
|
34
|
+
const APPROVED_USER_LIST = JSON.parse(process.env.APPROVED_USER_LIST || '[]');
|
|
30
35
|
const checkIfDetectedSnowflakesInDiff = (diffLocs, locToComment) => {
|
|
31
36
|
const locIdx = diffLocs.findIndex(([start, end]) => {
|
|
32
37
|
return locToComment >= start && locToComment <= end;
|
|
@@ -76,7 +81,9 @@ module.exports = (app) => {
|
|
|
76
81
|
if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
|
|
77
82
|
snowflakeComments.push({
|
|
78
83
|
path: filePath,
|
|
79
|
-
body:
|
|
84
|
+
body: isMobile
|
|
85
|
+
? SNOWFLAKE_COMMENTS_MOBILE['style']
|
|
86
|
+
: SNOWFLAKE_COMMENTS_WEB['style'],
|
|
80
87
|
line: loc,
|
|
81
88
|
});
|
|
82
89
|
}
|
|
@@ -85,7 +92,9 @@ module.exports = (app) => {
|
|
|
85
92
|
if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
|
|
86
93
|
snowflakeComments.push({
|
|
87
94
|
path: filePath,
|
|
88
|
-
body:
|
|
95
|
+
body: isMobile
|
|
96
|
+
? SNOWFLAKE_COMMENTS_MOBILE['styled-component']
|
|
97
|
+
: SNOWFLAKE_COMMENTS_WEB['styled-component'],
|
|
89
98
|
line: loc,
|
|
90
99
|
});
|
|
91
100
|
}
|
|
@@ -100,7 +109,7 @@ module.exports = (app) => {
|
|
|
100
109
|
if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
|
|
101
110
|
snowflakeComments.push({
|
|
102
111
|
path: filePath,
|
|
103
|
-
body:
|
|
112
|
+
body: SNOWFLAKE_COMMENTS_WEB['sx'],
|
|
104
113
|
line: loc,
|
|
105
114
|
});
|
|
106
115
|
}
|
|
@@ -109,7 +118,7 @@ module.exports = (app) => {
|
|
|
109
118
|
if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
|
|
110
119
|
snowflakeComments.push({
|
|
111
120
|
path: filePath,
|
|
112
|
-
body:
|
|
121
|
+
body: SNOWFLAKE_COMMENTS_WEB['className'],
|
|
113
122
|
line: loc,
|
|
114
123
|
});
|
|
115
124
|
}
|
|
@@ -147,4 +156,20 @@ module.exports = (app) => {
|
|
|
147
156
|
yield context.octokit.checks.create(Object.assign(Object.assign({}, repoInfo), { name: 'SnowflakeGuard/Check', head_sha: context.payload.pull_request.head.sha, status: 'completed', conclusion: 'failure' }));
|
|
148
157
|
return context.octokit.pulls.createReview(Object.assign(Object.assign({}, repoInfo), { pull_number: prNumber, commit_id: context.payload.pull_request.head.sha, event: 'COMMENT', body: 'Snowflake Guard Bot has detected some snowflakes in this PR. Please review the following comments.', comments: snowflakeComments }));
|
|
149
158
|
}));
|
|
159
|
+
app.on('pull_request_review.submitted', (context) => {
|
|
160
|
+
const submittedType = context.payload.review.state;
|
|
161
|
+
const submittedUser = context.payload.review.user.login;
|
|
162
|
+
if (submittedType !== 'approved' ||
|
|
163
|
+
!APPROVED_USER_LIST.includes(submittedUser)) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
return context.octokit.checks.create({
|
|
167
|
+
repo: context.payload.repository.name,
|
|
168
|
+
owner: context.payload.repository.owner.login,
|
|
169
|
+
name: 'SnowflakeGuard/Check',
|
|
170
|
+
head_sha: context.payload.pull_request.head.sha,
|
|
171
|
+
status: 'completed',
|
|
172
|
+
conclusion: 'success',
|
|
173
|
+
});
|
|
174
|
+
});
|
|
150
175
|
};
|