Skip to content

Commit 459b695

Browse files
committed
chore: issueBot: add logging and search in title
1 parent 5797b56 commit 459b695

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

scripts/issueBot.mjs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {execSync} from "node:child_process";
1+
import { execSync } from "node:child_process";
22

33
export async function newDeviceSupport(github, _core, context, zhcDir) {
44
const issue = context.payload.issue;
@@ -19,20 +19,23 @@ export async function newDeviceSupport(github, _core, context, zhcDir) {
1919
}
2020
}
2121

22+
const titleAndBody = `${issue.title}\n\n${issue.body ?? ""}`;
23+
2224
// Check if Tuya manufacturer name is already supported.
2325
const tuyaManufacturerNameRe = /['"](_T\w+_(\w+))['"]/g;
24-
const tuyaManufacturerNames = Array.from(issue.body.matchAll(tuyaManufacturerNameRe), (m) => [m[1], m[2]]);
25-
26+
const tuyaManufacturerNames = Array.from(titleAndBody.matchAll(tuyaManufacturerNameRe), (m) => [m[1], m[2]]);
27+
console.log("Found tuyaManufacturerNames", tuyaManufacturerNames);
2628
if (tuyaManufacturerNames.length > 0) {
2729
for (const [fullName, partialName] of tuyaManufacturerNames) {
2830
const fullMatch = (() => {
2931
try {
30-
return execSync(`grep -r --include="*.ts" "${fullName}" "${zhcDir}"`, {encoding: "utf8"});
32+
return execSync(`grep -r --include="*.ts" "${fullName}" "${zhcDir}"`, { encoding: "utf8" });
3133
} catch {
3234
return undefined;
3335
}
3436
})();
3537

38+
console.log(`Checking full match for '${fullName}', result: '${fullMatch}'`);
3639
if (fullMatch) {
3740
await github.rest.issues.createComment({
3841
owner: context.repo.owner,
@@ -57,12 +60,13 @@ If you need help with the process, feel free to ask here and we'll be happy to a
5760

5861
const partialMatch = (() => {
5962
try {
60-
return execSync(`grep -r --include="*.ts" "${partialName}" "${zhcDir}"`, {encoding: "utf8"});
63+
return execSync(`grep -r --include="*.ts" "${partialName}" "${zhcDir}"`, { encoding: "utf8" });
6164
} catch {
6265
return undefined;
6366
}
6467
})();
6568

69+
console.log(`Checking partial match for '${partialName}', result: '${partialMatch}'`);
6670
if (partialMatch) {
6771
const candidates = Array.from(partialMatch.matchAll(tuyaManufacturerNameRe), (m) => m[1]);
6872

@@ -85,13 +89,13 @@ Let us know if it works so we can support this device out-of-the-box!`,
8589
} else {
8690
// Check if zigbee model is already supported.
8791
const zigbeeModelRe = /zigbeeModel: \[['"](.+)['"]\]/g;
88-
const zigbeeModels = Array.from(issue.body.matchAll(zigbeeModelRe), (m) => m[1]);
92+
const zigbeeModels = Array.from(titleAndBody.matchAll(zigbeeModelRe), (m) => m[1]);
8993

9094
if (zigbeeModels.length > 0) {
9195
for (const zigbeeModel of zigbeeModels) {
9296
const fullMatch = (() => {
9397
try {
94-
return execSync(`grep -r --include="*.ts" '"${zigbeeModel}"' "${zhcDir}"`, {encoding: "utf8"});
98+
return execSync(`grep -r --include="*.ts" '"${zigbeeModel}"' "${zhcDir}"`, { encoding: "utf8" });
9599
} catch {
96100
return undefined;
97101
}
@@ -134,11 +138,10 @@ In case all features work, please submit a pull request on this repository so th
134138
For instructions on how to create a pull request see the [docs](https://www.zigbee2mqtt.io/advanced/support-new-devices/01_support_new_devices.html#_4-create-a-pull-request).
135139
136140
If **NOT** all features work, please follow the [How To Support new devices](https://www.zigbee2mqtt.io/advanced/support-new-devices/01_support_new_devices.html).
137-
${
138-
tuyaManufacturerNames.length > 0
139-
? "Since this is a Tuya also consider [How To Support new Tuya devices](https://www.zigbee2mqtt.io/advanced/support-new-devices/02_support_new_tuya_devices.html)."
140-
: ""
141-
}
141+
${tuyaManufacturerNames.length > 0
142+
? "Since this is a Tuya also consider [How To Support new Tuya devices](https://www.zigbee2mqtt.io/advanced/support-new-devices/02_support_new_tuya_devices.html)."
143+
: ""
144+
}
142145
143146
If you need help with the process, feel free to ask here and we'll be happy to assist.`,
144147
});

0 commit comments

Comments
 (0)