chore: refactor variable names for isomorphic git.

This commit is contained in:
blam
2020-12-29 13:32:24 +01:00
parent 610b3a205a
commit 8bccc6bec0
4 changed files with 33 additions and 32 deletions
+13 -13
View File
@@ -46,15 +46,15 @@ describe('Git', () => {
it('should call isomorphic-git with the correct arguments', async () => {
const git = Git.fromAuth({});
const dir = 'mockdirectory';
const remoteName = 'origin';
const remote = 'origin';
const url = 'git@github.com/something/sads';
await git.addRemote({ dir, remoteName, url });
await git.addRemote({ dir, remote, url });
expect(isomorphic.addRemote).toHaveBeenCalledWith({
fs,
dir,
remote: remoteName,
remote,
url,
});
});
@@ -224,18 +224,18 @@ describe('Git', () => {
name: 'comitter',
email: 'test@backstage.io',
};
const headBranch = 'master';
const baseBranch = 'production';
const theirs = 'master';
const ours = 'production';
const git = Git.fromAuth({});
await git.merge({ dir, headBranch, baseBranch, author, committer });
await git.merge({ dir, theirs, ours, author, committer });
expect(isomorphic.merge).toHaveBeenCalledWith({
fs,
dir,
ours: baseBranch,
theirs: headBranch,
ours,
theirs,
author,
committer,
});
@@ -244,7 +244,7 @@ describe('Git', () => {
describe('push', () => {
it('should call isomorphic-git with the correct arguments', async () => {
const remoteName = 'origin';
const remote = 'origin';
const dir = '/some/mock/dir';
const auth = {
username: 'blob',
@@ -252,12 +252,12 @@ describe('Git', () => {
};
const git = Git.fromAuth(auth);
await git.push({ dir, remoteName });
await git.push({ dir, remote });
expect(isomorphic.push).toHaveBeenCalledWith({
fs,
http,
remote: remoteName,
remote,
dir,
onProgress: expect.any(Function),
headers: {
@@ -267,7 +267,7 @@ describe('Git', () => {
});
});
it('should pass a function that returns the authorization as the onAuth handler', async () => {
const remoteName = 'origin';
const remote = 'origin';
const dir = '/some/mock/dir';
const auth = {
username: 'blob',
@@ -275,7 +275,7 @@ describe('Git', () => {
};
const git = Git.fromAuth(auth);
await git.push({ remoteName, dir });
await git.push({ remote, dir });
const { onAuth } = ((isomorphic.push as unknown) as jest.Mock<
typeof isomorphic['push']
+16 -15
View File
@@ -46,16 +46,16 @@ export class Git {
async addRemote({
dir,
url,
remoteName,
remote,
}: {
dir: string;
remoteName: string;
remote: string;
url: string;
}) {
this.config.logger?.info(
`Creating new remote {dir=${dir},remoteName=${remoteName},url=${url}}`,
`Creating new remote {dir=${dir},remote=${remote},url=${url}}`,
);
return git.addRemote({ fs, dir, remote: remoteName, url });
return git.addRemote({ fs, dir, remote, url });
}
async commit({
@@ -130,34 +130,35 @@ export class Git {
// https://isomorphic-git.org/docs/en/merge
async merge({
dir,
headBranch,
baseBranch,
theirs,
ours,
author,
committer,
}: {
dir: string;
headBranch: string;
baseBranch?: string;
theirs: string;
ours?: string;
author: { name: string; email: string };
committer: { name: string; email: string };
}) {
this.config.logger?.info(
`Merging branch '${headBranch}' into '${baseBranch}' for repository {dir=${dir}}`,
`Merging branch '${theirs}' into '${ours}' for repository {dir=${dir}}`,
);
// If baseBranch is undefined, current branch is used.
// If ours is undefined, current branch is used.
return git.merge({
fs,
dir,
ours: baseBranch,
theirs: headBranch,
ours,
theirs,
author,
committer,
});
}
async push({ dir, remoteName }: { dir: string; remoteName: string }) {
async push({ dir, remote }: { dir: string; remote: string }) {
this.config.logger?.info(
`Pushing directory to remote {dir=${dir},remoteName=${remoteName}}`,
`Pushing directory to remote {dir=${dir},remote=${remote}}`,
);
return git.push({
fs,
@@ -167,7 +168,7 @@ export class Git {
headers: {
'user-agent': 'git/@isomorphic-git',
},
remote: remoteName,
remote: remote,
onAuth: this.onAuth,
});
}
+2 -2
View File
@@ -170,8 +170,8 @@ export const checkoutGitRepository = async (
await git.fetch({ dir: repositoryTmpPath, remote: 'origin' });
await git.merge({
dir: repositoryTmpPath,
headBranch: `origin/${currentBranchName}`,
baseBranch: currentBranchName || undefined,
theirs: `origin/${currentBranchName}`,
ours: currentBranchName || undefined,
author: { name: 'Backstage TechDocs', email: 'techdocs@backstage.io' },
committer: {
name: 'Backstage TechDocs',
@@ -59,11 +59,11 @@ export async function initRepoAndPush({
await git.addRemote({
dir,
url: remoteUrl,
remoteName: 'origin',
remote: 'origin',
});
await git.push({
dir,
remoteName: 'origin',
remote: 'origin',
});
}