Skip to content
Open
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
34 changes: 33 additions & 1 deletion apps/server/src/git/operations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SimpleGit } from 'simple-git';
import { SimpleGit, simpleGit } from 'simple-git';
import { logger } from '../config/logger';
import { GitHubError } from '../utils/error';
import { envConfig } from '../config/env';
Expand Down Expand Up @@ -28,6 +28,38 @@ export const createBranch = async (git: SimpleGit, branchName: string): Promise<
}
};

/**
* Checkout a remote branch by name or SHA.
*/
export const checkoutRemoteBranch = async (
repoPath: string,
ref: string,
sha?: string,
): Promise<void> => {
const git = simpleGit(repoPath);
try {
logger.info({ repoPath, ref, sha }, 'Checking out remote branch/ref');

// Fetch all remote branches to ensure the ref is available locally
await git.fetch('origin');

// If a SHA is provided, try to checkout that specific commit
if (sha) {
await git.checkout(sha);
logger.info({ repoPath, sha }, 'Checked out specific commit SHA');
} else {
// Otherwise, checkout the branch directly
await git.checkout(ref);
logger.info({ repoPath, ref }, 'Checked out remote branch');
}
} catch (error) {
logger.error({ repoPath, ref, sha, error }, 'Failed to checkout remote branch/ref');
throw new GitHubError(
`Failed to checkout remote branch/ref ${ref}: ${error instanceof Error ? error.message : String(error)}`,
);
}
};

/**
* Stage and commit changes
*/
Expand Down
59 changes: 59 additions & 0 deletions apps/server/src/github/pr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Octokit } from '@octokit/rest';
import { logger } from '../config/logger';
import { GitHubError } from '../utils/error';
import { getOctokitInstance } from './app';

interface CreatePRParams {
owner: string;
repo: string;
Expand Down Expand Up @@ -92,3 +94,60 @@ export const createPullRequest = async (
);
}
};

/**
* Add a comment to a pull request review comment.
*/
export const addCommentToPullRequest = async (
owner: string,
repo: string,
pull_number: number,
comment_id: number,
body: string,
installationId: number,
): Promise<void> => {
try {
const octokit = await getOctokitInstance(installationId);
logger.info(
{
owner,
repo,
pull_number,
comment_id,
},
'Adding comment to pull request review comment',
);

await octokit.pulls.createReviewComment({
owner,
repo,
pull_number,
comment_id,
body,
});

logger.info(
{
owner,
repo,
pull_number,
comment_id,
},
'Comment added to pull request review comment successfully',
);
} catch (error) {
logger.error(
{
owner,
repo,
pull_number,
comment_id,
error,
},
'Failed to add comment to pull request review comment',
);
throw new GitHubError(
`Failed to add comment to pull request review comment: ${error instanceof Error ? error.message : String(error)}`,
);
}
};
Loading