Skip to content

Commit ab51215

Browse files
committed
Added ability to patch all template repos and push the changes
1 parent 86475d4 commit ab51215

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

.changeset/eleven-gorillas-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/sdk": patch
3+
---
4+
5+
Fixed an error message

packages/trigger-sdk/src/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export class HostConnection implements IConnection {
223223
new Date().getTime() - this.#closeUnresponsiveConnectionTimeoutMs
224224
) {
225225
this.#logger.error(
226-
"No pong received in last three minutes, closing connection to Interval and retrying..."
226+
"No pong received in last three minutes, closing connection to Trigger.dev and retrying..."
227227
);
228228
if (this.#pingIntervalHandle) {
229229
clearInterval(this.#pingIntervalHandle);

scripts/patchTemplates.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const { exec } = require("child_process");
2+
const fs = require("fs");
3+
const path = require("path");
4+
const fetch = require("node-fetch");
5+
6+
const templatesDir = process.argv[2];
7+
if (!templatesDir) {
8+
console.error("Please provide a path to the templates directory");
9+
process.exit(1);
10+
}
11+
12+
// patch is a path to a patch file
13+
async function patchTemplate(templateName, patch, message) {
14+
const templateDir = path.join(templatesDir, templateName);
15+
16+
if (fs.statSync(templateDir).isDirectory()) {
17+
console.log(`Patching template '${templateName}'`);
18+
// Make sure we're on the main branch and there are no uncommitted changes
19+
await execAsync(`cd ${templateDir} && git checkout main`);
20+
21+
// Make sure there are no uncommitted changes
22+
const preStatus = await execAsync(`cd ${templateDir} && git status`);
23+
24+
if (!preStatus.includes("nothing to commit")) {
25+
console.error(
26+
`There are uncommitted changes in template '${templateName}'`
27+
);
28+
return;
29+
}
30+
31+
// Make sure we're up to date with the remote
32+
await execAsync(`cd ${templateDir} && git pull origin main`);
33+
34+
// Apply the patch to the template repo
35+
await execAsync(`cd ${templateDir} && git apply ${patch}`);
36+
37+
// Check if there are any changes
38+
const status = await execAsync(`cd ${templateDir} && git status`);
39+
40+
if (!status.includes("modified:")) {
41+
console.log(`No changes for template '${templateName}'`);
42+
return;
43+
}
44+
45+
console.log(`Changes for template '${templateName}':`, status);
46+
47+
// Create a commit
48+
await execAsync(
49+
`cd ${templateDir} && git add -A && git commit -m "[triggerbot] ${message}"`
50+
);
51+
52+
// Push to remote
53+
await execAsync(`cd ${templateDir} && git push origin main`);
54+
55+
console.log(`Applied patch ${patch} to template '${templateName}'`);
56+
} else {
57+
console.log(`Skipping '${templateName}'`);
58+
}
59+
}
60+
61+
async function execAsync(command) {
62+
return new Promise((resolve, reject) => {
63+
exec(command, (error, stdout, stderr) => {
64+
if (error) {
65+
reject(error);
66+
} else {
67+
resolve(stdout);
68+
}
69+
});
70+
});
71+
}
72+
73+
// called like so: node scripts/patchTemplates.js /path/to/templates patchFile.patch "Patch message"
74+
async function main() {
75+
// Make a JSON request to https://app.trigger.dev/api/v1/templates and parse the response as an array of templates
76+
const templates = await fetch(
77+
"https://app.trigger.dev/api/v1/templates"
78+
).then((res) => res.json());
79+
80+
for (const template of templates) {
81+
try {
82+
await patchTemplate(template.slug, process.argv[3], process.argv[4]);
83+
} catch (error) {
84+
console.log(`Failed to update template '${template.slug}'`, error);
85+
}
86+
}
87+
}
88+
89+
main().catch(console.error);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
From a15d8456dfb82b88137d40e0fc0202dcc8134231 Mon Sep 17 00:00:00 2001
2+
From: Eric Allam <eallam@icloud.com>
3+
Date: Thu, 2 Mar 2023 22:46:05 +0000
4+
Subject: [PATCH] Update package.json
5+
6+
---
7+
package.json | 3 +++
8+
1 file changed, 3 insertions(+)
9+
10+
diff --git a/package.json b/package.json
11+
index f1616fe..d87cec6 100644
12+
--- a/package.json
13+
+++ b/package.json
14+
@@ -25,5 +25,8 @@
15+
"tsup": "^6.5.0",
16+
"tsx": "^3.12.2",
17+
"typescript": "^4.9.4"
18+
+ },
19+
+ "triggerdotdev": {
20+
+ "template": "hello-world"
21+
}
22+
}
23+

0 commit comments

Comments
 (0)