mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Don't pass author into git functions - use values from config
This commit is contained in:
3 files changed
+37
-93
No files matched your search
@@ -91,10 +91,6 @@ export function usePlugins() {
|
||||
dir: pluginDir,
|
||||
singleBranch: true,
|
||||
fastForward: true,
|
||||
author: {
|
||||
name: 'shakespeare.diy',
|
||||
email: '[email protected]',
|
||||
},
|
||||
});
|
||||
|
||||
return pluginName;
|
||||
|
||||
+1
-50
@@ -306,7 +306,7 @@ describe('Git', () => {
|
||||
const { readGitSettings } = await import('./configUtils');
|
||||
vi.mocked(readGitSettings).mockResolvedValue({
|
||||
credentials: [],
|
||||
coAuthorEnabled: true,
|
||||
coAuthorEnabled: false,
|
||||
});
|
||||
|
||||
await gitInstance.commit({
|
||||
@@ -322,10 +322,6 @@ describe('Git', () => {
|
||||
name: 'shakespeare.diy',
|
||||
email: '[email protected]',
|
||||
},
|
||||
committer: {
|
||||
name: 'shakespeare.diy',
|
||||
email: '[email protected]',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -351,10 +347,6 @@ describe('Git', () => {
|
||||
name: 'John Doe',
|
||||
email: '[email protected]',
|
||||
},
|
||||
committer: {
|
||||
name: 'John Doe',
|
||||
email: '[email protected]',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -380,47 +372,6 @@ describe('Git', () => {
|
||||
name: 'John Doe',
|
||||
email: '[email protected]',
|
||||
},
|
||||
committer: {
|
||||
name: 'John Doe',
|
||||
email: '[email protected]',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('respects provided author when explicitly passed', async () => {
|
||||
const { readGitSettings } = await import('./configUtils');
|
||||
vi.mocked(readGitSettings).mockResolvedValue({
|
||||
credentials: [],
|
||||
name: 'John Doe',
|
||||
email: '[email protected]',
|
||||
coAuthorEnabled: true,
|
||||
});
|
||||
|
||||
await gitInstance.commit({
|
||||
dir: '/test',
|
||||
message: 'Test commit',
|
||||
author: {
|
||||
name: 'Custom Author',
|
||||
email: '[email protected]',
|
||||
},
|
||||
committer: {
|
||||
name: 'Custom Committer',
|
||||
email: '[email protected]',
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockGit.commit).toHaveBeenCalledWith({
|
||||
fs,
|
||||
dir: '/test',
|
||||
message: 'Test commit',
|
||||
author: {
|
||||
name: 'Custom Author',
|
||||
email: '[email protected]',
|
||||
},
|
||||
committer: {
|
||||
name: 'Custom Committer',
|
||||
email: '[email protected]',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+36
-39
@@ -12,6 +12,7 @@ export interface GitOptions {
|
||||
nostr: NPool;
|
||||
corsProxy?: string;
|
||||
ngitServers?: string[];
|
||||
systemAuthor?: { name: string; email: string };
|
||||
}
|
||||
|
||||
interface NostrCloneURI {
|
||||
@@ -31,12 +32,17 @@ export class Git {
|
||||
private http: HttpClient;
|
||||
private nostr: NPool;
|
||||
private ngitServers: string[];
|
||||
private systemAuthor: { name: string; email: string };
|
||||
|
||||
constructor(options: GitOptions) {
|
||||
this.fs = options.fs;
|
||||
this.http = new GitHttp(options.corsProxy);
|
||||
this.nostr = options.nostr;
|
||||
this.ngitServers = options.ngitServers ?? ['git.shakespeare.diy', 'relay.ngit.dev'];
|
||||
this.systemAuthor = options.systemAuthor ?? {
|
||||
name: 'shakespeare.diy',
|
||||
email: '[email protected]',
|
||||
};
|
||||
}
|
||||
|
||||
// Repository initialization and configuration
|
||||
@@ -96,50 +102,19 @@ export class Git {
|
||||
}
|
||||
|
||||
// Commits and history
|
||||
async commit(options: Omit<Parameters<typeof git.commit>[0], 'fs'>) {
|
||||
// If author is not provided, use Git identity settings
|
||||
let author = options.author;
|
||||
let committer = options.committer;
|
||||
async commit(options: Omit<Parameters<typeof git.commit>[0], 'fs' | 'author'>) {
|
||||
const { author, coAuthorEnabled } = await this.getGitSettings();
|
||||
|
||||
// Add system co-author if enabled
|
||||
let message = options.message;
|
||||
|
||||
if (!author || !committer) {
|
||||
// Read Git identity settings from config
|
||||
const gitSettings = await readGitSettings(this.fs);
|
||||
|
||||
// Determine author based on Git identity settings
|
||||
const defaultAuthor = {
|
||||
name: 'shakespeare.diy',
|
||||
email: '[email protected]',
|
||||
};
|
||||
|
||||
const hasCustomIdentity = gitSettings.name && gitSettings.email;
|
||||
|
||||
if (hasCustomIdentity) {
|
||||
const customAuthor = {
|
||||
name: gitSettings.name!,
|
||||
email: gitSettings.email!,
|
||||
};
|
||||
|
||||
// Use custom identity
|
||||
if (!author) author = customAuthor;
|
||||
if (!committer) committer = customAuthor;
|
||||
|
||||
// Add Shakespeare as co-author if enabled
|
||||
if (gitSettings.coAuthorEnabled ?? true) {
|
||||
message = `${message}\n\nCo-authored-by: shakespeare.diy <[email protected]>`;
|
||||
}
|
||||
} else {
|
||||
// Use Shakespeare as default author
|
||||
if (!author) author = defaultAuthor;
|
||||
if (!committer) committer = defaultAuthor;
|
||||
}
|
||||
if (coAuthorEnabled) {
|
||||
message = `${message}\n\nCo-authored-by: ${this.systemAuthor.name} <${this.systemAuthor.email}>`;
|
||||
}
|
||||
|
||||
return git.commit({
|
||||
fs: this.fs,
|
||||
...options,
|
||||
author,
|
||||
committer,
|
||||
message,
|
||||
});
|
||||
}
|
||||
@@ -246,14 +221,15 @@ export class Git {
|
||||
});
|
||||
}
|
||||
|
||||
async pull(options: Omit<Parameters<typeof git.pull>[0], 'fs' | 'http' | 'corsProxy'>) {
|
||||
async pull(options: Omit<Parameters<typeof git.pull>[0], 'fs' | 'http' | 'author' | 'corsProxy'>) {
|
||||
// Check if this is a Nostr repository by looking at the remote URL
|
||||
const remote = options.remote || 'origin';
|
||||
const dir = options.dir || '.';
|
||||
const remoteUrl = await this.getRemoteURL(dir, remote);
|
||||
const { author } = await this.getGitSettings();
|
||||
|
||||
if (remoteUrl && remoteUrl.startsWith('nostr://')) {
|
||||
return this.nostrPull(remoteUrl, { ...options, remote, dir });
|
||||
return this.nostrPull(remoteUrl, { ...options, author, remote, dir });
|
||||
}
|
||||
|
||||
// Regular Git pull
|
||||
@@ -261,6 +237,7 @@ export class Git {
|
||||
fs: this.fs,
|
||||
http: this.http,
|
||||
...options,
|
||||
author,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -598,6 +575,26 @@ export class Git {
|
||||
return git.version();
|
||||
}
|
||||
|
||||
private async getGitSettings(): Promise<{ author: { name: string; email: string }; coAuthorEnabled: boolean }> {
|
||||
const {
|
||||
name,
|
||||
email,
|
||||
coAuthorEnabled = true,
|
||||
} = await readGitSettings(this.fs);
|
||||
|
||||
if (name && email) {
|
||||
return {
|
||||
author: { name, email },
|
||||
coAuthorEnabled,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
author: this.systemAuthor,
|
||||
coAuthorEnabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Nostr-specific helper methods
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user