mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Simplify git onAuth calls
This commit is contained in:
4 files changed
+11
-47
No files matched your search
@@ -65,15 +65,6 @@ export class GitPushCommand implements GitSubcommand {
|
||||
}
|
||||
|
||||
const settings = await readGitSettings(this.fs);
|
||||
const currentCredentials = findCredentialsForRepo(remoteUrl, settings.credentials);
|
||||
|
||||
// Prepare authentication if credentials are available
|
||||
const authOptions = currentCredentials ? {
|
||||
onAuth: () => ({
|
||||
username: currentCredentials.username,
|
||||
password: currentCredentials.password,
|
||||
}),
|
||||
} : {};
|
||||
|
||||
try {
|
||||
await this.git.push({
|
||||
@@ -81,7 +72,7 @@ export class GitPushCommand implements GitSubcommand {
|
||||
remote: remote,
|
||||
ref: targetBranch,
|
||||
remoteRef: targetBranch,
|
||||
...authOptions,
|
||||
onAuth: (url) => findCredentialsForRepo(url, settings.credentials),
|
||||
});
|
||||
|
||||
return createSuccessResult(`To ${remoteUrl}\n ${targetBranch} -> ${targetBranch}\n`);
|
||||
|
||||
@@ -64,17 +64,17 @@ describe('gitCredentials', () => {
|
||||
.toEqual({ username: 'git', password: 'github-token' });
|
||||
});
|
||||
|
||||
it('should return null when no credentials found', () => {
|
||||
it('should return undefined when no credentials found', () => {
|
||||
expect(findCredentialsForRepo('https://unknown.com/user/repo.git', mockCredentials))
|
||||
.toBe(null);
|
||||
|
||||
.toBe(undefined);
|
||||
|
||||
expect(findCredentialsForRepo('invalid-url', mockCredentials))
|
||||
.toBe(null);
|
||||
.toBe(undefined);
|
||||
});
|
||||
|
||||
it('should return null for empty credentials', () => {
|
||||
it('should return undefined for empty credentials', () => {
|
||||
expect(findCredentialsForRepo('https://github.com/user/repo.git', {}))
|
||||
.toBe(null);
|
||||
.toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ export function extractGitOrigin(gitUrl: string): string | null {
|
||||
export function findCredentialsForRepo(
|
||||
repoUrl: string,
|
||||
credentials: Record<string, GitCredential>
|
||||
): GitCredential | null {
|
||||
): GitCredential | undefined {
|
||||
const repoOrigin = extractGitOrigin(repoUrl);
|
||||
if (!repoOrigin) return null;
|
||||
if (!repoOrigin) return;
|
||||
|
||||
// Direct match
|
||||
if (credentials[repoOrigin]) {
|
||||
@@ -57,8 +57,6 @@ export function findCredentialsForRepo(
|
||||
return credential;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user