Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pkg/workflow/js/add_reaction_and_edit_comment.cjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
async function main() {
// Read inputs from environment variables
const reaction = process.env.GITHUB_AW_REACTION || "eyes";
const alias = process.env.GITHUB_AW_ALIAS; // Only present for alias workflows
const command = process.env.GITHUB_AW_COMMAND; // Only present for command workflows
const runId = context.runId;
const runUrl = context.payload.repository
? `${context.payload.repository.html_url}/actions/runs/${runId}`
: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;

console.log("Reaction type:", reaction);
console.log("Alias name:", alias || "none");
console.log("Command name:", command || "none");
console.log("Run ID:", runId);
console.log("Run URL:", runUrl);

Expand Down Expand Up @@ -59,8 +59,8 @@ async function main() {
}
reactionEndpoint = `/repos/${owner}/${repo}/issues/comments/${commentId}/reactions`;
commentUpdateEndpoint = `/repos/${owner}/${repo}/issues/comments/${commentId}`;
// Only edit comments for alias workflows
shouldEditComment = alias ? true : false;
// Only edit comments for command workflows
shouldEditComment = command ? true : false;
break;

case "pull_request":
Expand All @@ -83,8 +83,8 @@ async function main() {
}
reactionEndpoint = `/repos/${owner}/${repo}/pulls/comments/${reviewCommentId}/reactions`;
commentUpdateEndpoint = `/repos/${owner}/${repo}/pulls/comments/${reviewCommentId}`;
// Only edit comments for alias workflows
shouldEditComment = alias ? true : false;
// Only edit comments for command workflows
shouldEditComment = command ? true : false;
break;

default:
Expand All @@ -102,9 +102,9 @@ async function main() {
console.log("Comment update endpoint:", commentUpdateEndpoint);
await editCommentWithWorkflowLink(commentUpdateEndpoint, runUrl);
} else {
if (!alias && commentUpdateEndpoint) {
if (!command && commentUpdateEndpoint) {
console.log(
"Skipping comment edit - only available for alias workflows"
"Skipping comment edit - only available for command workflows"
);
} else {
console.log("Skipping comment edit for event type:", eventName);
Expand Down
30 changes: 10 additions & 20 deletions pkg/workflow/js/create_pull_request.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,17 @@ async function main() {
console.log("Draft:", draft);
console.log("Body length:", body.length);

const randomHex = crypto.randomBytes(8).toString("hex");
// Use branch name from JSONL if provided, otherwise generate unique branch name
if (!branchName) {
console.log(
"No branch name provided in JSONL, generating unique branch name"
);
// Generate unique branch name using cryptographic random hex
const randomHex = crypto.randomBytes(8).toString("hex");
branchName = `${workflowId}/${randomHex}`;
branchName = `${workflowId}-${randomHex}`;
} else {
console.log("Using branch name from JSONL:", branchName);
branchName = `${branchName}-${randomHex}`;
Comment thread
dsyme marked this conversation as resolved.
console.log("Using branch name from JSONL with added salt:", branchName);
}

console.log("Generated branch name:", branchName);
Expand All @@ -197,23 +198,12 @@ async function main() {
execSync(`git checkout ${baseBranch}`, { stdio: "inherit" });

// Handle branch creation/checkout
const branchFromJsonl = pullRequestItem.branch
? pullRequestItem.branch.trim()
: null;
if (branchFromJsonl) {
console.log("Checking if branch from JSONL exists:", branchFromJsonl);

console.log(
"Branch does not exist locally, creating new branch from base:",
branchFromJsonl
);
execSync(`git checkout -b ${branchFromJsonl}`, { stdio: "inherit" });
console.log("Created new branch from base:", branchFromJsonl);
} else {
// Create and checkout new branch with generated name from base branch
execSync(`git checkout -b ${branchName}`, { stdio: "inherit" });
console.log("Created and checked out new branch from base:", branchName);
}
console.log(
"Branch should not exist locally, creating new branch from base:",
branchName
);
execSync(`git checkout -b ${branchName}`, { stdio: "inherit" });
console.log("Created new branch from base:", branchName);

// Apply the patch using git CLI (skip if empty)
if (!isEmpty) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/workflow/js/create_pull_request.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ describe("create_pull_request.cjs", () => {

// Verify git operations (excluding git config which is handled by workflow)
expect(mockDependencies.execSync).toHaveBeenCalledWith(
"git checkout -b test-workflow/1234567890abcdef",
"git checkout -b test-workflow-1234567890abcdef",
{ stdio: "inherit" }
);
expect(mockDependencies.execSync).toHaveBeenCalledWith(
"git am /tmp/aw.patch",
{ stdio: "inherit" }
);
expect(mockDependencies.execSync).toHaveBeenCalledWith(
"git push origin test-workflow/1234567890abcdef",
"git push origin test-workflow-1234567890abcdef",
{ stdio: "inherit" }
);

Expand All @@ -200,7 +200,7 @@ describe("create_pull_request.cjs", () => {
repo: "testrepo",
title: "New Feature",
body: expect.stringContaining("This adds a new feature to the codebase."),
head: "test-workflow/1234567890abcdef",
head: "test-workflow-1234567890abcdef",
base: "main",
draft: true, // default value
});
Expand All @@ -215,7 +215,7 @@ describe("create_pull_request.cjs", () => {
);
expect(mockDependencies.core.setOutput).toHaveBeenCalledWith(
"branch_name",
"test-workflow/1234567890abcdef"
"test-workflow-1234567890abcdef"
);
});

Expand Down
Loading