Skip to content

Commit

Permalink
Merge pull request #5 from anfema/develop
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
pichfl authored Sep 5, 2018
2 parents 8a6a2e9 + b376b94 commit 1b92ff9
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 173 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ And
- Batch update GitHub labels



## Installation

If you have Node.js and Yarn installed, you can use install via:
Expand All @@ -18,11 +19,20 @@ yarn global add anfema/work
```


## Usage

### Changelogs

`-l` `--changelog` accepts a revision range, ie. `1.0.0` or `1.0.0..2.0.0` or `..HEAD` to limit the requested and rendered pull requests to that range. The output can be piped as well. For example `work -c | pbcopy` can be used to create the changelog and send it straight to your pasteboard on macOS.



## Configuration

This tool will ask for any required configuration. If you want to adjust default settings, you can add a JSON object to `.config/work` to adjust settings as necessary. Note: This should not be the case for anfema repositories.



## Credits

The changelog feature is more based on than inspired by [lerna-changelog](https://github.com/lerna/lerna-changelog) which didn't quite match what we needed. It's a great project to look at and learn.
16 changes: 0 additions & 16 deletions experiments.js

This file was deleted.

13 changes: 0 additions & 13 deletions lib/git/last-tag.js

This file was deleted.

49 changes: 0 additions & 49 deletions lib/git/tags.js

This file was deleted.

18 changes: 18 additions & 0 deletions lib/git/version-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const execa = require('execa');
const semver = require('semver');

module.exports = async () => {
try {
const { stdout: localTags } = await execa('git', ['tag']);

return localTags
.split('\n')
.map(semver.clean)
.filter(semver.valid)
.sort(semver.rcompare);
} catch (err) {
console.log(`Can't list version tags`, err);
}

return null;
};
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
"commander": "^2.17.1",
"conf": "^2.0.0",
"execa": "~1.0.0",
"get-stream": "~4.0.0",
"git-all-tags": "~1.0.0",
"git-commits": "~1.3.0",
"git-latest-semver-tag": "~1.0.2",
"git-repo-name": "~0.6.0",
"git-semver-tags": "~2.0.0",
"git-username": "~1.0.0",
"inquirer": "~6.2.0",
"lodash": "^4.17.10",
Expand Down
1 change: 1 addition & 0 deletions src/create-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module.exports = async ({ owner, repo, issue: number, username, branchFormat, de
}

try {
await execa('git', ['checkout', 'develop']);
await execa('git', ['checkout', '-b', branchName]);
await execa('git', ['push', '--set-upstream']);
} catch (err) {
Expand Down
17 changes: 5 additions & 12 deletions src/create-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const semver = require('semver');

const octokit = require('../lib/octokit.js');
const getCommits = require('../lib/git/get-commits.js');
const lastTag = require('../lib/git/last-tag.js');
const findPrId = require('../lib/git/find-pr-id.js');
const render = require('../lib/changelog/render.js');

Expand All @@ -16,19 +15,13 @@ const createChangelog = async ({
repo,
changelog: changelogCategories,
} = {}) => {
try {
if (!tagFrom) {
tagFrom = await lastTag();
}
} catch (err) {
console.log(`No tags found; can't create Changelog.`, err);

return;
}

try {
console.log(
chalk.green(`Rendering changelog from ${tagFrom}${tagTo ? ` to ${tagTo}` : ''}:`)
chalk.green(
`Rendering changelog from ${tagFrom ? tagFrom : 'Initial'}${
tagTo ? ` to ${tagTo}` : ''
}:`
)
);

let commits = await getCommits({ from: tagFrom, to: tagTo || '' });
Expand Down
71 changes: 71 additions & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module.exports = {
branchFormat: '[USERNAME]/[ISSUEID]-[DESCRIPTION]',
defaultBranch: 'develop',

cwd: process.cwd(),

prefixes: {
feature: 'Features',
bugfix: 'Fixed Bugs',
refactor: 'Improved Code',
test: 'Improved Tests',
chore: 'Miscellaneous',
},

changelog: {
'New Features & Improvements': ['Enhancement', 'Feature'],
'Fixed Bugs': ['Bug'],
'Behind the scenes': ['Refactor'],
'Other changes': ['Chore'],
},

tagFrom: '',
tagTo: 'HEAD',

// As of 2018-09-04
githubLabelstoDelete: [
'bug',
'duplicate',
'enhancement',
'good first issue',
'help wanted',
'invalid',
'question',
'wontfix',
],

defaultLabels: [
// Workflow columns
{ name: 'Status: To Do', color: '#73D0FF' },
{ name: 'Status: Blocked', color: '#363E4A' },
{ name: 'Status: In Progress', color: '#95E6CB' },
{ name: 'Status: Has PR', color: '#BAE67E' },
{ name: 'Status: To Test', color: '#FFC44C' },

// Types
{ name: 'Bug', color: '#EE0701' },
{ name: 'Change Request', color: '#D4BFFF' },
{ name: 'Chore', color: '#E3EFF8' },
{ name: 'Enhancement', color: '#0052CC' },
{ name: 'Needs Design', color: '#363E4A' },
{ name: 'Needs Discussion', color: '#363E4A' },
{ name: 'Refactor', color: '#E3EFF8' },
{ name: 'Test', color: '#CCC9C2' },

// Priority
{ name: 'Priority: Low', color: '#667380' },
{ name: 'Priority: !!!', color: '#FFA759' },

// Resolved states
{ name: 'Closed: Duplicate', color: '#FFFFFF' },
{ name: 'Closed: Invalid', color: '#FFFFFF' },
{ name: 'Closed: Wontfix', color: '#FFFFFF' },

// Managed by CodeTree
{ name: 'codetree-epic', color: '#FBF4EF' },
{ name: 'size: 1', color: '#FBF4EF' },
{ name: 'size: 2', color: '#FBF4EF' },
{ name: 'size: 4', color: '#FBF4EF' },
{ name: 'size: 8', color: '#FBF4EF' },
],
};
20 changes: 8 additions & 12 deletions src/program.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const program = require('commander');
const pkg = require('../package.json');
const defaults = require('./defaults.js');

program
.version(pkg.version)
.usage('[options]')
.option('-i, --issue [n]', 'Begin work on a specific issue')
.option('-c, --changelog [t..t]', 'Create changelog')
.option('-c, --changelog [t..t]', 'Render a changelog from Pull Requests')
.option('--sync-labels', 'Sync custom default labels to GitHub')
.option('--remove-labels', 'Remove GitHub default labels')
.option('--reset-config', 'Clears any configuration made (token, username, etc)')
Expand Down Expand Up @@ -36,23 +37,18 @@ if (program.resetConfig) {
args.task = 'reset-config';
}

if (program.changelog) {
if (program.changelog === true || typeof program.changelog === 'string') {
args.task = 'changelog';

let command = program.changelog;
if (typeof program.changelog === 'string') {
const [tagFrom, tagTo] = program.changelog.split('..');

command = command === true ? '' : command;

const range = command.split('..');
const [tagFrom, tagTo] = range;

if (tagFrom) {
args.tagFrom = tagFrom;
}

if (tagTo) {
args.tagTo = tagTo;
}

args.tagFrom = args.tagFrom || defaults.tagFrom;
args.tagTo = args.tagTo || defaults.tagTo;
}

module.exports = args;
56 changes: 56 additions & 0 deletions src/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ const chalk = require('chalk');
const inquirer = require('inquirer');
const termSize = require('term-size');

const defaults = require('./defaults.js');
const config = require('./config.js');
const settings = require('./settings.js');
const octokit = require('../lib/octokit.js');
const githubLogin = require('../lib/github/get-login.js');
const versionTags = require('../lib/git/version-tags.js');

const ask = async ({ owner, repo }, program) => {
if (!owner || !repo) {
Expand Down Expand Up @@ -210,6 +212,60 @@ const ask = async ({ owner, repo }, program) => {
results = Object.assign(results, answers);
}

if (results.task === 'changelog') {
const versions = await versionTags();

const answers = await inquirer.prompt([
{
name: 'tagFrom',
message: 'From where should the changelog start?',
type: 'list',
pageSize: Math.max(termSize().rows - 7, 5),
default: versions[0] || defaults.tagFrom,
choices: async () => {
return [
...versions,
{
name: 'Initial commit',
value: defaults.tagFrom,
short: 'Initial',
},
];
},
when() {
return program.tagFrom === undefined;
},
},
{
name: 'tagTo',
message: 'Where should the changelog end?',
type: 'list',
pageSize: Math.max(termSize().rows - 8, 5),
default: defaults.tagTo,
choices: async currentAnswers => {
const remainingVersions = versions.slice(
0,
versions.indexOf(currentAnswers.tagFrom)
);

return [
{
name: 'Current Head',
value: defaults.tagTo,
short: 'HEAD',
},
...remainingVersions,
];
},
when() {
return program.tagTo === undefined;
},
},
]);

results = Object.assign(results, answers);
}

results = Object.assign({}, program, results);

return results;
Expand Down
Loading

0 comments on commit 1b92ff9

Please sign in to comment.