Skip to content

Commit

Permalink
Add tortilla-release-list
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB committed May 31, 2019
1 parent 51ec13a commit 03437cb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ Initializes Tortilla essentials in the provided project.

**command:** `tortilla push <remote> <branch>`

Push a tutorial based on the provided branch. e.g. given `master` then `master-history`, `master-root`, `master@0.1.0`, etc, will be pushed. Note that everything will be pushed by FORCE and will override existing refs within the remote.
Push a tutorial based on the provided branch. e.g. given `master` then `master-history`, `master-root`, `master@0.1.0`, etc, will be pushed. Note that everything will be pushed by FORCE and will override existing refs within the remote, **even deleted refs**.

**command:** `tortilla pull <remote> <branch>`

Expand Down Expand Up @@ -381,6 +381,10 @@ Bumps the current release of the tutorial. This will create some new release tag

Reverts release to the most recent one. For example, if we have 2 releases: `master@2.0.0` and `master@1.0.0`, this command will delete `master@2.0.0`, leaving `master@1.0.0`. If no more releases are left, the `history` branch will be deleted. This is useful if we've released something by accident and we would like to fix it.

**command:** `tortilla release list [branch]`

Prints a list of all releases of the given `branch`. If no `branch` was provided, the active branch will be used by default.

**command:** `tortilla release current`

Prints the current release.
Expand Down
12 changes: 12 additions & 0 deletions src/cli/tortilla-release.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

import * as Program from 'commander';
import { Git } from '../git';
import { localStorage as LocalStorage } from '../local-storage';
import { Release } from '../release';

Expand All @@ -25,6 +26,17 @@ Program
Release.revert();
})

Program
.command('list [branch]')
.description('Lists all releases for given branch')
.action((branch = Git.activeBranchName()) => {
LocalStorage.assertTortilla(true);
const releases = Release.all(null, branch)
.map(release => `${branch}@${Release.format(release)}`);
releases[0] += ' -> current release';
console.log(releases.join('\n'));
});

Program
.command('current')
.description('Prints the current release')
Expand Down
4 changes: 1 addition & 3 deletions src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,7 @@ function getAllReleasesOfAllBranches(path = null) {
}
// Gets a list of all the releases represented as JSONs e.g.
// [{ major: 0, minor: 1, patch: 0 }]
function getAllReleases(path = null) {
const branch = Git.activeBranchName(path);

function getAllReleases(path = null, branch = Git.activeBranchName(path)) {
return Git(['tag'], path ? { cwd: path } : null)
// Put tags into an array
.split('\n')
Expand Down
36 changes: 35 additions & 1 deletion tests/release.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ describe('Release', () => {
});
});

describe.only('revert()', () => {
describe('revert()', () => {
it('should revert most recent release', () => {
context.tortilla(['release', 'bump', 'major', '-m', 'first release']);
context.tortilla(['release', 'bump', 'major', '-m', 'second release']);
Expand All @@ -378,6 +378,40 @@ describe('Release', () => {
});
});

describe('list()', () => {
it('should print all versions of current branch', () => {
context.tortilla(['release', 'bump', 'major', '-m', 'major version test']);
context.tortilla(['release', 'bump', 'next', '-m', 'next version test']);
context.tortilla(['release', 'bump', 'minor', '-m', 'minor version test']);
context.tortilla(['release', 'bump', 'patch', '-m', 'patch version test']);

const releasesList = context.tortilla(['release', 'list']);

expect(releasesList).toEqual([
'master@1.1.1 -> current release',
'master@1.1.0',
'master@1.0.0'
].join('\n'));
});

it('should print all versions of given branch', () => {
context.tortilla(['release', 'bump', 'major', '-m', 'major version test']);
context.tortilla(['release', 'bump', 'next', '-m', 'next version test']);
context.tortilla(['release', 'bump', 'minor', '-m', 'minor version test']);
context.tortilla(['release', 'bump', 'patch', '-m', 'patch version test']);

context.git(['checkout', '-b', 'test-branch']);

context.tortilla(['release', 'bump', 'major', '-m', 'major version test']);

const releasesList = context.tortilla(['release', 'list']);

expect(releasesList).toEqual([
'test-branch@1.0.0 -> current release'
].join('\n'));
});
});

describe('current()', () => {
it('should get the current version', () => {
context.tortilla(['release', 'bump', 'major', '-m', 'major version test']);
Expand Down

0 comments on commit 03437cb

Please sign in to comment.