Skip to content

Commit 0618aca

Browse files
authored
chore: merge master to dev
2 parents 56aab4e + cfc7ab8 commit 0618aca

1 file changed

Lines changed: 13 additions & 23 deletions

File tree

scripts/issueBot.mjs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import {execSync} from "node:child_process";
1+
import {execFileSync} from "node:child_process";
2+
3+
function grepTypeScriptFiles(needle, dir) {
4+
try {
5+
return execFileSync("grep", ["-r", "-F", "--include=*.ts", "--", needle, dir], {encoding: "utf8"});
6+
} catch {
7+
return undefined;
8+
}
9+
}
210

311
async function checkDuplicateIssue(github, context, name) {
412
// Search for existing issues with the same `name`
@@ -63,13 +71,7 @@ export async function newDeviceSupport(github, _core, context, zhcDir) {
6371
if (tuyaManufacturerNames.length > 0) {
6472
for (const [fullName, partialName] of tuyaManufacturerNames) {
6573
if (await checkDuplicateIssue(github, context, fullName)) return;
66-
const fullMatch = (() => {
67-
try {
68-
return execSync(`grep -r --include="*.ts" "${fullName}" "${zhcDir}"`, {encoding: "utf8"});
69-
} catch {
70-
return undefined;
71-
}
72-
})();
74+
const fullMatch = grepTypeScriptFiles(fullName, zhcDir);
7375

7476
console.log(`Checking full match for '${fullName}', result: '${fullMatch}'`);
7577
if (fullMatch) {
@@ -94,13 +96,7 @@ If you need help with the process, feel free to ask here and we'll be happy to a
9496
return;
9597
}
9698

97-
const partialMatch = (() => {
98-
try {
99-
return execSync(`grep -r --include="*.ts" "${partialName}" "${zhcDir}"`, {encoding: "utf8"});
100-
} catch {
101-
return undefined;
102-
}
103-
})();
99+
const partialMatch = grepTypeScriptFiles(partialName, zhcDir);
104100

105101
console.log(`Checking partial match for '${partialName}', result: '${partialMatch}'`);
106102
if (partialMatch) {
@@ -129,14 +125,8 @@ Let us know if it works so we can support this device out-of-the-box!`,
129125

130126
if (zigbeeModels.length > 0) {
131127
for (const zigbeeModel of zigbeeModels) {
132-
if (await checkDuplicateIssue(github, context, fullName)) return;
133-
const fullMatch = (() => {
134-
try {
135-
return execSync(`grep -r --include="*.ts" '"${zigbeeModel}"' "${zhcDir}"`, {encoding: "utf8"});
136-
} catch {
137-
return undefined;
138-
}
139-
})();
128+
if (await checkDuplicateIssue(github, context, zigbeeModel)) return;
129+
const fullMatch = grepTypeScriptFiles(`"${zigbeeModel}"`, zhcDir);
140130

141131
if (fullMatch) {
142132
await github.rest.issues.createComment({

0 commit comments

Comments
 (0)