Skip to content

Commit d84914a

Browse files
authored
feat(cloud): commit changes and do pr (#213)
1 parent f9b316c commit d84914a

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

packages/agent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@posthog/agent",
3-
"version": "1.26.0",
3+
"version": "1.27.0",
44
"repository": "https://github.com/PostHog/array",
55
"description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
66
"main": "./dist/index.js",

packages/agent/src/agent.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,46 @@ Generated by PostHog Agent`;
689689
stopReason: result.stopReason,
690690
});
691691

692+
const branchName = await this.gitManager.getCurrentBranch();
693+
const hasChanges = await this.gitManager.hasChanges();
694+
const shouldCreatePR = options.createPR ?? false;
695+
696+
if (hasChanges) {
697+
this.logger.info("Committing uncommitted changes", { taskId: task.id });
698+
await this.gitManager.commitImplementation(
699+
task.id,
700+
task.title,
701+
task.description ?? undefined,
702+
);
703+
}
704+
705+
const defaultBranch = await this.gitManager.getDefaultBranch();
706+
if (branchName !== defaultBranch) {
707+
this.logger.info("Pushing branch", { branchName, taskId: task.id });
708+
await this.gitManager.pushBranch(branchName);
709+
710+
if (shouldCreatePR) {
711+
this.logger.info("Creating PR", { branchName, taskId: task.id });
712+
713+
const prUrl = await this.createPullRequest(
714+
task.id,
715+
branchName,
716+
task.title,
717+
task.description ?? "",
718+
);
719+
720+
this.logger.info("PR created", { prUrl, taskId: task.id });
721+
722+
try {
723+
await this.attachPullRequestToTask(task.id, prUrl, branchName);
724+
} catch (err) {
725+
this.logger.warn("Could not attach PR to task", {
726+
error: err instanceof Error ? err.message : String(err),
727+
});
728+
}
729+
}
730+
}
731+
692732
await this.sessionStore.complete(taskRunId);
693733
} catch (error) {
694734
const errorMessage =

packages/agent/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export interface TaskExecutionOptions {
134134
repositoryPath?: string;
135135
permissionMode?: PermissionMode;
136136
isCloudMode?: boolean; // Determines local vs cloud behavior (local pauses after each phase)
137-
createPR?: boolean; // Whether to create PR after build (defaults to false if local. This setting has no effect if isCloudMode is true.)
137+
createPR?: boolean; // Whether to create PR after build (defaults to false)
138138
autoProgress?: boolean;
139139
queryOverrides?: Record<string, unknown>;
140140
// Fine-grained permission control (only applied to build phase)

0 commit comments

Comments
 (0)