Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
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
3 changes: 2 additions & 1 deletion script/lib/update-dependency/fetch-outdated-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ const apm = async function({ dependencies, packageDependencies }) {

const npm = async function(cwd) {
try {
console.log('Checking npm registry...');
console.log('Checking npm registry...', cwd);

const currentState = await npmCheck({
cwd,
ignoreDev: true,
skipUnused: true
});

const outdatedPackages = currentState
.get('packages')
.filter(p => {
Expand Down
28 changes: 18 additions & 10 deletions script/lib/update-dependency/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,32 @@ const git = (git, repositoryRootPath) => {
} catch (ex) {
console.log(ex.message);
}

async function createOrCheckoutBranch(newBranch) {
const { branches } = await git.branch();
const found = Object.keys(branches).find(
branch => branch.indexOf(newBranch) > -1
);
found
? await git.checkout(found)
: await git.checkoutLocalBranch(newBranch);

return { found, newBranch };
}

return {
switchToMaster: async function() {
await git.checkout('origin/master');
switchToCleanBranch: async function() {
const cleanBranch = 'clean-branch';
const { current } = await git.branch();
if (current !== cleanBranch) createOrCheckoutBranch(cleanBranch);
},
makeBranch: async function(dependency) {
const newBranch = `${dependency.moduleName}-${dependency.latest}`;
const { branches } = await git.branch();
const { files } = await git.status();
if (files.length > 0) {
await git.reset('hard');
}
const found = Object.keys(branches).find(
branch => branch.indexOf(newBranch) > -1
);
found
? await git.checkout(found)
: await git.checkoutLocalBranch(newBranch);
return { found, newBranch };
return createOrCheckoutBranch(newBranch);
},
createCommit: async function({ moduleName, latest }) {
try {
Expand Down
6 changes: 3 additions & 3 deletions script/lib/update-dependency/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const runApmInstall = require('../run-apm-install');
const {
makeBranch,
createCommit,
switchToMaster,
switchToCleanBranch,
publishBranch,
deleteBranch
} = require('./git')(git, repositoryRootPath);
Expand All @@ -27,7 +27,7 @@ const fetchOutdatedDependencies = require('./fetch-outdated-dependencies');
module.exports = async function() {
try {
// ensure we are on master
await switchToMaster();
await switchToCleanBranch();
const failedBumps = [];
const successfullBumps = [];
const outdateDependencies = [
Expand Down Expand Up @@ -69,7 +69,7 @@ module.exports = async function() {
});
}

await switchToMaster();
await switchToCleanBranch();
}
// create PRs here
for (const { dependency, branch, branchIsRemote } of pendingPRs) {
Expand Down
16 changes: 8 additions & 8 deletions script/lib/update-dependency/spec/git-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const repositoryRootPath = path.resolve('.', 'fixtures', 'dummy');
const git = simpleGit(repositoryRootPath);

const {
switchToMaster,
switchToCleanBranch,
makeBranch,
publishBranch,
createCommit,
Expand All @@ -23,22 +23,22 @@ describe('GIT', () => {
const branch = `${dependency.moduleName}-${dependency.latest}`;

beforeEach(async () => {
await git.checkout('master');
await git.checkout('clean-branch');
});

it('remotes should include ATOM', async () => {
const remotes = await git.getRemotes();
expect(remotes.map(({ name }) => name).includes('ATOM')).toBeTruthy();
});

it('current branch should be master', async () => {
it('current branch should be clean-branch', async () => {
const testBranchExists = await findBranch('test');
testBranchExists
? await git.checkout('test')
: await git.checkoutLocalBranch('test');
expect((await git.branch()).current).toBe('test');
await switchToMaster();
expect((await git.branch()).current).toBe('master');
await switchToCleanBranch();
expect((await git.branch()).current).toBe('clean-branch');
await git.deleteLocalBranch('test', true);
});

Expand All @@ -47,7 +47,7 @@ describe('GIT', () => {
expect(found).toBe(undefined);
expect(newBranch).toBe(branch);
expect((await git.branch()).current).toBe(branch);
await git.checkout('master');
await git.checkout('clean-branch');
await git.deleteLocalBranch(branch, true);
});

Expand All @@ -56,7 +56,7 @@ describe('GIT', () => {
const { found } = await makeBranch(dependency);
expect(found).not.toBe(undefined);
expect((await git.branch()).current).toBe(found);
await git.checkout('master');
await git.checkout('clean-branch');
await git.deleteLocalBranch(branch, true);
});

Expand Down Expand Up @@ -86,7 +86,7 @@ describe('GIT', () => {

it('should delete an existing branch', async () => {
await git.checkoutLocalBranch(branch);
await git.checkout('master');
await git.checkout('clean-branch');
expect(await findBranch(branch)).not.toBe(undefined);
await deleteBranch(branch);
expect(await findBranch(branch)).toBe(undefined);
Expand Down