@elizaos/plugin-github 2.0.0-alpha.6 → 2.0.3-beta.2
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/LICENSE +21 -0
- package/README.md +86 -0
- package/package.json +37 -99
- package/dist/index.js +0 -2219
- package/dist/index.js.map +0 -27
package/dist/index.js
DELETED
|
@@ -1,2219 +0,0 @@
|
|
|
1
|
-
// index.ts
|
|
2
|
-
import { logger as logger9 } from "@elizaos/core";
|
|
3
|
-
|
|
4
|
-
// actions/createBranch.ts
|
|
5
|
-
import {
|
|
6
|
-
logger as logger2
|
|
7
|
-
} from "@elizaos/core";
|
|
8
|
-
|
|
9
|
-
// generated/specs/specs.ts
|
|
10
|
-
var coreActionsSpec = {
|
|
11
|
-
version: "1.0.0",
|
|
12
|
-
actions: [
|
|
13
|
-
{
|
|
14
|
-
name: "CREATE_GITHUB_BRANCH",
|
|
15
|
-
description: "",
|
|
16
|
-
parameters: []
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
name: "CREATE_GITHUB_COMMENT",
|
|
20
|
-
description: "",
|
|
21
|
-
parameters: []
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: "CREATE_GITHUB_ISSUE",
|
|
25
|
-
description: "",
|
|
26
|
-
parameters: []
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: "CREATE_GITHUB_PULL_REQUEST",
|
|
30
|
-
description: "",
|
|
31
|
-
parameters: []
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: "MERGE_GITHUB_PULL_REQUEST",
|
|
35
|
-
description: "",
|
|
36
|
-
parameters: []
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "PUSH_GITHUB_CODE",
|
|
40
|
-
description: "",
|
|
41
|
-
parameters: []
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: "REVIEW_GITHUB_PULL_REQUEST",
|
|
45
|
-
description: "",
|
|
46
|
-
parameters: []
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
};
|
|
50
|
-
var allActionsSpec = {
|
|
51
|
-
version: "1.0.0",
|
|
52
|
-
actions: [
|
|
53
|
-
{
|
|
54
|
-
name: "CREATE_GITHUB_BRANCH",
|
|
55
|
-
description: "",
|
|
56
|
-
parameters: []
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: "CREATE_GITHUB_COMMENT",
|
|
60
|
-
description: "",
|
|
61
|
-
parameters: []
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
name: "CREATE_GITHUB_ISSUE",
|
|
65
|
-
description: "",
|
|
66
|
-
parameters: []
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: "CREATE_GITHUB_PULL_REQUEST",
|
|
70
|
-
description: "",
|
|
71
|
-
parameters: []
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: "MERGE_GITHUB_PULL_REQUEST",
|
|
75
|
-
description: "",
|
|
76
|
-
parameters: []
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
name: "PUSH_GITHUB_CODE",
|
|
80
|
-
description: "",
|
|
81
|
-
parameters: []
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
name: "REVIEW_GITHUB_PULL_REQUEST",
|
|
85
|
-
description: "",
|
|
86
|
-
parameters: []
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
};
|
|
90
|
-
var coreProvidersSpec = {
|
|
91
|
-
version: "1.0.0",
|
|
92
|
-
providers: [
|
|
93
|
-
{
|
|
94
|
-
name: "GITHUB_ISSUE_CONTEXT",
|
|
95
|
-
description: "Provides detailed context about a specific GitHub issue or pull request when referenced",
|
|
96
|
-
dynamic: true
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
name: "GITHUB_REPOSITORY_STATE",
|
|
100
|
-
description: "Provides context about the current GitHub repository including recent activity",
|
|
101
|
-
dynamic: true
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
};
|
|
105
|
-
var allProvidersSpec = {
|
|
106
|
-
version: "1.0.0",
|
|
107
|
-
providers: [
|
|
108
|
-
{
|
|
109
|
-
name: "GITHUB_ISSUE_CONTEXT",
|
|
110
|
-
description: "Provides detailed context about a specific GitHub issue or pull request when referenced",
|
|
111
|
-
dynamic: true
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: "GITHUB_REPOSITORY_STATE",
|
|
115
|
-
description: "Provides context about the current GitHub repository including recent activity",
|
|
116
|
-
dynamic: true
|
|
117
|
-
}
|
|
118
|
-
]
|
|
119
|
-
};
|
|
120
|
-
var coreEvaluatorsSpec = {
|
|
121
|
-
version: "1.0.0",
|
|
122
|
-
evaluators: []
|
|
123
|
-
};
|
|
124
|
-
var allEvaluatorsSpec = {
|
|
125
|
-
version: "1.0.0",
|
|
126
|
-
evaluators: []
|
|
127
|
-
};
|
|
128
|
-
var coreActionDocs = coreActionsSpec.actions;
|
|
129
|
-
var allActionDocs = allActionsSpec.actions;
|
|
130
|
-
var coreProviderDocs = coreProvidersSpec.providers;
|
|
131
|
-
var allProviderDocs = allProvidersSpec.providers;
|
|
132
|
-
var coreEvaluatorDocs = coreEvaluatorsSpec.evaluators;
|
|
133
|
-
var allEvaluatorDocs = allEvaluatorsSpec.evaluators;
|
|
134
|
-
|
|
135
|
-
// generated/specs/spec-helpers.ts
|
|
136
|
-
var coreActionMap = new Map(coreActionDocs.map((doc) => [doc.name, doc]));
|
|
137
|
-
var allActionMap = new Map(allActionDocs.map((doc) => [doc.name, doc]));
|
|
138
|
-
var coreProviderMap = new Map(coreProviderDocs.map((doc) => [doc.name, doc]));
|
|
139
|
-
var allProviderMap = new Map(allProviderDocs.map((doc) => [doc.name, doc]));
|
|
140
|
-
var coreEvaluatorMap = new Map(coreEvaluatorDocs.map((doc) => [doc.name, doc]));
|
|
141
|
-
var allEvaluatorMap = new Map(allEvaluatorDocs.map((doc) => [doc.name, doc]));
|
|
142
|
-
function getActionSpec(name) {
|
|
143
|
-
return coreActionMap.get(name) ?? allActionMap.get(name);
|
|
144
|
-
}
|
|
145
|
-
function requireActionSpec(name) {
|
|
146
|
-
const spec = getActionSpec(name);
|
|
147
|
-
if (!spec) {
|
|
148
|
-
throw new Error(`Action spec not found: ${name}`);
|
|
149
|
-
}
|
|
150
|
-
return spec;
|
|
151
|
-
}
|
|
152
|
-
function getProviderSpec(name) {
|
|
153
|
-
return coreProviderMap.get(name) ?? allProviderMap.get(name);
|
|
154
|
-
}
|
|
155
|
-
function requireProviderSpec(name) {
|
|
156
|
-
const spec = getProviderSpec(name);
|
|
157
|
-
if (!spec) {
|
|
158
|
-
throw new Error(`Provider spec not found: ${name}`);
|
|
159
|
-
}
|
|
160
|
-
return spec;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// service.ts
|
|
164
|
-
import { logger, Service } from "@elizaos/core";
|
|
165
|
-
import { Octokit } from "@octokit/rest";
|
|
166
|
-
|
|
167
|
-
// config.ts
|
|
168
|
-
import { z as z2 } from "zod";
|
|
169
|
-
|
|
170
|
-
// error.ts
|
|
171
|
-
class GitHubError extends Error {
|
|
172
|
-
constructor(message) {
|
|
173
|
-
super(message);
|
|
174
|
-
this.name = "GitHubError";
|
|
175
|
-
Object.setPrototypeOf(this, GitHubError.prototype);
|
|
176
|
-
}
|
|
177
|
-
isRetryable() {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
retryAfterMs() {
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
class ConfigError extends GitHubError {
|
|
185
|
-
constructor(message) {
|
|
186
|
-
super(`Configuration error: ${message}`);
|
|
187
|
-
this.name = "ConfigError";
|
|
188
|
-
Object.setPrototypeOf(this, ConfigError.prototype);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
class MissingSettingError extends GitHubError {
|
|
193
|
-
settingName;
|
|
194
|
-
constructor(settingName) {
|
|
195
|
-
super(`Missing required setting: ${settingName}`);
|
|
196
|
-
this.name = "MissingSettingError";
|
|
197
|
-
this.settingName = settingName;
|
|
198
|
-
Object.setPrototypeOf(this, MissingSettingError.prototype);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
class FileNotFoundError extends GitHubError {
|
|
202
|
-
path;
|
|
203
|
-
constructor(path, owner, repo) {
|
|
204
|
-
super(`File not found: ${path} in ${owner}/${repo}`);
|
|
205
|
-
this.name = "FileNotFoundError";
|
|
206
|
-
this.path = path;
|
|
207
|
-
Object.setPrototypeOf(this, FileNotFoundError.prototype);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// types.ts
|
|
212
|
-
import { z } from "zod";
|
|
213
|
-
var repositoryRefSchema = z.object({
|
|
214
|
-
owner: z.string().min(1, "Owner is required"),
|
|
215
|
-
repo: z.string().min(1, "Repo is required")
|
|
216
|
-
});
|
|
217
|
-
var fileRefSchema = repositoryRefSchema.extend({
|
|
218
|
-
path: z.string().min(1, "Path is required"),
|
|
219
|
-
branch: z.string().optional()
|
|
220
|
-
});
|
|
221
|
-
var createIssueSchema = repositoryRefSchema.extend({
|
|
222
|
-
title: z.string().min(1, "Title is required"),
|
|
223
|
-
body: z.string().optional(),
|
|
224
|
-
assignees: z.array(z.string()).optional(),
|
|
225
|
-
labels: z.array(z.string()).optional(),
|
|
226
|
-
milestone: z.number().optional()
|
|
227
|
-
});
|
|
228
|
-
var updateIssueSchema = repositoryRefSchema.extend({
|
|
229
|
-
issueNumber: z.number().min(1, "Issue number is required"),
|
|
230
|
-
title: z.string().optional(),
|
|
231
|
-
body: z.string().optional(),
|
|
232
|
-
state: z.enum(["open", "closed"]).optional(),
|
|
233
|
-
stateReason: z.enum(["completed", "not_planned", "reopened"]).optional(),
|
|
234
|
-
assignees: z.array(z.string()).optional(),
|
|
235
|
-
labels: z.array(z.string()).optional(),
|
|
236
|
-
milestone: z.number().nullable().optional()
|
|
237
|
-
});
|
|
238
|
-
var createPullRequestSchema = repositoryRefSchema.extend({
|
|
239
|
-
title: z.string().min(1, "Title is required"),
|
|
240
|
-
body: z.string().optional(),
|
|
241
|
-
head: z.string().min(1, "Head branch is required"),
|
|
242
|
-
base: z.string().min(1, "Base branch is required"),
|
|
243
|
-
draft: z.boolean().optional(),
|
|
244
|
-
maintainerCanModify: z.boolean().optional()
|
|
245
|
-
});
|
|
246
|
-
var createReviewSchema = repositoryRefSchema.extend({
|
|
247
|
-
pullNumber: z.number().min(1, "Pull request number is required"),
|
|
248
|
-
body: z.string().optional(),
|
|
249
|
-
event: z.enum(["APPROVE", "REQUEST_CHANGES", "COMMENT"]),
|
|
250
|
-
commitId: z.string().optional(),
|
|
251
|
-
comments: z.array(z.object({
|
|
252
|
-
path: z.string(),
|
|
253
|
-
line: z.number(),
|
|
254
|
-
body: z.string(),
|
|
255
|
-
side: z.enum(["LEFT", "RIGHT"]).optional(),
|
|
256
|
-
startLine: z.number().optional(),
|
|
257
|
-
startSide: z.enum(["LEFT", "RIGHT"]).optional()
|
|
258
|
-
})).optional()
|
|
259
|
-
});
|
|
260
|
-
var createCommentSchema = repositoryRefSchema.extend({
|
|
261
|
-
issueNumber: z.number().min(1, "Issue number is required"),
|
|
262
|
-
body: z.string().min(1, "Comment body is required")
|
|
263
|
-
});
|
|
264
|
-
var createBranchSchema = repositoryRefSchema.extend({
|
|
265
|
-
branchName: z.string().min(1, "Branch name is required"),
|
|
266
|
-
fromRef: z.string().min(1, "Source ref is required")
|
|
267
|
-
});
|
|
268
|
-
var createCommitSchema = repositoryRefSchema.extend({
|
|
269
|
-
message: z.string().min(1, "Commit message is required"),
|
|
270
|
-
files: z.array(z.object({
|
|
271
|
-
path: z.string().min(1, "File path is required"),
|
|
272
|
-
content: z.string(),
|
|
273
|
-
encoding: z.enum(["utf-8", "base64"]).optional(),
|
|
274
|
-
operation: z.enum(["add", "modify", "delete"]).optional()
|
|
275
|
-
})),
|
|
276
|
-
branch: z.string().min(1, "Branch is required"),
|
|
277
|
-
parentSha: z.string().optional(),
|
|
278
|
-
authorName: z.string().optional(),
|
|
279
|
-
authorEmail: z.string().optional()
|
|
280
|
-
});
|
|
281
|
-
var mergePullRequestSchema = repositoryRefSchema.extend({
|
|
282
|
-
pullNumber: z.number().min(1, "Pull request number is required"),
|
|
283
|
-
commitTitle: z.string().optional(),
|
|
284
|
-
commitMessage: z.string().optional(),
|
|
285
|
-
mergeMethod: z.enum(["merge", "squash", "rebase"]).optional(),
|
|
286
|
-
sha: z.string().optional()
|
|
287
|
-
});
|
|
288
|
-
var gitHubSettingsSchema = z.object({
|
|
289
|
-
apiToken: z.string().min(1, "API token is required"),
|
|
290
|
-
owner: z.string().optional(),
|
|
291
|
-
repo: z.string().optional(),
|
|
292
|
-
branch: z.string().optional(),
|
|
293
|
-
webhookSecret: z.string().optional(),
|
|
294
|
-
appId: z.string().optional(),
|
|
295
|
-
appPrivateKey: z.string().optional(),
|
|
296
|
-
installationId: z.string().optional()
|
|
297
|
-
});
|
|
298
|
-
function formatZodErrors(error) {
|
|
299
|
-
return z.prettifyError(error);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// config.ts
|
|
303
|
-
var configSchema = z2.object({
|
|
304
|
-
apiToken: z2.string().min(1, "API token is required"),
|
|
305
|
-
owner: z2.string().optional(),
|
|
306
|
-
repo: z2.string().optional(),
|
|
307
|
-
branch: z2.string().default("main"),
|
|
308
|
-
webhookSecret: z2.string().optional(),
|
|
309
|
-
appId: z2.string().optional(),
|
|
310
|
-
appPrivateKey: z2.string().optional(),
|
|
311
|
-
installationId: z2.string().optional()
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
class GitHubPluginConfig {
|
|
315
|
-
apiToken;
|
|
316
|
-
owner;
|
|
317
|
-
repo;
|
|
318
|
-
branch;
|
|
319
|
-
webhookSecret;
|
|
320
|
-
appId;
|
|
321
|
-
appPrivateKey;
|
|
322
|
-
installationId;
|
|
323
|
-
constructor(config) {
|
|
324
|
-
this.apiToken = config.apiToken;
|
|
325
|
-
this.owner = config.owner;
|
|
326
|
-
this.repo = config.repo;
|
|
327
|
-
this.branch = config.branch;
|
|
328
|
-
this.webhookSecret = config.webhookSecret;
|
|
329
|
-
this.appId = config.appId;
|
|
330
|
-
this.appPrivateKey = config.appPrivateKey;
|
|
331
|
-
this.installationId = config.installationId;
|
|
332
|
-
}
|
|
333
|
-
static fromRuntime(runtime) {
|
|
334
|
-
const apiToken = runtime.getSetting("GITHUB_API_TOKEN");
|
|
335
|
-
if (!apiToken) {
|
|
336
|
-
throw new MissingSettingError("GITHUB_API_TOKEN");
|
|
337
|
-
}
|
|
338
|
-
const rawConfig = {
|
|
339
|
-
apiToken,
|
|
340
|
-
owner: runtime.getSetting("GITHUB_OWNER") ?? undefined,
|
|
341
|
-
repo: runtime.getSetting("GITHUB_REPO") ?? undefined,
|
|
342
|
-
branch: runtime.getSetting("GITHUB_BRANCH") ?? "main",
|
|
343
|
-
webhookSecret: runtime.getSetting("GITHUB_WEBHOOK_SECRET") ?? undefined,
|
|
344
|
-
appId: runtime.getSetting("GITHUB_APP_ID") ?? undefined,
|
|
345
|
-
appPrivateKey: runtime.getSetting("GITHUB_APP_PRIVATE_KEY") ?? undefined,
|
|
346
|
-
installationId: runtime.getSetting("GITHUB_INSTALLATION_ID") ?? undefined
|
|
347
|
-
};
|
|
348
|
-
const result = configSchema.safeParse(rawConfig);
|
|
349
|
-
if (!result.success) {
|
|
350
|
-
throw new ConfigError(formatZodErrors(result.error));
|
|
351
|
-
}
|
|
352
|
-
return new GitHubPluginConfig(result.data);
|
|
353
|
-
}
|
|
354
|
-
static fromSettings(settings) {
|
|
355
|
-
const result = configSchema.safeParse({
|
|
356
|
-
...settings,
|
|
357
|
-
branch: settings.branch ?? "main"
|
|
358
|
-
});
|
|
359
|
-
if (!result.success) {
|
|
360
|
-
throw new ConfigError(formatZodErrors(result.error));
|
|
361
|
-
}
|
|
362
|
-
return new GitHubPluginConfig(result.data);
|
|
363
|
-
}
|
|
364
|
-
static fromEnv() {
|
|
365
|
-
const apiToken = process.env.GITHUB_API_TOKEN;
|
|
366
|
-
if (!apiToken) {
|
|
367
|
-
throw new MissingSettingError("GITHUB_API_TOKEN");
|
|
368
|
-
}
|
|
369
|
-
const rawConfig = {
|
|
370
|
-
apiToken,
|
|
371
|
-
owner: process.env.GITHUB_OWNER,
|
|
372
|
-
repo: process.env.GITHUB_REPO,
|
|
373
|
-
branch: process.env.GITHUB_BRANCH ?? "main",
|
|
374
|
-
webhookSecret: process.env.GITHUB_WEBHOOK_SECRET,
|
|
375
|
-
appId: process.env.GITHUB_APP_ID,
|
|
376
|
-
appPrivateKey: process.env.GITHUB_APP_PRIVATE_KEY,
|
|
377
|
-
installationId: process.env.GITHUB_INSTALLATION_ID
|
|
378
|
-
};
|
|
379
|
-
const result = configSchema.safeParse(rawConfig);
|
|
380
|
-
if (!result.success) {
|
|
381
|
-
throw new ConfigError(formatZodErrors(result.error));
|
|
382
|
-
}
|
|
383
|
-
return new GitHubPluginConfig(result.data);
|
|
384
|
-
}
|
|
385
|
-
getRepositoryRef(owner, repo) {
|
|
386
|
-
const resolvedOwner = owner ?? this.owner;
|
|
387
|
-
const resolvedRepo = repo ?? this.repo;
|
|
388
|
-
if (!resolvedOwner) {
|
|
389
|
-
throw new MissingSettingError("owner (GITHUB_OWNER)");
|
|
390
|
-
}
|
|
391
|
-
if (!resolvedRepo) {
|
|
392
|
-
throw new MissingSettingError("repo (GITHUB_REPO)");
|
|
393
|
-
}
|
|
394
|
-
return { owner: resolvedOwner, repo: resolvedRepo };
|
|
395
|
-
}
|
|
396
|
-
hasAppAuth() {
|
|
397
|
-
return !!(this.appId && this.appPrivateKey);
|
|
398
|
-
}
|
|
399
|
-
validate() {
|
|
400
|
-
if (!this.apiToken.startsWith("ghp_") && !this.apiToken.startsWith("gho_") && !this.apiToken.startsWith("ghu_") && !this.apiToken.startsWith("ghs_") && !this.apiToken.startsWith("ghr_") && !this.apiToken.startsWith("github_pat_")) {
|
|
401
|
-
console.warn("GitHub API token format not recognized. Ensure it is a valid token.");
|
|
402
|
-
}
|
|
403
|
-
if (this.hasAppAuth() && !this.installationId) {
|
|
404
|
-
throw new ConfigError("GITHUB_INSTALLATION_ID is required when using GitHub App authentication");
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
toSettings() {
|
|
408
|
-
return {
|
|
409
|
-
apiToken: this.apiToken,
|
|
410
|
-
owner: this.owner,
|
|
411
|
-
repo: this.repo,
|
|
412
|
-
branch: this.branch,
|
|
413
|
-
webhookSecret: this.webhookSecret,
|
|
414
|
-
appId: this.appId,
|
|
415
|
-
appPrivateKey: this.appPrivateKey,
|
|
416
|
-
installationId: this.installationId
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
function validateGitHubConfig(runtime) {
|
|
421
|
-
const config = GitHubPluginConfig.fromRuntime(runtime);
|
|
422
|
-
config.validate();
|
|
423
|
-
return config;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// service.ts
|
|
427
|
-
var GITHUB_SERVICE_NAME = "github";
|
|
428
|
-
|
|
429
|
-
class GitHubService extends Service {
|
|
430
|
-
static serviceType = GITHUB_SERVICE_NAME;
|
|
431
|
-
octokit = null;
|
|
432
|
-
_config = null;
|
|
433
|
-
capabilityDescription = "GitHub integration for repository management, issues, pull requests, and code reviews";
|
|
434
|
-
get name() {
|
|
435
|
-
return GITHUB_SERVICE_NAME;
|
|
436
|
-
}
|
|
437
|
-
getConfig() {
|
|
438
|
-
if (!this._config) {
|
|
439
|
-
throw new Error("GitHub service not initialized");
|
|
440
|
-
}
|
|
441
|
-
return this._config;
|
|
442
|
-
}
|
|
443
|
-
getClient() {
|
|
444
|
-
if (!this.octokit) {
|
|
445
|
-
throw new Error("GitHub service not initialized");
|
|
446
|
-
}
|
|
447
|
-
return this.octokit;
|
|
448
|
-
}
|
|
449
|
-
async start(runtime) {
|
|
450
|
-
logger.info("Starting GitHub service...");
|
|
451
|
-
this._config = validateGitHubConfig(runtime);
|
|
452
|
-
const settings = this._config.toSettings();
|
|
453
|
-
this.config = {
|
|
454
|
-
apiToken: settings.apiToken ?? "",
|
|
455
|
-
owner: settings.owner ?? undefined,
|
|
456
|
-
repo: settings.repo ?? undefined,
|
|
457
|
-
branch: settings.branch ?? "main",
|
|
458
|
-
webhookSecret: settings.webhookSecret ?? undefined,
|
|
459
|
-
appId: settings.appId ?? undefined,
|
|
460
|
-
appPrivateKey: settings.appPrivateKey ?? undefined,
|
|
461
|
-
installationId: settings.installationId ?? undefined
|
|
462
|
-
};
|
|
463
|
-
this.octokit = new Octokit({
|
|
464
|
-
auth: this._config.apiToken,
|
|
465
|
-
userAgent: "elizaos-plugin-github/1.0.0"
|
|
466
|
-
});
|
|
467
|
-
const { data: user } = await this.octokit.users.getAuthenticated();
|
|
468
|
-
logger.info(`GitHub service started - authenticated as ${user.login}`);
|
|
469
|
-
}
|
|
470
|
-
async stop() {
|
|
471
|
-
logger.info("Stopping GitHub service...");
|
|
472
|
-
this.octokit = null;
|
|
473
|
-
this._config = null;
|
|
474
|
-
this.config = undefined;
|
|
475
|
-
logger.info("GitHub service stopped");
|
|
476
|
-
}
|
|
477
|
-
async getRepository(params) {
|
|
478
|
-
const client = this.getClient();
|
|
479
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
480
|
-
const { data } = await client.repos.get({ owner, repo });
|
|
481
|
-
return this.mapRepository(data);
|
|
482
|
-
}
|
|
483
|
-
async listRepositories(username, options) {
|
|
484
|
-
const client = this.getClient();
|
|
485
|
-
const { data } = username ? await client.repos.listForUser({
|
|
486
|
-
username,
|
|
487
|
-
type: options?.type ?? "owner",
|
|
488
|
-
per_page: options?.perPage ?? 30,
|
|
489
|
-
page: options?.page ?? 1
|
|
490
|
-
}) : await client.repos.listForAuthenticatedUser({
|
|
491
|
-
type: options?.type ?? "all",
|
|
492
|
-
per_page: options?.perPage ?? 30,
|
|
493
|
-
page: options?.page ?? 1
|
|
494
|
-
});
|
|
495
|
-
return data.map((r) => this.mapRepository(r));
|
|
496
|
-
}
|
|
497
|
-
async createIssue(params) {
|
|
498
|
-
const client = this.getClient();
|
|
499
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
500
|
-
const { data } = await client.issues.create({
|
|
501
|
-
owner,
|
|
502
|
-
repo,
|
|
503
|
-
title: params.title,
|
|
504
|
-
body: params.body,
|
|
505
|
-
assignees: params.assignees,
|
|
506
|
-
labels: params.labels,
|
|
507
|
-
milestone: params.milestone
|
|
508
|
-
});
|
|
509
|
-
return this.mapIssue(data);
|
|
510
|
-
}
|
|
511
|
-
async getIssue(params) {
|
|
512
|
-
const client = this.getClient();
|
|
513
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
514
|
-
const { data } = await client.issues.get({
|
|
515
|
-
owner,
|
|
516
|
-
repo,
|
|
517
|
-
issue_number: params.issueNumber
|
|
518
|
-
});
|
|
519
|
-
return this.mapIssue(data);
|
|
520
|
-
}
|
|
521
|
-
async updateIssue(params) {
|
|
522
|
-
const client = this.getClient();
|
|
523
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
524
|
-
const { data } = await client.issues.update({
|
|
525
|
-
owner,
|
|
526
|
-
repo,
|
|
527
|
-
issue_number: params.issueNumber,
|
|
528
|
-
title: params.title,
|
|
529
|
-
body: params.body,
|
|
530
|
-
state: params.state,
|
|
531
|
-
state_reason: params.stateReason,
|
|
532
|
-
assignees: params.assignees,
|
|
533
|
-
labels: params.labels,
|
|
534
|
-
milestone: params.milestone ?? undefined
|
|
535
|
-
});
|
|
536
|
-
return this.mapIssue(data);
|
|
537
|
-
}
|
|
538
|
-
async listIssues(params) {
|
|
539
|
-
const client = this.getClient();
|
|
540
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
541
|
-
const { data } = await client.issues.listForRepo({
|
|
542
|
-
owner,
|
|
543
|
-
repo,
|
|
544
|
-
state: params.state ?? "open",
|
|
545
|
-
labels: params.labels,
|
|
546
|
-
sort: params.sort ?? "created",
|
|
547
|
-
direction: params.direction ?? "desc",
|
|
548
|
-
assignee: params.assignee,
|
|
549
|
-
creator: params.creator,
|
|
550
|
-
mentioned: params.mentioned,
|
|
551
|
-
per_page: params.perPage ?? 30,
|
|
552
|
-
page: params.page ?? 1
|
|
553
|
-
});
|
|
554
|
-
return data.filter((issue) => !issue.pull_request).map((issue) => this.mapIssue(issue));
|
|
555
|
-
}
|
|
556
|
-
async closeIssue(params) {
|
|
557
|
-
return this.updateIssue({
|
|
558
|
-
...params,
|
|
559
|
-
state: "closed",
|
|
560
|
-
stateReason: params.reason ?? "completed"
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
async reopenIssue(params) {
|
|
564
|
-
return this.updateIssue({
|
|
565
|
-
...params,
|
|
566
|
-
state: "open",
|
|
567
|
-
stateReason: "reopened"
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
async createPullRequest(params) {
|
|
571
|
-
const client = this.getClient();
|
|
572
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
573
|
-
const { data } = await client.pulls.create({
|
|
574
|
-
owner,
|
|
575
|
-
repo,
|
|
576
|
-
title: params.title,
|
|
577
|
-
body: params.body,
|
|
578
|
-
head: params.head,
|
|
579
|
-
base: params.base,
|
|
580
|
-
draft: params.draft,
|
|
581
|
-
maintainer_can_modify: params.maintainerCanModify
|
|
582
|
-
});
|
|
583
|
-
return this.mapPullRequest(data);
|
|
584
|
-
}
|
|
585
|
-
async getPullRequest(params) {
|
|
586
|
-
const client = this.getClient();
|
|
587
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
588
|
-
const { data } = await client.pulls.get({
|
|
589
|
-
owner,
|
|
590
|
-
repo,
|
|
591
|
-
pull_number: params.pullNumber
|
|
592
|
-
});
|
|
593
|
-
return this.mapPullRequest(data);
|
|
594
|
-
}
|
|
595
|
-
async updatePullRequest(params) {
|
|
596
|
-
const client = this.getClient();
|
|
597
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
598
|
-
const { data } = await client.pulls.update({
|
|
599
|
-
owner,
|
|
600
|
-
repo,
|
|
601
|
-
pull_number: params.pullNumber,
|
|
602
|
-
title: params.title,
|
|
603
|
-
body: params.body,
|
|
604
|
-
state: params.state,
|
|
605
|
-
base: params.base,
|
|
606
|
-
maintainer_can_modify: params.maintainerCanModify
|
|
607
|
-
});
|
|
608
|
-
return this.mapPullRequest(data);
|
|
609
|
-
}
|
|
610
|
-
async listPullRequests(params) {
|
|
611
|
-
const client = this.getClient();
|
|
612
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
613
|
-
const { data } = await client.pulls.list({
|
|
614
|
-
owner,
|
|
615
|
-
repo,
|
|
616
|
-
state: params.state ?? "open",
|
|
617
|
-
head: params.head,
|
|
618
|
-
base: params.base,
|
|
619
|
-
sort: params.sort ?? "created",
|
|
620
|
-
direction: params.direction ?? "desc",
|
|
621
|
-
per_page: params.perPage ?? 30,
|
|
622
|
-
page: params.page ?? 1
|
|
623
|
-
});
|
|
624
|
-
return data.map((pr) => this.mapPullRequest(pr));
|
|
625
|
-
}
|
|
626
|
-
async mergePullRequest(params) {
|
|
627
|
-
const client = this.getClient();
|
|
628
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
629
|
-
const { data } = await client.pulls.merge({
|
|
630
|
-
owner,
|
|
631
|
-
repo,
|
|
632
|
-
pull_number: params.pullNumber,
|
|
633
|
-
commit_title: params.commitTitle,
|
|
634
|
-
commit_message: params.commitMessage,
|
|
635
|
-
merge_method: params.mergeMethod ?? "merge",
|
|
636
|
-
sha: params.sha
|
|
637
|
-
});
|
|
638
|
-
return {
|
|
639
|
-
sha: data.sha,
|
|
640
|
-
merged: data.merged,
|
|
641
|
-
message: data.message
|
|
642
|
-
};
|
|
643
|
-
}
|
|
644
|
-
async closePullRequest(params) {
|
|
645
|
-
return this.updatePullRequest({
|
|
646
|
-
...params,
|
|
647
|
-
state: "closed"
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
async createReview(params) {
|
|
651
|
-
const client = this.getClient();
|
|
652
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
653
|
-
const { data } = await client.pulls.createReview({
|
|
654
|
-
owner,
|
|
655
|
-
repo,
|
|
656
|
-
pull_number: params.pullNumber,
|
|
657
|
-
body: params.body,
|
|
658
|
-
event: params.event,
|
|
659
|
-
commit_id: params.commitId,
|
|
660
|
-
comments: params.comments?.map((c) => ({
|
|
661
|
-
path: c.path,
|
|
662
|
-
line: c.line,
|
|
663
|
-
body: c.body,
|
|
664
|
-
side: c.side,
|
|
665
|
-
start_line: c.startLine,
|
|
666
|
-
start_side: c.startSide
|
|
667
|
-
}))
|
|
668
|
-
});
|
|
669
|
-
return this.mapReview(data);
|
|
670
|
-
}
|
|
671
|
-
async listReviews(params) {
|
|
672
|
-
const client = this.getClient();
|
|
673
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
674
|
-
const { data } = await client.pulls.listReviews({
|
|
675
|
-
owner,
|
|
676
|
-
repo,
|
|
677
|
-
pull_number: params.pullNumber
|
|
678
|
-
});
|
|
679
|
-
return data.map((r) => this.mapReview(r));
|
|
680
|
-
}
|
|
681
|
-
async createComment(params) {
|
|
682
|
-
const client = this.getClient();
|
|
683
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
684
|
-
const { data } = await client.issues.createComment({
|
|
685
|
-
owner,
|
|
686
|
-
repo,
|
|
687
|
-
issue_number: params.issueNumber,
|
|
688
|
-
body: params.body
|
|
689
|
-
});
|
|
690
|
-
return this.mapComment(data);
|
|
691
|
-
}
|
|
692
|
-
async listComments(params) {
|
|
693
|
-
const client = this.getClient();
|
|
694
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
695
|
-
const { data } = await client.issues.listComments({
|
|
696
|
-
owner,
|
|
697
|
-
repo,
|
|
698
|
-
issue_number: params.issueNumber,
|
|
699
|
-
per_page: params.perPage ?? 30,
|
|
700
|
-
page: params.page ?? 1
|
|
701
|
-
});
|
|
702
|
-
return data.map((c) => this.mapComment(c));
|
|
703
|
-
}
|
|
704
|
-
async createBranch(params) {
|
|
705
|
-
const client = this.getClient();
|
|
706
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
707
|
-
let sha;
|
|
708
|
-
if (params.fromRef.match(/^[0-9a-f]{40}$/i)) {
|
|
709
|
-
sha = params.fromRef;
|
|
710
|
-
} else {
|
|
711
|
-
const { data: refData } = await client.git.getRef({
|
|
712
|
-
owner,
|
|
713
|
-
repo,
|
|
714
|
-
ref: `heads/${params.fromRef}`
|
|
715
|
-
});
|
|
716
|
-
sha = refData.object.sha;
|
|
717
|
-
}
|
|
718
|
-
await client.git.createRef({
|
|
719
|
-
owner,
|
|
720
|
-
repo,
|
|
721
|
-
ref: `refs/heads/${params.branchName}`,
|
|
722
|
-
sha
|
|
723
|
-
});
|
|
724
|
-
return {
|
|
725
|
-
name: params.branchName,
|
|
726
|
-
sha,
|
|
727
|
-
protected: false
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
async deleteBranch(params) {
|
|
731
|
-
const client = this.getClient();
|
|
732
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
733
|
-
await client.git.deleteRef({
|
|
734
|
-
owner,
|
|
735
|
-
repo,
|
|
736
|
-
ref: `heads/${params.branchName}`
|
|
737
|
-
});
|
|
738
|
-
}
|
|
739
|
-
async listBranches(params) {
|
|
740
|
-
const client = this.getClient();
|
|
741
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
742
|
-
const { data } = await client.repos.listBranches({
|
|
743
|
-
owner,
|
|
744
|
-
repo,
|
|
745
|
-
per_page: params.perPage ?? 30,
|
|
746
|
-
page: params.page ?? 1
|
|
747
|
-
});
|
|
748
|
-
return data.map((b) => ({
|
|
749
|
-
name: b.name,
|
|
750
|
-
sha: b.commit.sha,
|
|
751
|
-
protected: b.protected
|
|
752
|
-
}));
|
|
753
|
-
}
|
|
754
|
-
async getFile(params) {
|
|
755
|
-
const client = this.getClient();
|
|
756
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
757
|
-
const { data } = await client.repos.getContent({
|
|
758
|
-
owner,
|
|
759
|
-
repo,
|
|
760
|
-
path: params.path,
|
|
761
|
-
ref: params.branch
|
|
762
|
-
});
|
|
763
|
-
if (Array.isArray(data)) {
|
|
764
|
-
throw new FileNotFoundError(`${params.path} is a directory, not a file`, owner, repo);
|
|
765
|
-
}
|
|
766
|
-
if (data.type !== "file") {
|
|
767
|
-
throw new FileNotFoundError(`${params.path} is not a file`, owner, repo);
|
|
768
|
-
}
|
|
769
|
-
let content = "";
|
|
770
|
-
if ("content" in data && data.content) {
|
|
771
|
-
content = Buffer.from(data.content, "base64").toString("utf-8");
|
|
772
|
-
}
|
|
773
|
-
return {
|
|
774
|
-
name: data.name,
|
|
775
|
-
path: data.path,
|
|
776
|
-
content,
|
|
777
|
-
sha: data.sha,
|
|
778
|
-
size: data.size,
|
|
779
|
-
type: data.type,
|
|
780
|
-
encoding: "encoding" in data ? data.encoding ?? "base64" : "base64",
|
|
781
|
-
htmlUrl: data.html_url ?? "",
|
|
782
|
-
downloadUrl: data.download_url
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
async listDirectory(params) {
|
|
786
|
-
const client = this.getClient();
|
|
787
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
788
|
-
const { data } = await client.repos.getContent({
|
|
789
|
-
owner,
|
|
790
|
-
repo,
|
|
791
|
-
path: params.path,
|
|
792
|
-
ref: params.branch
|
|
793
|
-
});
|
|
794
|
-
if (!Array.isArray(data)) {
|
|
795
|
-
throw new FileNotFoundError(`${params.path} is a file, not a directory`, owner, repo);
|
|
796
|
-
}
|
|
797
|
-
return data.map((entry) => ({
|
|
798
|
-
name: entry.name,
|
|
799
|
-
path: entry.path,
|
|
800
|
-
sha: entry.sha,
|
|
801
|
-
size: entry.size,
|
|
802
|
-
type: entry.type,
|
|
803
|
-
htmlUrl: entry.html_url ?? "",
|
|
804
|
-
downloadUrl: entry.download_url
|
|
805
|
-
}));
|
|
806
|
-
}
|
|
807
|
-
async createCommit(params) {
|
|
808
|
-
const client = this.getClient();
|
|
809
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
810
|
-
let parentSha = params.parentSha;
|
|
811
|
-
if (!parentSha) {
|
|
812
|
-
const { data: refData } = await client.git.getRef({
|
|
813
|
-
owner,
|
|
814
|
-
repo,
|
|
815
|
-
ref: `heads/${params.branch}`
|
|
816
|
-
});
|
|
817
|
-
parentSha = refData.object.sha;
|
|
818
|
-
}
|
|
819
|
-
const { data: parentCommit } = await client.git.getCommit({
|
|
820
|
-
owner,
|
|
821
|
-
repo,
|
|
822
|
-
commit_sha: parentSha
|
|
823
|
-
});
|
|
824
|
-
const treeItems = [];
|
|
825
|
-
for (const file of params.files) {
|
|
826
|
-
if (file.operation === "delete") {
|
|
827
|
-
continue;
|
|
828
|
-
}
|
|
829
|
-
const { data: blob } = await client.git.createBlob({
|
|
830
|
-
owner,
|
|
831
|
-
repo,
|
|
832
|
-
content: file.content,
|
|
833
|
-
encoding: file.encoding ?? "utf-8"
|
|
834
|
-
});
|
|
835
|
-
treeItems.push({
|
|
836
|
-
path: file.path,
|
|
837
|
-
mode: "100644",
|
|
838
|
-
type: "blob",
|
|
839
|
-
sha: blob.sha
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
const { data: newTree } = await client.git.createTree({
|
|
843
|
-
owner,
|
|
844
|
-
repo,
|
|
845
|
-
base_tree: parentCommit.tree.sha,
|
|
846
|
-
tree: treeItems
|
|
847
|
-
});
|
|
848
|
-
const { data: commit } = await client.git.createCommit({
|
|
849
|
-
owner,
|
|
850
|
-
repo,
|
|
851
|
-
message: params.message,
|
|
852
|
-
tree: newTree.sha,
|
|
853
|
-
parents: [parentSha],
|
|
854
|
-
author: params.authorName ? {
|
|
855
|
-
name: params.authorName,
|
|
856
|
-
email: params.authorEmail ?? `${params.authorName}@users.noreply.github.com`
|
|
857
|
-
} : undefined
|
|
858
|
-
});
|
|
859
|
-
await client.git.updateRef({
|
|
860
|
-
owner,
|
|
861
|
-
repo,
|
|
862
|
-
ref: `heads/${params.branch}`,
|
|
863
|
-
sha: commit.sha
|
|
864
|
-
});
|
|
865
|
-
return {
|
|
866
|
-
sha: commit.sha,
|
|
867
|
-
message: commit.message,
|
|
868
|
-
author: {
|
|
869
|
-
name: commit.author?.name ?? "Unknown",
|
|
870
|
-
email: commit.author?.email ?? "",
|
|
871
|
-
date: commit.author?.date ?? new Date().toISOString()
|
|
872
|
-
},
|
|
873
|
-
committer: {
|
|
874
|
-
name: commit.committer?.name ?? "Unknown",
|
|
875
|
-
email: commit.committer?.email ?? "",
|
|
876
|
-
date: commit.committer?.date ?? new Date().toISOString()
|
|
877
|
-
},
|
|
878
|
-
timestamp: commit.author?.date ?? new Date().toISOString(),
|
|
879
|
-
htmlUrl: commit.html_url,
|
|
880
|
-
parents: commit.parents.map((p) => p.sha)
|
|
881
|
-
};
|
|
882
|
-
}
|
|
883
|
-
async listCommits(params) {
|
|
884
|
-
const client = this.getClient();
|
|
885
|
-
const { owner, repo } = this.resolveRepoRef(params);
|
|
886
|
-
const branch = params.branch ?? this._config?.branch ?? "main";
|
|
887
|
-
const { data } = await client.repos.listCommits({
|
|
888
|
-
owner,
|
|
889
|
-
repo,
|
|
890
|
-
sha: branch,
|
|
891
|
-
path: params.path,
|
|
892
|
-
per_page: params.perPage ?? 30,
|
|
893
|
-
page: params.page ?? 1
|
|
894
|
-
});
|
|
895
|
-
return data.map((c) => ({
|
|
896
|
-
sha: c.sha,
|
|
897
|
-
message: c.commit.message,
|
|
898
|
-
author: {
|
|
899
|
-
name: c.commit.author?.name ?? "Unknown",
|
|
900
|
-
email: c.commit.author?.email ?? "",
|
|
901
|
-
date: c.commit.author?.date ?? ""
|
|
902
|
-
},
|
|
903
|
-
committer: {
|
|
904
|
-
name: c.commit.committer?.name ?? "Unknown",
|
|
905
|
-
email: c.commit.committer?.email ?? "",
|
|
906
|
-
date: c.commit.committer?.date ?? ""
|
|
907
|
-
},
|
|
908
|
-
timestamp: c.commit.author?.date ?? "",
|
|
909
|
-
htmlUrl: c.html_url,
|
|
910
|
-
parents: c.parents.map((p) => p.sha)
|
|
911
|
-
}));
|
|
912
|
-
}
|
|
913
|
-
async getAuthenticatedUser() {
|
|
914
|
-
const client = this.getClient();
|
|
915
|
-
const { data } = await client.users.getAuthenticated();
|
|
916
|
-
return this.mapUser(data);
|
|
917
|
-
}
|
|
918
|
-
async getUser(username) {
|
|
919
|
-
const client = this.getClient();
|
|
920
|
-
const { data } = await client.users.getByUsername({ username });
|
|
921
|
-
return this.mapUser(data);
|
|
922
|
-
}
|
|
923
|
-
resolveRepoRef(params) {
|
|
924
|
-
const owner = params.owner ?? this._config?.owner;
|
|
925
|
-
const repo = params.repo ?? this._config?.repo;
|
|
926
|
-
if (!owner || !repo) {
|
|
927
|
-
throw new Error("Repository owner and name are required. Configure defaults or provide them explicitly.");
|
|
928
|
-
}
|
|
929
|
-
return { owner, repo };
|
|
930
|
-
}
|
|
931
|
-
mapRepository(data) {
|
|
932
|
-
const d = data;
|
|
933
|
-
const license = d.license;
|
|
934
|
-
return {
|
|
935
|
-
id: d.id,
|
|
936
|
-
name: d.name,
|
|
937
|
-
fullName: d.full_name,
|
|
938
|
-
owner: this.mapUser(d.owner),
|
|
939
|
-
description: d.description,
|
|
940
|
-
private: d.private,
|
|
941
|
-
fork: d.fork,
|
|
942
|
-
defaultBranch: d.default_branch,
|
|
943
|
-
language: d.language,
|
|
944
|
-
stargazersCount: d.stargazers_count,
|
|
945
|
-
forksCount: d.forks_count,
|
|
946
|
-
openIssuesCount: d.open_issues_count,
|
|
947
|
-
watchersCount: d.watchers_count,
|
|
948
|
-
htmlUrl: d.html_url,
|
|
949
|
-
cloneUrl: d.clone_url,
|
|
950
|
-
sshUrl: d.ssh_url,
|
|
951
|
-
createdAt: d.created_at,
|
|
952
|
-
updatedAt: d.updated_at,
|
|
953
|
-
pushedAt: d.pushed_at,
|
|
954
|
-
topics: d.topics ?? [],
|
|
955
|
-
license: license ? {
|
|
956
|
-
key: license.key,
|
|
957
|
-
name: license.name,
|
|
958
|
-
spdxId: license.spdx_id,
|
|
959
|
-
url: license.url
|
|
960
|
-
} : null
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
mapUser(data) {
|
|
964
|
-
const d = data;
|
|
965
|
-
return {
|
|
966
|
-
id: d.id,
|
|
967
|
-
login: d.login,
|
|
968
|
-
name: d.name ?? null,
|
|
969
|
-
avatarUrl: d.avatar_url,
|
|
970
|
-
htmlUrl: d.html_url,
|
|
971
|
-
type: d.type
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
mapIssue(data) {
|
|
975
|
-
const d = data;
|
|
976
|
-
return {
|
|
977
|
-
number: d.number,
|
|
978
|
-
title: d.title,
|
|
979
|
-
body: d.body,
|
|
980
|
-
state: d.state,
|
|
981
|
-
stateReason: d.state_reason ?? null,
|
|
982
|
-
user: this.mapUser(d.user),
|
|
983
|
-
assignees: (d.assignees ?? []).map((a) => this.mapUser(a)),
|
|
984
|
-
labels: (d.labels ?? []).map((l) => this.mapLabel(l)),
|
|
985
|
-
milestone: d.milestone ? this.mapMilestone(d.milestone) : null,
|
|
986
|
-
createdAt: d.created_at,
|
|
987
|
-
updatedAt: d.updated_at,
|
|
988
|
-
closedAt: d.closed_at,
|
|
989
|
-
htmlUrl: d.html_url,
|
|
990
|
-
comments: d.comments,
|
|
991
|
-
isPullRequest: !!d.pull_request
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
mapLabel(data) {
|
|
995
|
-
if (typeof data === "string") {
|
|
996
|
-
return {
|
|
997
|
-
id: 0,
|
|
998
|
-
name: data,
|
|
999
|
-
color: "",
|
|
1000
|
-
description: null,
|
|
1001
|
-
default: false
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
|
-
const d = data;
|
|
1005
|
-
return {
|
|
1006
|
-
id: d.id,
|
|
1007
|
-
name: d.name,
|
|
1008
|
-
color: d.color,
|
|
1009
|
-
description: d.description,
|
|
1010
|
-
default: d.default
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
mapMilestone(data) {
|
|
1014
|
-
const d = data;
|
|
1015
|
-
return {
|
|
1016
|
-
number: d.number,
|
|
1017
|
-
title: d.title,
|
|
1018
|
-
description: d.description,
|
|
1019
|
-
state: d.state,
|
|
1020
|
-
dueOn: d.due_on,
|
|
1021
|
-
createdAt: d.created_at,
|
|
1022
|
-
updatedAt: d.updated_at,
|
|
1023
|
-
closedAt: d.closed_at,
|
|
1024
|
-
openIssues: d.open_issues,
|
|
1025
|
-
closedIssues: d.closed_issues
|
|
1026
|
-
};
|
|
1027
|
-
}
|
|
1028
|
-
mapPullRequest(data) {
|
|
1029
|
-
const d = data;
|
|
1030
|
-
const head = d.head;
|
|
1031
|
-
const base = d.base;
|
|
1032
|
-
const headRepo = head.repo;
|
|
1033
|
-
const baseRepo = base.repo;
|
|
1034
|
-
const headRepoOwner = headRepo?.owner;
|
|
1035
|
-
const baseRepoOwner = baseRepo?.owner;
|
|
1036
|
-
return {
|
|
1037
|
-
number: d.number,
|
|
1038
|
-
title: d.title,
|
|
1039
|
-
body: d.body,
|
|
1040
|
-
state: d.state,
|
|
1041
|
-
draft: d.draft ?? false,
|
|
1042
|
-
merged: d.merged ?? false,
|
|
1043
|
-
mergeable: d.mergeable,
|
|
1044
|
-
mergeableState: d.mergeable_state ?? "unknown",
|
|
1045
|
-
user: this.mapUser(d.user),
|
|
1046
|
-
head: {
|
|
1047
|
-
ref: head.ref,
|
|
1048
|
-
label: head.label,
|
|
1049
|
-
sha: head.sha,
|
|
1050
|
-
repo: headRepo ? {
|
|
1051
|
-
owner: headRepoOwner?.login,
|
|
1052
|
-
repo: headRepo.name
|
|
1053
|
-
} : null
|
|
1054
|
-
},
|
|
1055
|
-
base: {
|
|
1056
|
-
ref: base.ref,
|
|
1057
|
-
label: base.label,
|
|
1058
|
-
sha: base.sha,
|
|
1059
|
-
repo: baseRepo ? {
|
|
1060
|
-
owner: baseRepoOwner?.login,
|
|
1061
|
-
repo: baseRepo.name
|
|
1062
|
-
} : null
|
|
1063
|
-
},
|
|
1064
|
-
assignees: (d.assignees ?? []).map((a) => this.mapUser(a)),
|
|
1065
|
-
requestedReviewers: (d.requested_reviewers ?? []).map((r) => this.mapUser(r)),
|
|
1066
|
-
labels: (d.labels ?? []).map((l) => this.mapLabel(l)),
|
|
1067
|
-
milestone: d.milestone ? this.mapMilestone(d.milestone) : null,
|
|
1068
|
-
createdAt: d.created_at,
|
|
1069
|
-
updatedAt: d.updated_at,
|
|
1070
|
-
closedAt: d.closed_at,
|
|
1071
|
-
mergedAt: d.merged_at,
|
|
1072
|
-
htmlUrl: d.html_url,
|
|
1073
|
-
commits: d.commits ?? 0,
|
|
1074
|
-
additions: d.additions ?? 0,
|
|
1075
|
-
deletions: d.deletions ?? 0,
|
|
1076
|
-
changedFiles: d.changed_files ?? 0
|
|
1077
|
-
};
|
|
1078
|
-
}
|
|
1079
|
-
mapReview(data) {
|
|
1080
|
-
const d = data;
|
|
1081
|
-
return {
|
|
1082
|
-
id: d.id,
|
|
1083
|
-
user: this.mapUser(d.user),
|
|
1084
|
-
body: d.body,
|
|
1085
|
-
state: d.state,
|
|
1086
|
-
commitId: d.commit_id,
|
|
1087
|
-
htmlUrl: d.html_url,
|
|
1088
|
-
submittedAt: d.submitted_at
|
|
1089
|
-
};
|
|
1090
|
-
}
|
|
1091
|
-
mapComment(data) {
|
|
1092
|
-
const d = data;
|
|
1093
|
-
return {
|
|
1094
|
-
id: d.id,
|
|
1095
|
-
body: d.body,
|
|
1096
|
-
user: this.mapUser(d.user),
|
|
1097
|
-
createdAt: d.created_at,
|
|
1098
|
-
updatedAt: d.updated_at,
|
|
1099
|
-
htmlUrl: d.html_url
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
// actions/createBranch.ts
|
|
1105
|
-
var spec = requireActionSpec("CREATE_BRANCH");
|
|
1106
|
-
var examples = [
|
|
1107
|
-
[
|
|
1108
|
-
{
|
|
1109
|
-
name: "{{user1}}",
|
|
1110
|
-
content: {
|
|
1111
|
-
text: "Create a branch called feature/new-feature from main"
|
|
1112
|
-
}
|
|
1113
|
-
},
|
|
1114
|
-
{
|
|
1115
|
-
name: "{{agent}}",
|
|
1116
|
-
content: {
|
|
1117
|
-
text: "I'll create the feature/new-feature branch from main.",
|
|
1118
|
-
actions: ["CREATE_GITHUB_BRANCH"]
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
],
|
|
1122
|
-
[
|
|
1123
|
-
{
|
|
1124
|
-
name: "{{user1}}",
|
|
1125
|
-
content: {
|
|
1126
|
-
text: "Make a new branch fix/bug-123 based on develop"
|
|
1127
|
-
}
|
|
1128
|
-
},
|
|
1129
|
-
{
|
|
1130
|
-
name: "{{agent}}",
|
|
1131
|
-
content: {
|
|
1132
|
-
text: "Creating branch fix/bug-123 from develop.",
|
|
1133
|
-
actions: ["CREATE_GITHUB_BRANCH"]
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
]
|
|
1137
|
-
];
|
|
1138
|
-
var createBranchAction = {
|
|
1139
|
-
name: "CREATE_GITHUB_BRANCH",
|
|
1140
|
-
similes: spec.similes ? [...spec.similes] : [],
|
|
1141
|
-
description: spec.description,
|
|
1142
|
-
validate: async (runtime, message, state, options) => {
|
|
1143
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
1144
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
1145
|
-
const __avKeywords = ["create", "github", "branch"];
|
|
1146
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
|
|
1147
|
-
const __avRegex = /\b(?:create|github|branch)\b/i;
|
|
1148
|
-
const __avRegexOk = Boolean(__avText.match(__avRegex));
|
|
1149
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
1150
|
-
const __avExpectedSource = "";
|
|
1151
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
|
|
1152
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
1153
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
1154
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
1155
|
-
return false;
|
|
1156
|
-
}
|
|
1157
|
-
const __avLegacyValidate = async (runtime2, message2, _state) => {
|
|
1158
|
-
const service = runtime2.getService(GITHUB_SERVICE_NAME);
|
|
1159
|
-
if (!service) {
|
|
1160
|
-
return false;
|
|
1161
|
-
}
|
|
1162
|
-
const text = message2.content.text?.toLowerCase() ?? "";
|
|
1163
|
-
return text.includes("branch") || text.includes("fork") || text.includes("checkout");
|
|
1164
|
-
};
|
|
1165
|
-
try {
|
|
1166
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1167
|
-
} catch {
|
|
1168
|
-
return false;
|
|
1169
|
-
}
|
|
1170
|
-
},
|
|
1171
|
-
handler: async (runtime, _message, state, _options, callback) => {
|
|
1172
|
-
const service = runtime.getService(GITHUB_SERVICE_NAME);
|
|
1173
|
-
if (!service) {
|
|
1174
|
-
logger2.error("GitHub service not available");
|
|
1175
|
-
if (callback) {
|
|
1176
|
-
await callback({
|
|
1177
|
-
text: "GitHub service is not available. Please ensure the plugin is properly configured."
|
|
1178
|
-
});
|
|
1179
|
-
}
|
|
1180
|
-
return { success: false };
|
|
1181
|
-
}
|
|
1182
|
-
try {
|
|
1183
|
-
const params = {
|
|
1184
|
-
owner: state?.owner ?? service.getConfig().owner ?? "",
|
|
1185
|
-
repo: state?.repo ?? service.getConfig().repo ?? "",
|
|
1186
|
-
branchName: state?.branchName ?? "",
|
|
1187
|
-
fromRef: state?.fromRef ?? service.getConfig().branch ?? "main"
|
|
1188
|
-
};
|
|
1189
|
-
const validation = createBranchSchema.safeParse(params);
|
|
1190
|
-
if (!validation.success) {
|
|
1191
|
-
const errors = formatZodErrors(validation.error);
|
|
1192
|
-
logger2.error(`Invalid branch parameters: ${errors}`);
|
|
1193
|
-
if (callback) {
|
|
1194
|
-
await callback({
|
|
1195
|
-
text: `I couldn't create the branch due to missing information: ${errors}`
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
|
-
return { success: false };
|
|
1199
|
-
}
|
|
1200
|
-
const branch = await service.createBranch(params);
|
|
1201
|
-
logger2.info(`Created branch ${branch.name} from ${params.fromRef}`);
|
|
1202
|
-
if (callback) {
|
|
1203
|
-
await callback({
|
|
1204
|
-
text: `Created branch "${branch.name}" from ${params.fromRef}.
|
|
1205
|
-
|
|
1206
|
-
Latest commit: ${branch.sha.slice(0, 7)}`
|
|
1207
|
-
});
|
|
1208
|
-
}
|
|
1209
|
-
return { success: true };
|
|
1210
|
-
} catch (error) {
|
|
1211
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1212
|
-
logger2.error(`Failed to create branch: ${errorMessage}`);
|
|
1213
|
-
if (callback) {
|
|
1214
|
-
await callback({
|
|
1215
|
-
text: `Failed to create the branch: ${errorMessage}`
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
return { success: false };
|
|
1219
|
-
}
|
|
1220
|
-
},
|
|
1221
|
-
examples
|
|
1222
|
-
};
|
|
1223
|
-
// actions/createComment.ts
|
|
1224
|
-
import {
|
|
1225
|
-
logger as logger3
|
|
1226
|
-
} from "@elizaos/core";
|
|
1227
|
-
var spec2 = requireActionSpec("CREATE_COMMENT");
|
|
1228
|
-
var examples2 = [
|
|
1229
|
-
[
|
|
1230
|
-
{
|
|
1231
|
-
name: "{{user1}}",
|
|
1232
|
-
content: {
|
|
1233
|
-
text: "Comment on issue #42 saying 'I'll take a look at this today'"
|
|
1234
|
-
}
|
|
1235
|
-
},
|
|
1236
|
-
{
|
|
1237
|
-
name: "{{agent}}",
|
|
1238
|
-
content: {
|
|
1239
|
-
text: "I'll add that comment to issue #42.",
|
|
1240
|
-
actions: ["CREATE_GITHUB_COMMENT"]
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
],
|
|
1244
|
-
[
|
|
1245
|
-
{
|
|
1246
|
-
name: "{{user1}}",
|
|
1247
|
-
content: {
|
|
1248
|
-
text: "Reply to PR #15 with 'Thanks for the fix!'"
|
|
1249
|
-
}
|
|
1250
|
-
},
|
|
1251
|
-
{
|
|
1252
|
-
name: "{{agent}}",
|
|
1253
|
-
content: {
|
|
1254
|
-
text: "Adding your comment to pull request #15.",
|
|
1255
|
-
actions: ["CREATE_GITHUB_COMMENT"]
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
]
|
|
1259
|
-
];
|
|
1260
|
-
var createCommentAction = {
|
|
1261
|
-
name: "CREATE_GITHUB_COMMENT",
|
|
1262
|
-
similes: spec2.similes ? [...spec2.similes] : [],
|
|
1263
|
-
description: spec2.description,
|
|
1264
|
-
validate: async (runtime, message, state, options) => {
|
|
1265
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
1266
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
1267
|
-
const __avKeywords = ["create", "github", "comment"];
|
|
1268
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
|
|
1269
|
-
const __avRegex = /\b(?:create|github|comment)\b/i;
|
|
1270
|
-
const __avRegexOk = Boolean(__avText.match(__avRegex));
|
|
1271
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
1272
|
-
const __avExpectedSource = "";
|
|
1273
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
|
|
1274
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
1275
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
1276
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
1277
|
-
return false;
|
|
1278
|
-
}
|
|
1279
|
-
const __avLegacyValidate = async (runtime2, message2, _state) => {
|
|
1280
|
-
const service = runtime2.getService(GITHUB_SERVICE_NAME);
|
|
1281
|
-
if (!service) {
|
|
1282
|
-
return false;
|
|
1283
|
-
}
|
|
1284
|
-
const text = message2.content.text?.toLowerCase() ?? "";
|
|
1285
|
-
return text.includes("comment") || text.includes("reply") || text.includes("respond");
|
|
1286
|
-
};
|
|
1287
|
-
try {
|
|
1288
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1289
|
-
} catch {
|
|
1290
|
-
return false;
|
|
1291
|
-
}
|
|
1292
|
-
},
|
|
1293
|
-
handler: async (runtime, message, state, _options, callback) => {
|
|
1294
|
-
const service = runtime.getService(GITHUB_SERVICE_NAME);
|
|
1295
|
-
if (!service) {
|
|
1296
|
-
logger3.error("GitHub service not available");
|
|
1297
|
-
if (callback) {
|
|
1298
|
-
await callback({
|
|
1299
|
-
text: "GitHub service is not available. Please ensure the plugin is properly configured."
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
return { success: false };
|
|
1303
|
-
}
|
|
1304
|
-
try {
|
|
1305
|
-
const content = message.content;
|
|
1306
|
-
const text = content.text ?? "";
|
|
1307
|
-
const params = {
|
|
1308
|
-
owner: state?.owner ?? service.getConfig().owner ?? "",
|
|
1309
|
-
repo: state?.repo ?? service.getConfig().repo ?? "",
|
|
1310
|
-
issueNumber: state?.issueNumber ?? 0,
|
|
1311
|
-
body: state?.body ?? text
|
|
1312
|
-
};
|
|
1313
|
-
const validation = createCommentSchema.safeParse(params);
|
|
1314
|
-
if (!validation.success) {
|
|
1315
|
-
const errors = formatZodErrors(validation.error);
|
|
1316
|
-
logger3.error(`Invalid comment parameters: ${errors}`);
|
|
1317
|
-
if (callback) {
|
|
1318
|
-
await callback({
|
|
1319
|
-
text: `I couldn't create the comment due to missing information: ${errors}`
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1322
|
-
return { success: false };
|
|
1323
|
-
}
|
|
1324
|
-
const comment = await service.createComment(params);
|
|
1325
|
-
logger3.info(`Created comment on #${params.issueNumber}`);
|
|
1326
|
-
if (callback) {
|
|
1327
|
-
await callback({
|
|
1328
|
-
text: `Added comment to #${params.issueNumber}.
|
|
1329
|
-
|
|
1330
|
-
View it at: ${comment.htmlUrl}`
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
return { success: true };
|
|
1334
|
-
} catch (error) {
|
|
1335
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1336
|
-
logger3.error(`Failed to create comment: ${errorMessage}`);
|
|
1337
|
-
if (callback) {
|
|
1338
|
-
await callback({
|
|
1339
|
-
text: `Failed to create the comment: ${errorMessage}`
|
|
1340
|
-
});
|
|
1341
|
-
}
|
|
1342
|
-
return { success: false };
|
|
1343
|
-
}
|
|
1344
|
-
},
|
|
1345
|
-
examples: examples2
|
|
1346
|
-
};
|
|
1347
|
-
// actions/createIssue.ts
|
|
1348
|
-
import {
|
|
1349
|
-
logger as logger4
|
|
1350
|
-
} from "@elizaos/core";
|
|
1351
|
-
var spec3 = requireActionSpec("CREATE_ISSUE");
|
|
1352
|
-
var examples3 = [
|
|
1353
|
-
[
|
|
1354
|
-
{
|
|
1355
|
-
name: "{{user1}}",
|
|
1356
|
-
content: {
|
|
1357
|
-
text: "Create an issue in my-org/my-repo with title 'Bug: Login fails' and body 'Users cannot log in after update'"
|
|
1358
|
-
}
|
|
1359
|
-
},
|
|
1360
|
-
{
|
|
1361
|
-
name: "{{agent}}",
|
|
1362
|
-
content: {
|
|
1363
|
-
text: "I'll create that issue for you in my-org/my-repo.",
|
|
1364
|
-
actions: ["CREATE_GITHUB_ISSUE"]
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
],
|
|
1368
|
-
[
|
|
1369
|
-
{
|
|
1370
|
-
name: "{{user1}}",
|
|
1371
|
-
content: {
|
|
1372
|
-
text: "Open a new issue titled 'Add dark mode support' with labels 'enhancement' and 'ui'"
|
|
1373
|
-
}
|
|
1374
|
-
},
|
|
1375
|
-
{
|
|
1376
|
-
name: "{{agent}}",
|
|
1377
|
-
content: {
|
|
1378
|
-
text: "Creating a new issue with the title 'Add dark mode support' and the specified labels.",
|
|
1379
|
-
actions: ["CREATE_GITHUB_ISSUE"]
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
]
|
|
1383
|
-
];
|
|
1384
|
-
var createIssueAction = {
|
|
1385
|
-
name: "CREATE_GITHUB_ISSUE",
|
|
1386
|
-
similes: spec3.similes ? [...spec3.similes] : [],
|
|
1387
|
-
description: spec3.description,
|
|
1388
|
-
validate: async (runtime, message, state, options) => {
|
|
1389
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
1390
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
1391
|
-
const __avKeywords = ["create", "github", "issue"];
|
|
1392
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
|
|
1393
|
-
const __avRegex = /\b(?:create|github|issue)\b/i;
|
|
1394
|
-
const __avRegexOk = Boolean(__avText.match(__avRegex));
|
|
1395
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
1396
|
-
const __avExpectedSource = "";
|
|
1397
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
|
|
1398
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
1399
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
1400
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
1401
|
-
return false;
|
|
1402
|
-
}
|
|
1403
|
-
const __avLegacyValidate = async (runtime2, message2, _state) => {
|
|
1404
|
-
const service = runtime2.getService(GITHUB_SERVICE_NAME);
|
|
1405
|
-
if (!service) {
|
|
1406
|
-
return false;
|
|
1407
|
-
}
|
|
1408
|
-
const text = message2.content.text?.toLowerCase() ?? "";
|
|
1409
|
-
return text.includes("issue") || text.includes("bug") || text.includes("report") || text.includes("ticket");
|
|
1410
|
-
};
|
|
1411
|
-
try {
|
|
1412
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1413
|
-
} catch {
|
|
1414
|
-
return false;
|
|
1415
|
-
}
|
|
1416
|
-
},
|
|
1417
|
-
handler: async (runtime, message, state, _options, callback) => {
|
|
1418
|
-
const service = runtime.getService(GITHUB_SERVICE_NAME);
|
|
1419
|
-
if (!service) {
|
|
1420
|
-
logger4.error("GitHub service not available");
|
|
1421
|
-
if (callback) {
|
|
1422
|
-
await callback({
|
|
1423
|
-
text: "GitHub service is not available. Please ensure the plugin is properly configured."
|
|
1424
|
-
});
|
|
1425
|
-
}
|
|
1426
|
-
return { success: false };
|
|
1427
|
-
}
|
|
1428
|
-
try {
|
|
1429
|
-
const content = message.content;
|
|
1430
|
-
const text = content.text ?? "";
|
|
1431
|
-
const params = {
|
|
1432
|
-
owner: state?.owner ?? service.getConfig().owner ?? "",
|
|
1433
|
-
repo: state?.repo ?? service.getConfig().repo ?? "",
|
|
1434
|
-
title: state?.title ?? text.slice(0, 100),
|
|
1435
|
-
body: state?.body ?? text,
|
|
1436
|
-
labels: state?.labels ?? [],
|
|
1437
|
-
assignees: state?.assignees ?? []
|
|
1438
|
-
};
|
|
1439
|
-
const validation = createIssueSchema.safeParse(params);
|
|
1440
|
-
if (!validation.success) {
|
|
1441
|
-
const errors = formatZodErrors(validation.error);
|
|
1442
|
-
logger4.error(`Invalid issue parameters: ${errors}`);
|
|
1443
|
-
if (callback) {
|
|
1444
|
-
await callback({
|
|
1445
|
-
text: `I couldn't create the issue due to missing information: ${errors}`
|
|
1446
|
-
});
|
|
1447
|
-
}
|
|
1448
|
-
return { success: false };
|
|
1449
|
-
}
|
|
1450
|
-
const issue = await service.createIssue(params);
|
|
1451
|
-
logger4.info(`Created issue #${issue.number}: ${issue.title}`);
|
|
1452
|
-
if (callback) {
|
|
1453
|
-
await callback({
|
|
1454
|
-
text: `Created issue #${issue.number}: "${issue.title}"
|
|
1455
|
-
|
|
1456
|
-
View it at: ${issue.htmlUrl}`
|
|
1457
|
-
});
|
|
1458
|
-
}
|
|
1459
|
-
return { success: true };
|
|
1460
|
-
} catch (error) {
|
|
1461
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1462
|
-
logger4.error(`Failed to create issue: ${errorMessage}`);
|
|
1463
|
-
if (callback) {
|
|
1464
|
-
await callback({
|
|
1465
|
-
text: `Failed to create the issue: ${errorMessage}`
|
|
1466
|
-
});
|
|
1467
|
-
}
|
|
1468
|
-
return { success: false };
|
|
1469
|
-
}
|
|
1470
|
-
},
|
|
1471
|
-
examples: examples3
|
|
1472
|
-
};
|
|
1473
|
-
// actions/createPullRequest.ts
|
|
1474
|
-
import {
|
|
1475
|
-
logger as logger5
|
|
1476
|
-
} from "@elizaos/core";
|
|
1477
|
-
var spec4 = requireActionSpec("CREATE_PULL_REQUEST");
|
|
1478
|
-
var examples4 = [
|
|
1479
|
-
[
|
|
1480
|
-
{
|
|
1481
|
-
name: spec4.name,
|
|
1482
|
-
content: {
|
|
1483
|
-
text: "Create a pull request from feature/dark-mode to main with title 'Add dark mode support'"
|
|
1484
|
-
}
|
|
1485
|
-
},
|
|
1486
|
-
{
|
|
1487
|
-
name: "{{agent}}",
|
|
1488
|
-
content: {
|
|
1489
|
-
text: "I'll create a pull request from feature/dark-mode to main.",
|
|
1490
|
-
actions: ["CREATE_GITHUB_PULL_REQUEST"]
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
],
|
|
1494
|
-
[
|
|
1495
|
-
{
|
|
1496
|
-
name: "{{user1}}",
|
|
1497
|
-
content: {
|
|
1498
|
-
text: "Open a PR to merge my-branch into develop"
|
|
1499
|
-
}
|
|
1500
|
-
},
|
|
1501
|
-
{
|
|
1502
|
-
name: "{{agent}}",
|
|
1503
|
-
content: {
|
|
1504
|
-
text: "Creating a pull request to merge my-branch into develop.",
|
|
1505
|
-
actions: ["CREATE_GITHUB_PULL_REQUEST"]
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
]
|
|
1509
|
-
];
|
|
1510
|
-
var createPullRequestAction = {
|
|
1511
|
-
name: "CREATE_GITHUB_PULL_REQUEST",
|
|
1512
|
-
similes: spec4.similes ? [...spec4.similes] : [],
|
|
1513
|
-
description: spec4.description,
|
|
1514
|
-
validate: async (runtime, message, state, options) => {
|
|
1515
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
1516
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
1517
|
-
const __avKeywords = ["create", "github", "pull", "request"];
|
|
1518
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
|
|
1519
|
-
const __avRegex = /\b(?:create|github|pull|request)\b/i;
|
|
1520
|
-
const __avRegexOk = Boolean(__avText.match(__avRegex));
|
|
1521
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
1522
|
-
const __avExpectedSource = "";
|
|
1523
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
|
|
1524
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
1525
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
1526
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
1527
|
-
return false;
|
|
1528
|
-
}
|
|
1529
|
-
const __avLegacyValidate = async (runtime2, message2, _state) => {
|
|
1530
|
-
const service = runtime2.getService(GITHUB_SERVICE_NAME);
|
|
1531
|
-
if (!service) {
|
|
1532
|
-
return false;
|
|
1533
|
-
}
|
|
1534
|
-
const text = message2.content.text?.toLowerCase() ?? "";
|
|
1535
|
-
return text.includes("pull request") || text.includes("pr") || text.includes("merge");
|
|
1536
|
-
};
|
|
1537
|
-
try {
|
|
1538
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1539
|
-
} catch {
|
|
1540
|
-
return false;
|
|
1541
|
-
}
|
|
1542
|
-
},
|
|
1543
|
-
handler: async (runtime, message, state, _options, callback) => {
|
|
1544
|
-
const service = runtime.getService(GITHUB_SERVICE_NAME);
|
|
1545
|
-
if (!service) {
|
|
1546
|
-
logger5.error("GitHub service not available");
|
|
1547
|
-
if (callback) {
|
|
1548
|
-
await callback({
|
|
1549
|
-
text: "GitHub service is not available. Please ensure the plugin is properly configured."
|
|
1550
|
-
});
|
|
1551
|
-
}
|
|
1552
|
-
return { success: false };
|
|
1553
|
-
}
|
|
1554
|
-
try {
|
|
1555
|
-
const content = message.content;
|
|
1556
|
-
const text = content.text ?? "";
|
|
1557
|
-
const params = {
|
|
1558
|
-
owner: state?.owner ?? service.getConfig().owner ?? "",
|
|
1559
|
-
repo: state?.repo ?? service.getConfig().repo ?? "",
|
|
1560
|
-
title: state?.title ?? text.slice(0, 100),
|
|
1561
|
-
body: state?.body ?? text,
|
|
1562
|
-
head: state?.head ?? "",
|
|
1563
|
-
base: state?.base ?? service.getConfig().branch ?? "main",
|
|
1564
|
-
draft: state?.draft ?? false
|
|
1565
|
-
};
|
|
1566
|
-
const validation = createPullRequestSchema.safeParse(params);
|
|
1567
|
-
if (!validation.success) {
|
|
1568
|
-
const errors = formatZodErrors(validation.error);
|
|
1569
|
-
logger5.error(`Invalid pull request parameters: ${errors}`);
|
|
1570
|
-
if (callback) {
|
|
1571
|
-
await callback({
|
|
1572
|
-
text: `I couldn't create the pull request due to missing information: ${errors}`
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
return { success: false };
|
|
1576
|
-
}
|
|
1577
|
-
const pr = await service.createPullRequest(params);
|
|
1578
|
-
logger5.info(`Created pull request #${pr.number}: ${pr.title}`);
|
|
1579
|
-
if (callback) {
|
|
1580
|
-
await callback({
|
|
1581
|
-
text: `Created pull request #${pr.number}: "${pr.title}"
|
|
1582
|
-
|
|
1583
|
-
From: ${pr.head.ref}
|
|
1584
|
-
To: ${pr.base.ref}
|
|
1585
|
-
|
|
1586
|
-
View it at: ${pr.htmlUrl}`
|
|
1587
|
-
});
|
|
1588
|
-
}
|
|
1589
|
-
return { success: true };
|
|
1590
|
-
} catch (error) {
|
|
1591
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1592
|
-
logger5.error(`Failed to create pull request: ${errorMessage}`);
|
|
1593
|
-
if (callback) {
|
|
1594
|
-
await callback({
|
|
1595
|
-
text: `Failed to create the pull request: ${errorMessage}`
|
|
1596
|
-
});
|
|
1597
|
-
}
|
|
1598
|
-
return { success: false };
|
|
1599
|
-
}
|
|
1600
|
-
},
|
|
1601
|
-
examples: examples4
|
|
1602
|
-
};
|
|
1603
|
-
// actions/mergePullRequest.ts
|
|
1604
|
-
import {
|
|
1605
|
-
logger as logger6
|
|
1606
|
-
} from "@elizaos/core";
|
|
1607
|
-
var spec5 = requireActionSpec("MERGE_PULL_REQUEST");
|
|
1608
|
-
var examples5 = [
|
|
1609
|
-
[
|
|
1610
|
-
{
|
|
1611
|
-
name: spec5.name,
|
|
1612
|
-
content: {
|
|
1613
|
-
text: "Merge pull request #42"
|
|
1614
|
-
}
|
|
1615
|
-
},
|
|
1616
|
-
{
|
|
1617
|
-
name: "{{agent}}",
|
|
1618
|
-
content: {
|
|
1619
|
-
text: "I'll merge pull request #42.",
|
|
1620
|
-
actions: ["MERGE_GITHUB_PULL_REQUEST"]
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
],
|
|
1624
|
-
[
|
|
1625
|
-
{
|
|
1626
|
-
name: "{{user1}}",
|
|
1627
|
-
content: {
|
|
1628
|
-
text: "Squash and merge PR #15 with title 'Feature: Add dark mode'"
|
|
1629
|
-
}
|
|
1630
|
-
},
|
|
1631
|
-
{
|
|
1632
|
-
name: "{{agent}}",
|
|
1633
|
-
content: {
|
|
1634
|
-
text: "Squash merging pull request #15 with your custom commit title.",
|
|
1635
|
-
actions: ["MERGE_GITHUB_PULL_REQUEST"]
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
]
|
|
1639
|
-
];
|
|
1640
|
-
var mergePullRequestAction = {
|
|
1641
|
-
name: "MERGE_GITHUB_PULL_REQUEST",
|
|
1642
|
-
similes: spec5.similes ? [...spec5.similes] : [],
|
|
1643
|
-
description: spec5.description,
|
|
1644
|
-
validate: async (runtime, message, state, options) => {
|
|
1645
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
1646
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
1647
|
-
const __avKeywords = ["merge", "github", "pull", "request"];
|
|
1648
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
|
|
1649
|
-
const __avRegex = /\b(?:merge|github|pull|request)\b/i;
|
|
1650
|
-
const __avRegexOk = Boolean(__avText.match(__avRegex));
|
|
1651
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
1652
|
-
const __avExpectedSource = "";
|
|
1653
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
|
|
1654
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
1655
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
1656
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
1657
|
-
return false;
|
|
1658
|
-
}
|
|
1659
|
-
const __avLegacyValidate = async (runtime2, message2, _state) => {
|
|
1660
|
-
const service = runtime2.getService(GITHUB_SERVICE_NAME);
|
|
1661
|
-
if (!service) {
|
|
1662
|
-
return false;
|
|
1663
|
-
}
|
|
1664
|
-
const text = message2.content.text?.toLowerCase() ?? "";
|
|
1665
|
-
return text.includes("merge");
|
|
1666
|
-
};
|
|
1667
|
-
try {
|
|
1668
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1669
|
-
} catch {
|
|
1670
|
-
return false;
|
|
1671
|
-
}
|
|
1672
|
-
},
|
|
1673
|
-
handler: async (runtime, message, state, _options, callback) => {
|
|
1674
|
-
const service = runtime.getService(GITHUB_SERVICE_NAME);
|
|
1675
|
-
if (!service) {
|
|
1676
|
-
logger6.error("GitHub service not available");
|
|
1677
|
-
if (callback) {
|
|
1678
|
-
await callback({
|
|
1679
|
-
text: "GitHub service is not available. Please ensure the plugin is properly configured."
|
|
1680
|
-
});
|
|
1681
|
-
}
|
|
1682
|
-
return { success: false };
|
|
1683
|
-
}
|
|
1684
|
-
try {
|
|
1685
|
-
const content = message.content;
|
|
1686
|
-
const text = content.text?.toLowerCase() ?? "";
|
|
1687
|
-
let mergeMethod = "merge";
|
|
1688
|
-
if (text.includes("squash")) {
|
|
1689
|
-
mergeMethod = "squash";
|
|
1690
|
-
} else if (text.includes("rebase")) {
|
|
1691
|
-
mergeMethod = "rebase";
|
|
1692
|
-
}
|
|
1693
|
-
const params = {
|
|
1694
|
-
owner: state?.owner ?? service.getConfig().owner ?? "",
|
|
1695
|
-
repo: state?.repo ?? service.getConfig().repo ?? "",
|
|
1696
|
-
pullNumber: state?.pullNumber ?? 0,
|
|
1697
|
-
commitTitle: state?.commitTitle,
|
|
1698
|
-
commitMessage: state?.commitMessage,
|
|
1699
|
-
mergeMethod: state?.mergeMethod ?? mergeMethod
|
|
1700
|
-
};
|
|
1701
|
-
const validation = mergePullRequestSchema.safeParse(params);
|
|
1702
|
-
if (!validation.success) {
|
|
1703
|
-
const errors = formatZodErrors(validation.error);
|
|
1704
|
-
logger6.error(`Invalid merge parameters: ${errors}`);
|
|
1705
|
-
if (callback) {
|
|
1706
|
-
await callback({
|
|
1707
|
-
text: `I couldn't merge the pull request due to missing information: ${errors}`
|
|
1708
|
-
});
|
|
1709
|
-
}
|
|
1710
|
-
return { success: false };
|
|
1711
|
-
}
|
|
1712
|
-
const result = await service.mergePullRequest(params);
|
|
1713
|
-
if (result.merged) {
|
|
1714
|
-
logger6.info(`Merged pull request #${params.pullNumber}`);
|
|
1715
|
-
if (callback) {
|
|
1716
|
-
await callback({
|
|
1717
|
-
text: `Successfully merged pull request #${params.pullNumber}.
|
|
1718
|
-
|
|
1719
|
-
Merge commit: ${result.sha.slice(0, 7)}
|
|
1720
|
-
Method: ${params.mergeMethod}`
|
|
1721
|
-
});
|
|
1722
|
-
}
|
|
1723
|
-
return { success: true };
|
|
1724
|
-
} else {
|
|
1725
|
-
logger6.warn(`Pull request #${params.pullNumber} was not merged: ${result.message}`);
|
|
1726
|
-
if (callback) {
|
|
1727
|
-
await callback({
|
|
1728
|
-
text: `Could not merge pull request #${params.pullNumber}: ${result.message}`
|
|
1729
|
-
});
|
|
1730
|
-
}
|
|
1731
|
-
return { success: false };
|
|
1732
|
-
}
|
|
1733
|
-
} catch (error) {
|
|
1734
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1735
|
-
logger6.error(`Failed to merge pull request: ${errorMessage}`);
|
|
1736
|
-
if (callback) {
|
|
1737
|
-
await callback({
|
|
1738
|
-
text: `Failed to merge the pull request: ${errorMessage}`
|
|
1739
|
-
});
|
|
1740
|
-
}
|
|
1741
|
-
return { success: false };
|
|
1742
|
-
}
|
|
1743
|
-
},
|
|
1744
|
-
examples: examples5
|
|
1745
|
-
};
|
|
1746
|
-
// actions/pushCode.ts
|
|
1747
|
-
import {
|
|
1748
|
-
logger as logger7
|
|
1749
|
-
} from "@elizaos/core";
|
|
1750
|
-
var spec6 = requireActionSpec("PUSH_CODE");
|
|
1751
|
-
var examples6 = [
|
|
1752
|
-
[
|
|
1753
|
-
{
|
|
1754
|
-
name: spec6.name,
|
|
1755
|
-
content: {
|
|
1756
|
-
text: "Push the file changes to the feature/dark-mode branch with message 'Add dark mode styles'"
|
|
1757
|
-
}
|
|
1758
|
-
},
|
|
1759
|
-
{
|
|
1760
|
-
name: "{{agent}}",
|
|
1761
|
-
content: {
|
|
1762
|
-
text: "I'll commit and push those changes to feature/dark-mode.",
|
|
1763
|
-
actions: ["PUSH_GITHUB_CODE"]
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
],
|
|
1767
|
-
[
|
|
1768
|
-
{
|
|
1769
|
-
name: "{{user1}}",
|
|
1770
|
-
content: {
|
|
1771
|
-
text: "Commit these files to main: README.md with content 'Hello World'"
|
|
1772
|
-
}
|
|
1773
|
-
},
|
|
1774
|
-
{
|
|
1775
|
-
name: "{{agent}}",
|
|
1776
|
-
content: {
|
|
1777
|
-
text: "Committing README.md to main branch.",
|
|
1778
|
-
actions: ["PUSH_GITHUB_CODE"]
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
]
|
|
1782
|
-
];
|
|
1783
|
-
var pushCodeAction = {
|
|
1784
|
-
name: "PUSH_GITHUB_CODE",
|
|
1785
|
-
similes: spec6.similes ? [...spec6.similes] : [],
|
|
1786
|
-
description: spec6.description,
|
|
1787
|
-
validate: async (runtime, message, state, options) => {
|
|
1788
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
1789
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
1790
|
-
const __avKeywords = ["push", "github", "code"];
|
|
1791
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
|
|
1792
|
-
const __avRegex = /\b(?:push|github|code)\b/i;
|
|
1793
|
-
const __avRegexOk = Boolean(__avText.match(__avRegex));
|
|
1794
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
1795
|
-
const __avExpectedSource = "";
|
|
1796
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
|
|
1797
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
1798
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
1799
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
1800
|
-
return false;
|
|
1801
|
-
}
|
|
1802
|
-
const __avLegacyValidate = async (runtime2, message2, _state) => {
|
|
1803
|
-
const service = runtime2.getService(GITHUB_SERVICE_NAME);
|
|
1804
|
-
if (!service) {
|
|
1805
|
-
return false;
|
|
1806
|
-
}
|
|
1807
|
-
const text = message2.content.text?.toLowerCase() ?? "";
|
|
1808
|
-
return text.includes("push") || text.includes("commit") || text.includes("save") || text.includes("upload");
|
|
1809
|
-
};
|
|
1810
|
-
try {
|
|
1811
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1812
|
-
} catch {
|
|
1813
|
-
return false;
|
|
1814
|
-
}
|
|
1815
|
-
},
|
|
1816
|
-
handler: async (runtime, message, state, _options, callback) => {
|
|
1817
|
-
const service = runtime.getService(GITHUB_SERVICE_NAME);
|
|
1818
|
-
if (!service) {
|
|
1819
|
-
logger7.error("GitHub service not available");
|
|
1820
|
-
if (callback) {
|
|
1821
|
-
await callback({
|
|
1822
|
-
text: "GitHub service is not available. Please ensure the plugin is properly configured."
|
|
1823
|
-
});
|
|
1824
|
-
}
|
|
1825
|
-
return { success: false };
|
|
1826
|
-
}
|
|
1827
|
-
try {
|
|
1828
|
-
const content = message.content;
|
|
1829
|
-
const text = content.text ?? "";
|
|
1830
|
-
const files = state?.files ?? [];
|
|
1831
|
-
const params = {
|
|
1832
|
-
owner: state?.owner ?? service.getConfig().owner ?? "",
|
|
1833
|
-
repo: state?.repo ?? service.getConfig().repo ?? "",
|
|
1834
|
-
message: state?.message ?? text.slice(0, 100),
|
|
1835
|
-
files,
|
|
1836
|
-
branch: state?.branch ?? service.getConfig().branch ?? "main",
|
|
1837
|
-
authorName: state?.authorName,
|
|
1838
|
-
authorEmail: state?.authorEmail
|
|
1839
|
-
};
|
|
1840
|
-
const validation = createCommitSchema.safeParse(params);
|
|
1841
|
-
if (!validation.success) {
|
|
1842
|
-
const errors = formatZodErrors(validation.error);
|
|
1843
|
-
logger7.error(`Invalid commit parameters: ${errors}`);
|
|
1844
|
-
if (callback) {
|
|
1845
|
-
await callback({
|
|
1846
|
-
text: `I couldn't push the code due to missing information: ${errors}`
|
|
1847
|
-
});
|
|
1848
|
-
}
|
|
1849
|
-
return { success: false };
|
|
1850
|
-
}
|
|
1851
|
-
const commit = await service.createCommit(params);
|
|
1852
|
-
logger7.info(`Created commit ${commit.sha.slice(0, 7)} on ${params.branch}`);
|
|
1853
|
-
if (callback) {
|
|
1854
|
-
await callback({
|
|
1855
|
-
text: `Pushed ${files.length} file(s) to ${params.branch}.
|
|
1856
|
-
|
|
1857
|
-
Commit: ${commit.sha.slice(0, 7)}
|
|
1858
|
-
Message: ${commit.message}
|
|
1859
|
-
|
|
1860
|
-
View at: ${commit.htmlUrl}`
|
|
1861
|
-
});
|
|
1862
|
-
}
|
|
1863
|
-
return { success: true };
|
|
1864
|
-
} catch (error) {
|
|
1865
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1866
|
-
logger7.error(`Failed to push code: ${errorMessage}`);
|
|
1867
|
-
if (callback) {
|
|
1868
|
-
await callback({
|
|
1869
|
-
text: `Failed to push the code: ${errorMessage}`
|
|
1870
|
-
});
|
|
1871
|
-
}
|
|
1872
|
-
return { success: false };
|
|
1873
|
-
}
|
|
1874
|
-
},
|
|
1875
|
-
examples: examples6
|
|
1876
|
-
};
|
|
1877
|
-
// actions/reviewPullRequest.ts
|
|
1878
|
-
import {
|
|
1879
|
-
logger as logger8
|
|
1880
|
-
} from "@elizaos/core";
|
|
1881
|
-
var spec7 = requireActionSpec("REVIEW_PULL_REQUEST");
|
|
1882
|
-
var examples7 = [
|
|
1883
|
-
[
|
|
1884
|
-
{
|
|
1885
|
-
name: spec7.name,
|
|
1886
|
-
content: {
|
|
1887
|
-
text: "Approve pull request #42 with comment 'LGTM!'"
|
|
1888
|
-
}
|
|
1889
|
-
},
|
|
1890
|
-
{
|
|
1891
|
-
name: "{{agent}}",
|
|
1892
|
-
content: {
|
|
1893
|
-
text: "I'll approve pull request #42 with that comment.",
|
|
1894
|
-
actions: ["REVIEW_GITHUB_PULL_REQUEST"]
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
],
|
|
1898
|
-
[
|
|
1899
|
-
{
|
|
1900
|
-
name: "{{user1}}",
|
|
1901
|
-
content: {
|
|
1902
|
-
text: "Request changes on PR #15 - the tests are failing"
|
|
1903
|
-
}
|
|
1904
|
-
},
|
|
1905
|
-
{
|
|
1906
|
-
name: "{{agent}}",
|
|
1907
|
-
content: {
|
|
1908
|
-
text: "I'll request changes on pull request #15 with your feedback.",
|
|
1909
|
-
actions: ["REVIEW_GITHUB_PULL_REQUEST"]
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
]
|
|
1913
|
-
];
|
|
1914
|
-
var reviewPullRequestAction = {
|
|
1915
|
-
name: "REVIEW_GITHUB_PULL_REQUEST",
|
|
1916
|
-
similes: spec7.similes ? [...spec7.similes] : [],
|
|
1917
|
-
description: spec7.description,
|
|
1918
|
-
validate: async (runtime, message, state, options) => {
|
|
1919
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
1920
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
1921
|
-
const __avKeywords = ["review", "github", "pull", "request"];
|
|
1922
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
|
|
1923
|
-
const __avRegex = /\b(?:review|github|pull|request)\b/i;
|
|
1924
|
-
const __avRegexOk = Boolean(__avText.match(__avRegex));
|
|
1925
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
1926
|
-
const __avExpectedSource = "";
|
|
1927
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
|
|
1928
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
1929
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
1930
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
1931
|
-
return false;
|
|
1932
|
-
}
|
|
1933
|
-
const __avLegacyValidate = async (runtime2, message2, _state) => {
|
|
1934
|
-
const service = runtime2.getService(GITHUB_SERVICE_NAME);
|
|
1935
|
-
if (!service) {
|
|
1936
|
-
return false;
|
|
1937
|
-
}
|
|
1938
|
-
const text = message2.content.text?.toLowerCase() ?? "";
|
|
1939
|
-
return text.includes("review") || text.includes("approve") || text.includes("request changes") || text.includes("lgtm");
|
|
1940
|
-
};
|
|
1941
|
-
try {
|
|
1942
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1943
|
-
} catch {
|
|
1944
|
-
return false;
|
|
1945
|
-
}
|
|
1946
|
-
},
|
|
1947
|
-
handler: async (runtime, message, state, _options, callback) => {
|
|
1948
|
-
const service = runtime.getService(GITHUB_SERVICE_NAME);
|
|
1949
|
-
if (!service) {
|
|
1950
|
-
logger8.error("GitHub service not available");
|
|
1951
|
-
if (callback) {
|
|
1952
|
-
await callback({
|
|
1953
|
-
text: "GitHub service is not available. Please ensure the plugin is properly configured."
|
|
1954
|
-
});
|
|
1955
|
-
}
|
|
1956
|
-
return { success: false };
|
|
1957
|
-
}
|
|
1958
|
-
try {
|
|
1959
|
-
const content = message.content;
|
|
1960
|
-
const text = content.text ?? "";
|
|
1961
|
-
let event = "COMMENT";
|
|
1962
|
-
const lowerText = text.toLowerCase();
|
|
1963
|
-
if (lowerText.includes("approve") || lowerText.includes("lgtm") || lowerText.includes("looks good")) {
|
|
1964
|
-
event = "APPROVE";
|
|
1965
|
-
} else if (lowerText.includes("request changes") || lowerText.includes("needs work") || lowerText.includes("fix")) {
|
|
1966
|
-
event = "REQUEST_CHANGES";
|
|
1967
|
-
}
|
|
1968
|
-
const params = {
|
|
1969
|
-
owner: state?.owner ?? service.getConfig().owner ?? "",
|
|
1970
|
-
repo: state?.repo ?? service.getConfig().repo ?? "",
|
|
1971
|
-
pullNumber: state?.pullNumber ?? 0,
|
|
1972
|
-
body: state?.body ?? text,
|
|
1973
|
-
event: state?.event ?? event
|
|
1974
|
-
};
|
|
1975
|
-
const validation = createReviewSchema.safeParse(params);
|
|
1976
|
-
if (!validation.success) {
|
|
1977
|
-
const errors = formatZodErrors(validation.error);
|
|
1978
|
-
logger8.error(`Invalid review parameters: ${errors}`);
|
|
1979
|
-
if (callback) {
|
|
1980
|
-
await callback({
|
|
1981
|
-
text: `I couldn't create the review due to missing information: ${errors}`
|
|
1982
|
-
});
|
|
1983
|
-
}
|
|
1984
|
-
return { success: false };
|
|
1985
|
-
}
|
|
1986
|
-
const review = await service.createReview(params);
|
|
1987
|
-
const eventLabel = review.state === "APPROVED" ? "approved" : review.state === "CHANGES_REQUESTED" ? "requested changes on" : "commented on";
|
|
1988
|
-
logger8.info(`Created ${review.state} review on PR #${params.pullNumber}`);
|
|
1989
|
-
if (callback) {
|
|
1990
|
-
await callback({
|
|
1991
|
-
text: `I've ${eventLabel} pull request #${params.pullNumber}.
|
|
1992
|
-
|
|
1993
|
-
View the review at: ${review.htmlUrl}`
|
|
1994
|
-
});
|
|
1995
|
-
}
|
|
1996
|
-
return { success: true };
|
|
1997
|
-
} catch (error) {
|
|
1998
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1999
|
-
logger8.error(`Failed to create review: ${errorMessage}`);
|
|
2000
|
-
if (callback) {
|
|
2001
|
-
await callback({
|
|
2002
|
-
text: `Failed to create the review: ${errorMessage}`
|
|
2003
|
-
});
|
|
2004
|
-
}
|
|
2005
|
-
return { success: false };
|
|
2006
|
-
}
|
|
2007
|
-
},
|
|
2008
|
-
examples: examples7
|
|
2009
|
-
};
|
|
2010
|
-
// actions/index.ts
|
|
2011
|
-
var allActions = [
|
|
2012
|
-
createIssueAction,
|
|
2013
|
-
createPullRequestAction,
|
|
2014
|
-
reviewPullRequestAction,
|
|
2015
|
-
createCommentAction,
|
|
2016
|
-
createBranchAction,
|
|
2017
|
-
pushCodeAction,
|
|
2018
|
-
mergePullRequestAction
|
|
2019
|
-
];
|
|
2020
|
-
|
|
2021
|
-
// providers/issueContext.ts
|
|
2022
|
-
function extractIssueNumber(text) {
|
|
2023
|
-
const patterns = [/#(\d+)/, /issue\s*#?(\d+)/i, /pr\s*#?(\d+)/i, /pull\s*request\s*#?(\d+)/i];
|
|
2024
|
-
for (const pattern of patterns) {
|
|
2025
|
-
const match = text.match(pattern);
|
|
2026
|
-
if (match?.[1]) {
|
|
2027
|
-
return Number.parseInt(match[1], 10);
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
return null;
|
|
2031
|
-
}
|
|
2032
|
-
var spec8 = requireProviderSpec("issueContext");
|
|
2033
|
-
var issueContextProvider = {
|
|
2034
|
-
name: spec8.name,
|
|
2035
|
-
description: "Provides detailed context about a specific GitHub issue or pull request when referenced",
|
|
2036
|
-
dynamic: true,
|
|
2037
|
-
get: async (runtime, message, _state) => {
|
|
2038
|
-
const service = runtime.getService(GITHUB_SERVICE_NAME);
|
|
2039
|
-
if (!service) {
|
|
2040
|
-
return { text: null };
|
|
2041
|
-
}
|
|
2042
|
-
const text = message.content.text ?? "";
|
|
2043
|
-
const issueNumber = extractIssueNumber(text);
|
|
2044
|
-
if (!issueNumber) {
|
|
2045
|
-
return { text: null };
|
|
2046
|
-
}
|
|
2047
|
-
try {
|
|
2048
|
-
const config = service.getConfig();
|
|
2049
|
-
if (!config.owner || !config.repo) {
|
|
2050
|
-
return { text: null };
|
|
2051
|
-
}
|
|
2052
|
-
try {
|
|
2053
|
-
const issue = await service.getIssue({
|
|
2054
|
-
owner: config.owner,
|
|
2055
|
-
repo: config.repo,
|
|
2056
|
-
issueNumber
|
|
2057
|
-
});
|
|
2058
|
-
if (issue.isPullRequest) {
|
|
2059
|
-
const pr = await service.getPullRequest({
|
|
2060
|
-
owner: config.owner,
|
|
2061
|
-
repo: config.repo,
|
|
2062
|
-
pullNumber: issueNumber
|
|
2063
|
-
});
|
|
2064
|
-
const labels2 = pr.labels.map((l) => l.name).join(", ");
|
|
2065
|
-
const assignees2 = pr.assignees.map((a) => a.login).join(", ");
|
|
2066
|
-
const reviewers = pr.requestedReviewers.map((r) => r.login).join(", ");
|
|
2067
|
-
const parts2 = [
|
|
2068
|
-
`## Pull Request #${pr.number}: ${pr.title}`,
|
|
2069
|
-
"",
|
|
2070
|
-
`**State:** ${pr.state}${pr.draft ? " (Draft)" : ""}${pr.merged ? " (Merged)" : ""}`,
|
|
2071
|
-
`**Author:** ${pr.user.login}`,
|
|
2072
|
-
`**Branch:** ${pr.head.ref} → ${pr.base.ref}`,
|
|
2073
|
-
`**Created:** ${pr.createdAt}`,
|
|
2074
|
-
`**Updated:** ${pr.updatedAt}`
|
|
2075
|
-
];
|
|
2076
|
-
if (labels2) {
|
|
2077
|
-
parts2.push(`**Labels:** ${labels2}`);
|
|
2078
|
-
}
|
|
2079
|
-
if (assignees2) {
|
|
2080
|
-
parts2.push(`**Assignees:** ${assignees2}`);
|
|
2081
|
-
}
|
|
2082
|
-
if (reviewers) {
|
|
2083
|
-
parts2.push(`**Reviewers Requested:** ${reviewers}`);
|
|
2084
|
-
}
|
|
2085
|
-
parts2.push("", `**Changes:** +${pr.additions} / -${pr.deletions} (${pr.changedFiles} files)`, "", "### Description", pr.body ?? "_No description provided_", "", `**URL:** ${pr.htmlUrl}`);
|
|
2086
|
-
return { text: parts2.join(`
|
|
2087
|
-
`) };
|
|
2088
|
-
}
|
|
2089
|
-
const labels = issue.labels.map((l) => l.name).join(", ");
|
|
2090
|
-
const assignees = issue.assignees.map((a) => a.login).join(", ");
|
|
2091
|
-
const parts = [
|
|
2092
|
-
`## Issue #${issue.number}: ${issue.title}`,
|
|
2093
|
-
"",
|
|
2094
|
-
`**State:** ${issue.state}${issue.stateReason ? ` (${issue.stateReason})` : ""}`,
|
|
2095
|
-
`**Author:** ${issue.user.login}`,
|
|
2096
|
-
`**Created:** ${issue.createdAt}`,
|
|
2097
|
-
`**Updated:** ${issue.updatedAt}`,
|
|
2098
|
-
`**Comments:** ${issue.comments}`
|
|
2099
|
-
];
|
|
2100
|
-
if (labels) {
|
|
2101
|
-
parts.push(`**Labels:** ${labels}`);
|
|
2102
|
-
}
|
|
2103
|
-
if (assignees) {
|
|
2104
|
-
parts.push(`**Assignees:** ${assignees}`);
|
|
2105
|
-
}
|
|
2106
|
-
if (issue.milestone) {
|
|
2107
|
-
parts.push(`**Milestone:** ${issue.milestone.title}`);
|
|
2108
|
-
}
|
|
2109
|
-
parts.push("", "### Description", issue.body ?? "_No description provided_", "", `**URL:** ${issue.htmlUrl}`);
|
|
2110
|
-
return { text: parts.join(`
|
|
2111
|
-
`) };
|
|
2112
|
-
} catch {
|
|
2113
|
-
return {
|
|
2114
|
-
text: `Issue/PR #${issueNumber} not found in ${config.owner}/${config.repo}`
|
|
2115
|
-
};
|
|
2116
|
-
}
|
|
2117
|
-
} catch (error) {
|
|
2118
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
2119
|
-
return { text: `Unable to fetch issue context: ${errorMessage}` };
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
};
|
|
2123
|
-
// providers/repositoryState.ts
|
|
2124
|
-
var spec9 = requireProviderSpec("repositoryState");
|
|
2125
|
-
var repositoryStateProvider = {
|
|
2126
|
-
name: spec9.name,
|
|
2127
|
-
description: "Provides context about the current GitHub repository including recent activity",
|
|
2128
|
-
dynamic: true,
|
|
2129
|
-
get: async (runtime, _message, _state) => {
|
|
2130
|
-
const service = runtime.getService(GITHUB_SERVICE_NAME);
|
|
2131
|
-
if (!service) {
|
|
2132
|
-
return { text: null };
|
|
2133
|
-
}
|
|
2134
|
-
try {
|
|
2135
|
-
const config = service.getConfig();
|
|
2136
|
-
if (!config.owner || !config.repo) {
|
|
2137
|
-
return {
|
|
2138
|
-
text: "GitHub repository not configured. Please set GITHUB_OWNER and GITHUB_REPO."
|
|
2139
|
-
};
|
|
2140
|
-
}
|
|
2141
|
-
const repo = await service.getRepository({
|
|
2142
|
-
owner: config.owner,
|
|
2143
|
-
repo: config.repo
|
|
2144
|
-
});
|
|
2145
|
-
const issues = await service.listIssues({
|
|
2146
|
-
owner: config.owner,
|
|
2147
|
-
repo: config.repo,
|
|
2148
|
-
state: "open",
|
|
2149
|
-
perPage: 5
|
|
2150
|
-
});
|
|
2151
|
-
const pullRequests = await service.listPullRequests({
|
|
2152
|
-
owner: config.owner,
|
|
2153
|
-
repo: config.repo,
|
|
2154
|
-
state: "open",
|
|
2155
|
-
perPage: 5
|
|
2156
|
-
});
|
|
2157
|
-
const parts = [
|
|
2158
|
-
`## GitHub Repository: ${repo.fullName}`,
|
|
2159
|
-
"",
|
|
2160
|
-
`**Description:** ${repo.description ?? "No description"}`,
|
|
2161
|
-
`**Default Branch:** ${repo.defaultBranch}`,
|
|
2162
|
-
`**Language:** ${repo.language ?? "Not specified"}`,
|
|
2163
|
-
`**Stars:** ${repo.stargazersCount} | **Forks:** ${repo.forksCount}`,
|
|
2164
|
-
`**Open Issues:** ${repo.openIssuesCount}`,
|
|
2165
|
-
""
|
|
2166
|
-
];
|
|
2167
|
-
if (issues.length > 0) {
|
|
2168
|
-
parts.push("### Recent Open Issues");
|
|
2169
|
-
for (const issue of issues) {
|
|
2170
|
-
const labels = issue.labels.map((l) => l.name).join(", ");
|
|
2171
|
-
parts.push(`- #${issue.number}: ${issue.title}${labels ? ` [${labels}]` : ""}`);
|
|
2172
|
-
}
|
|
2173
|
-
parts.push("");
|
|
2174
|
-
}
|
|
2175
|
-
if (pullRequests.length > 0) {
|
|
2176
|
-
parts.push("### Recent Open Pull Requests");
|
|
2177
|
-
for (const pr of pullRequests) {
|
|
2178
|
-
const status = pr.draft ? "[DRAFT] " : "";
|
|
2179
|
-
parts.push(`- #${pr.number}: ${status}${pr.title} (${pr.head.ref} → ${pr.base.ref})`);
|
|
2180
|
-
}
|
|
2181
|
-
parts.push("");
|
|
2182
|
-
}
|
|
2183
|
-
return { text: parts.join(`
|
|
2184
|
-
`) };
|
|
2185
|
-
} catch (error) {
|
|
2186
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
2187
|
-
return {
|
|
2188
|
-
text: `Unable to fetch GitHub repository state: ${errorMessage}`
|
|
2189
|
-
};
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
};
|
|
2193
|
-
// providers/index.ts
|
|
2194
|
-
var allProviders = [repositoryStateProvider, issueContextProvider];
|
|
2195
|
-
|
|
2196
|
-
// index.ts
|
|
2197
|
-
var githubPlugin = {
|
|
2198
|
-
name: "github",
|
|
2199
|
-
description: "GitHub integration for repository management, issues, pull requests, and code reviews",
|
|
2200
|
-
services: [GitHubService],
|
|
2201
|
-
actions: allActions,
|
|
2202
|
-
providers: allProviders,
|
|
2203
|
-
init: async (_config, runtime) => {
|
|
2204
|
-
const token = runtime.getSetting("GITHUB_API_TOKEN");
|
|
2205
|
-
const owner = runtime.getSetting("GITHUB_OWNER");
|
|
2206
|
-
const repo = runtime.getSetting("GITHUB_REPO");
|
|
2207
|
-
const branch = runtime.getSetting("GITHUB_BRANCH") ?? "main";
|
|
2208
|
-
logger9.info(`GitHub Plugin - Token: ${token ? "configured" : "not configured"}, Owner: ${owner ?? "not set"}, Repo: ${repo ?? "not set"}, Branch: ${branch}`);
|
|
2209
|
-
if (!token) {
|
|
2210
|
-
logger9.warn("GitHub API Token not provided - plugin will not be functional");
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
};
|
|
2214
|
-
var typescript_default = githubPlugin;
|
|
2215
|
-
export {
|
|
2216
|
-
typescript_default as default
|
|
2217
|
-
};
|
|
2218
|
-
|
|
2219
|
-
//# debugId=8467D22198144F6864756E2164756E21
|