mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Fix auto-branch workflow: commit changes to feature branch
**Critical Fix:** When auto-creating a feature branch from main/master: 1. Create the feature branch first 2. Checkout the feature branch 3. Commit uncommitted changes to the feature branch 4. This ensures main and feature branch differ (required for PRs) **Previous Bug:** - Was committing to main, then branching - Result: main and feature-branch at same commit = no diff = "head: invalid" **New Flow:** - Branch from main (both at same commit) - Checkout feature branch - Commit changes to feature branch - Result: feature-branch ahead of main = valid PR **Added Logging:** - Shows head ref format being used - Logs PR data being sent to API - Helps debug "head: invalid" errors **Validation:** - Checks if branch and main are at same commit - Shows error if no changes to submit - Prevents empty PRs This fixes the "Validation Failed - head: invalid" error when creating PRs from main/master.
This commit is contained in:
1 parent
a08e59248d
commit
428c6b0e2e
2 files changed
+107
-27
No files matched your search
@@ -201,10 +201,12 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
|
||||
.replace(/^-|-$/g, '')
|
||||
.substring(0, 50);
|
||||
|
||||
const featureBranchName = `${sanitizedTitle}-${Date.now().toString(36).slice(-4)}`;
|
||||
const baseName = sanitizedTitle || 'feature';
|
||||
const featureBranchName = `${baseName}-${Date.now().toString(36).slice(-4)}`;
|
||||
console.log(`Creating feature branch: ${featureBranchName}`);
|
||||
|
||||
try {
|
||||
// Create branch first
|
||||
await git.branch({
|
||||
dir: projectPath,
|
||||
ref: featureBranchName,
|
||||
@@ -214,6 +216,29 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
|
||||
branchToUse = featureBranchName;
|
||||
console.log(`Successfully created and checked out branch: ${featureBranchName}`);
|
||||
|
||||
// Check if there are uncommitted changes to commit to this branch
|
||||
const statusMatrix = await git.statusMatrix({ dir: projectPath });
|
||||
const hasUncommittedChanges = statusMatrix.some(([, head, workdir]) => head !== workdir);
|
||||
|
||||
if (hasUncommittedChanges) {
|
||||
console.log('Committing changes to new branch');
|
||||
|
||||
for (const [filepath, , workdir] of statusMatrix) {
|
||||
if (workdir === 0) {
|
||||
await git.remove({ dir: projectPath, filepath });
|
||||
} else if (workdir !== 0) {
|
||||
await git.add({ dir: projectPath, filepath });
|
||||
}
|
||||
}
|
||||
|
||||
await git.commit({
|
||||
dir: projectPath,
|
||||
message: title,
|
||||
});
|
||||
|
||||
console.log('Committed changes to new branch');
|
||||
}
|
||||
|
||||
toast({
|
||||
title: 'Feature branch created',
|
||||
description: `Created branch '${featureBranchName}' for your changes`,
|
||||
@@ -234,6 +259,9 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
|
||||
? `${forkInfo.forkOwner}:${branchToUse}`
|
||||
: branchToUse;
|
||||
|
||||
console.log('PR head ref will be:', headRef);
|
||||
console.log('PR base ref will be:', targetBranch);
|
||||
|
||||
if (forkInfo.needsFork && forkInfo.forkUrl) {
|
||||
console.log(`Pushing branch ${branchToUse} to fork ${forkInfo.forkUrl}`);
|
||||
|
||||
@@ -279,19 +307,24 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
|
||||
}
|
||||
|
||||
const url = `${remoteInfo.apiUrl}/repos/${remoteInfo.owner}/${remoteInfo.repo}/pulls`;
|
||||
|
||||
const prData = {
|
||||
title,
|
||||
body: description,
|
||||
head: headRef,
|
||||
base: targetBranch,
|
||||
maintainer_can_modify: true,
|
||||
};
|
||||
|
||||
console.log('Creating PR with data:', prData);
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `token ${credentials.password}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
title,
|
||||
body: description,
|
||||
head: headRef,
|
||||
base: targetBranch,
|
||||
maintainer_can_modify: true,
|
||||
}),
|
||||
body: JSON.stringify(prData),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in new issue
Block a user