backport
Version:
A CLI tool that automates the process of backporting commits
79 lines • 3.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const childProcessHelper_1 = require("../../childProcessHelper");
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
const sandbox_1 = require("../../sandbox");
const runBackportViaCli_1 = require("./runBackportViaCli");
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
const COMMIT_BY_JOHN_DOE_SHA = 'c3f837226bea3c7a50f2ba16d807fbe846ed3453';
describe('commit author', () => {
let sourceRepo;
let backportRepo;
beforeEach(async () => {
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
await (0, sandbox_1.resetSandbox)(sandboxPath);
sourceRepo = `${sandboxPath}/sourceRepo`;
backportRepo = `${sandboxPath}/backportRepo`;
await (0, childProcessHelper_1.exec)(`git clone https://github.com/backport-org/repo-with-different-commits-authors.git ${sourceRepo}`, { cwd: sandboxPath });
// set dummy git author. This should not have any effect and should never be used
await (0, childProcessHelper_1.exec)(`git config user.name "Peter Kanin"`, { cwd: sourceRepo });
await (0, childProcessHelper_1.exec)(`git config user.email "kanin@zoo.dk"`, { cwd: sourceRepo });
});
describe('when nothing is specified (default)', () => {
it('uses commit author from source commit', async () => {
await (0, runBackportViaCli_1.runBackportViaCli)([
`--accessToken=${accessToken}`,
`--dir=${backportRepo}`,
'--branch=production',
`--sha=${COMMIT_BY_JOHN_DOE_SHA}`,
'--dry-run',
], { cwd: sourceRepo, showOra: true });
const { authorEmail, authorName } = await getCommitAuthor({
cwd: backportRepo,
});
expect(authorName).toEqual('John Doe');
expect(authorEmail).toEqual('john.doe@backport-testing.dk');
});
});
describe('when setting author via `--gitAuthor*` cli options', () => {
it('respects the settings', async () => {
await (0, runBackportViaCli_1.runBackportViaCli)([
`--accessToken=${accessToken}`,
`--dir=${backportRepo}`,
'--branch=production',
`--sha=${COMMIT_BY_JOHN_DOE_SHA}`,
'--dry-run',
'--gitAuthorName="Donald Duck"',
'--gitAuthorEmail=duck@disney.com',
], { cwd: sourceRepo, showOra: true });
const { authorEmail, authorName } = await getCommitAuthor({
cwd: backportRepo,
});
expect(authorName).toEqual('Donald Duck');
expect(authorEmail).toEqual('duck@disney.com');
});
});
describe('when using `--resetAuthor` option', () => {
it('sets the current user as author of commit', async () => {
await (0, runBackportViaCli_1.runBackportViaCli)([
`--accessToken=${accessToken}`,
`--dir=${backportRepo}`,
'--branch=production',
`--sha=${COMMIT_BY_JOHN_DOE_SHA}`,
'--dry-run',
'--reset-author',
], { cwd: sourceRepo, showOra: true });
const { authorEmail, authorName } = await getCommitAuthor({
cwd: backportRepo,
});
expect(authorName).toEqual('sorenlouv');
expect(authorEmail).toEqual('sorenlouv@users.noreply.github.com');
});
});
});
async function getCommitAuthor({ cwd }) {
const { stdout: authorName } = await (0, childProcessHelper_1.exec)('git --no-pager log -1 --format=format:"%cn"', { cwd });
const { stdout: authorEmail } = await (0, childProcessHelper_1.exec)('git --no-pager log -1 --format=format:"%ce"', { cwd });
return { authorName, authorEmail };
}
//# sourceMappingURL=commit-author.private.test.js.map