@sapphire-sh/utils 3.6.0 → 3.7.0

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.
@@ -20,6 +20,7 @@ const workflowsDir = join('.github', 'workflows');
20
20
  const workflowValuesPath = join('.github', 'sapphire-workflows.json');
21
21
  const withLinePattern = /^\s*with:\s*$/m;
22
22
  const pathsIgnoreLinePattern = /^\s*paths-ignore:\s*$/m;
23
+ const reviewersOnlyBlockPattern = /^\n {6}reviewers: .*\n$/;
23
24
  const pushBlockPattern = /^on:\n(?:[ \t].*\n|\n)*? {2}push:\n((?: {4}.*\n|\n)*)/m;
24
25
  const branchesListPattern = /^ {2}push:\n {4}branches:\n(?: {6}- .*\n)*/m;
25
26
  const entryKeys = new Set(['push', 'with']);
@@ -64,7 +65,7 @@ const readWorkflowValues = () => {
64
65
 
65
66
  const codeOwnersPath = join('.github', 'CODEOWNERS');
66
67
 
67
- const readCodeOwnerAssignees = () => {
68
+ const readCodeOwnerUsers = () => {
68
69
  const filepath = join(cwd, codeOwnersPath);
69
70
 
70
71
  if (existsSync(filepath) === false) {
@@ -125,8 +126,17 @@ const writeWorkflow = (outputName, template) => {
125
126
  let content = template;
126
127
 
127
128
  if (values === undefined) {
128
- if (existsSync(filepath) && withLinePattern.test(readFileSync(filepath, 'utf-8'))) {
129
- console.log(`warning: ${outputName} had with: values that are not in ${workflowValuesPath}`);
129
+ if (existsSync(filepath)) {
130
+ const existing = readFileSync(filepath, 'utf-8');
131
+ const withLine = withLinePattern.exec(existing);
132
+
133
+ if (
134
+ withLine !== null &&
135
+ (basename(outputName, '.yml') !== 'dependabot-review-request' ||
136
+ reviewersOnlyBlockPattern.test(existing.slice(withLine.index + withLine[0].length)) === false)
137
+ ) {
138
+ console.log(`warning: ${outputName} had with: values that are not in ${workflowValuesPath}`);
139
+ }
130
140
  }
131
141
  } else {
132
142
  const { push = {}, with: withValues } = values;
@@ -147,6 +157,18 @@ const writeWorkflow = (outputName, template) => {
147
157
  }
148
158
  }
149
159
 
160
+ if (basename(outputName, '.yml') === 'dependabot-review-request') {
161
+ const reviewers = readCodeOwnerUsers();
162
+
163
+ if (reviewers.length > 0) {
164
+ if (withLinePattern.test(content) === false) {
165
+ content += ' with:\n';
166
+ }
167
+
168
+ content += ` reviewers: ${formatYamlValue(reviewers.join(' '))}\n`;
169
+ }
170
+ }
171
+
150
172
  if (
151
173
  (values?.push === undefined || Object.hasOwn(values.push, 'paths-ignore') === false) &&
152
174
  existsSync(filepath) &&
@@ -200,7 +222,7 @@ const writeDependabotConfig = (outputName, template) => {
200
222
  );
201
223
  }
202
224
 
203
- const assignees = readCodeOwnerAssignees();
225
+ const assignees = readCodeOwnerUsers();
204
226
 
205
227
  if (assignees.length > 0) {
206
228
  const assigneeLines = assignees.map((assignee) => ` - ${formatYamlValue(assignee)}\n`).join('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire-sh/utils",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "@sapphire-sh/utils",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -0,0 +1,12 @@
1
+ name: dependabot-review-request
2
+
3
+ on:
4
+ pull_request:
5
+ types:
6
+ - opened
7
+
8
+ jobs:
9
+ request:
10
+ uses: sapphire-sh/github-actions/.github/workflows/dependabot-review-request-template.yml@main
11
+ permissions:
12
+ pull-requests: write