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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@github/copilot-engine-sdk",
"version": "0.1.0",
"version": "0.2.0",
"description": "SDK for building engines on the GitHub Copilot agent platform",
"type": "module",
"main": "dist/index.js",
Expand Down
15 changes: 12 additions & 3 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export interface CloneRepoOptions {
commitEmail: string;
/** Base directory for cloning (default: /tmp/workspace) */
cloneDir?: string;
/** Whether to exclude the repository subfolder (owner/repo) when cloning (default: false) */
excludeRepoSubfolder?: boolean;
/** If set, use an environment variable name for Git credential helper rather than embedding the token in the config (default: undefined) */
credentialHelperEnvVar?: string;
}

/**
Expand Down Expand Up @@ -84,9 +88,14 @@ export interface CommitAndPushResult {
* @returns The local path where the repository was cloned
*/
export function cloneRepo(options: CloneRepoOptions): string {
const { serverUrl, repository, gitToken, branchName, commitLogin, commitEmail } = options;
const { serverUrl, repository, gitToken, credentialHelperEnvVar, excludeRepoSubfolder, branchName, commitLogin, commitEmail } = options;

if (credentialHelperEnvVar && !/^[A-Za-z_][A-Za-z0-9_]*$/.test(credentialHelperEnvVar)) {
throw new Error(`Invalid credentialHelperEnvVar: must be a valid environment variable name (letters, digits, underscores; cannot start with a digit)`);
}

const cloneDir = options.cloneDir ?? DEFAULT_CLONE_DIR;
const repoLocation = `${cloneDir}/${repository}`;
const repoLocation = excludeRepoSubfolder ? cloneDir : `${cloneDir}/${repository}`;
Comment thread
Chuxel marked this conversation as resolved.

const cloneUrl = `${serverUrl.replace(/\/$/, "")}/${repository}.git`;

Expand All @@ -95,7 +104,7 @@ export function cloneRepo(options: CloneRepoOptions): string {
execFileSync("git", ["config", "user.email", commitEmail], { cwd: repoLocation });
execFileSync("git", ["config", "credential.username", "x-access-token"], { cwd: repoLocation });
execFileSync("git", ["config", "credential.helper",
`!f() { test "$1" = get && echo "password=${gitToken}"; }; f`], { cwd: repoLocation });
`!f() { test "$1" = get && echo "password=${credentialHelperEnvVar ? '${' + credentialHelperEnvVar + '}' : gitToken}"; }; f`], { cwd: repoLocation });
Comment thread
Chuxel marked this conversation as resolved.
execFileSync("git", ["remote", "set-url", "origin", cloneUrl], { cwd: repoLocation });
};

Expand Down