Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Pichler committed Sep 5, 2018
1 parent 1442f4b commit 8a6a2e9
Show file tree
Hide file tree
Showing 34 changed files with 3,575 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_size = 4

[{package.json,*.{yaml,yml},bower.json}]
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false

[*.{diff,md}]
trim_trailing_whitespace = false
33 changes: 33 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

# Disabled because eslint-plugin-prettier chokes on this,
# because ember-cli-eslint is naive
# root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_size = 4

[{package.json,config/*.json}]
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false

[*.{diff,md}]
trim_trailing_whitespace = false

[*.{yaml,yml}]
indent_style = space
indent_size = 2

[.prettierrc]
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: 'anfema/node',
};
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.workrc
16 changes: 16 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.hbs
*.yaml
*.yml
.editorconfig
.eslintignore
.git
.gitignore
.ignore
.stylelintignore
dist
node_modules
package.json
public
tmp
vendor
yarn.lock
19 changes: 19 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
bracketSpacing: true
jsxBracketSameLine: false
printWidth: 100
semi: true
singleQuote: true
tabWidth: 4
trailingComma: es5
useTabs: true
overrides:
-
files: '{.watchmanconfig,.ember-cli,config/*.json}'
options:
parser: json
-
files: '*.yaml'
options:
parser: yaml
useTabs: false
tabWidth: 2
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,21 @@ And

- Batch update GitHub labels


## Installation

If you have Node.js and Yarn installed, you can use install via:

```sh
yarn global add anfema/work
```


## 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.
3 changes: 3 additions & 0 deletions bin/work
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../index.js');
16 changes: 16 additions & 0 deletions experiments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const createChangelog = require('./src/create-changelog.js');
const { owner, repo } = require('./lib/git/github-info.js');

(async () => {
await createChangelog({
tagFrom: '1.0.0',
owner,
repo,
changelog: {
'New Features & Improvements': ['Enhancement', 'Feature'],
'Behind the scenes': ['Refactor'],
'Fixed Bugs': ['Bug'],
'Other changes': ['Chore'],
},
});
})();
56 changes: 56 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const chalk = require('chalk');

const config = require('./src/config.js');
const githubInfo = require('./lib/git/github-info.js');
const program = require('./src/program.js');
const questions = require('./src/questions.js');
const settings = require('./src/settings.js');

const createBranch = require('./src/create-branch.js');
const createChangelog = require('./src/create-changelog.js');
const createLabels = require('./src/create-labels.js');
const deleteLabels = require('./src/delete-labels.js');

(async () => {
try {
const answers = await questions(githubInfo, program);
const results = Object.assign({}, config.store, settings, githubInfo, answers);

switch (results.task) {
case 'branch':
await createBranch(results);

break;

case 'pr':
console.log(chalk.blue(`Pull Requests are not implemented yet`));

break;

case 'changelog':
await createChangelog(results);

break;

case 'gh-remove-default-labels':
await deleteLabels(results);

break;

case 'gh-sync-custom-labels':
await createLabels(results);

break;

case 'reset-config':
config.clear();

break;

default:
break;
}
} catch (err) {
console.error(err);
}
})();
88 changes: 88 additions & 0 deletions lib/changelog/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const chalk = require('chalk');
const { highlight } = require('cli-highlight');
const { template, sortBy } = require('lodash');

const changelogTemplate = template(`<%
versions.forEach(version => {
%>
## <%= version.version %>
<%
version.categories.forEach(category => {
%>
### <%=
category.title
%>
<%
category.entries.forEach(entry => {
%>- #<%=
entry.pr.number
%><%
if (entry.otherLabels.length > 0) {
%> [<%=
entry.otherLabels.join(', ')
%>]<%
}
%> <%=
entry.pr.title
%> @<%=
entry.pr.user.login
%>
<%
})
%><%
})
%><%
})
%>
`);

module.exports = function render(data) {
const payload = {
versions: [...data.entries()].reduce((versions, [version, { commits, categories }]) => {
if (commits.length > 0) {
versions.push({
version,
categories: [...categories.entries()].reduce((acc, [title, entries]) => {
if (entries.size === 0) {
return acc;
}

entries = [...entries.values()];
entries = sortBy(entries, entry => entry.pr.number);

acc.push({
title,
entries,
});

return acc;
}, []),
});
}

return versions;
}, []),
};

if (payload.versions.length === 0) {
console.error(chalk.yellow(`No pull requests in selected range.`));

return '';
}

const rendered = changelogTemplate(payload);

if (chalk.enabled) {
return highlight(rendered, {
language: 'Markdown',
theme: {
section: chalk.bold.blue,
string: chalk.gray,
link: chalk.dim,
},
});
}

return rendered;
};
30 changes: 30 additions & 0 deletions lib/git/branch-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const execa = require('execa');
const { trim } = require('lodash');

module.exports = async () => {
const { stdout } = await execa('git', ['branch', '-a', '--no-color']);

const branches = stdout.split('\n').reduce(
(acc, branch) => {
branch = trim(branch);

if (branch.substring(0, 2) === '* ') {
acc.current = branch.substring(2);
acc.local.push(acc.current);
} else if (branch.match(/^remotes\//)) {
acc.remote.push(branch.substring(8));
} else {
acc.local.push(branch);
}

return acc;
},
{
current: undefined,
local: [],
remote: [],
}
);

return branches;
};
18 changes: 18 additions & 0 deletions lib/git/find-pr-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = message => {
const lines = message.split('\n');
const firstLine = lines[0];

const mergeMatch = firstLine.match(/^Merge pull request #(\d+) from /);

if (mergeMatch) {
return mergeMatch[1];
}

const squashMergeMatch = firstLine.match(/\(#(\d+)\)$/);

if (squashMergeMatch) {
return squashMergeMatch[1];
}

return null;
};
32 changes: 32 additions & 0 deletions lib/git/get-commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const execa = require('execa');

const commits = async ({ from = '', to = '' } = {}) => {
to = to || 'HEAD';

try {
const args = ['log', '--oneline', '--pretty=%H;%D;%s;%cd', '--date=short'];

if (from) {
args.push(`${from}..${to}`);
}

const { stdout } = await execa('git', args);

return stdout
.split('\n')
.filter(Boolean)
.map(commit => {
const parts = commit.split(';');
const sha = parts[0];
const refName = parts[1];
const summary = parts[2];
const date = parts[3];

return { sha, refName, summary, date };
});
} catch (err) {
console.log('Error requesting commits', err);
}
};

module.exports = commits;
13 changes: 13 additions & 0 deletions lib/git/github-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const gitRepoName = require('git-repo-name');
const gitUsername = require('git-username');

module.exports = (() => {
try {
return {
repo: gitRepoName.sync(),
owner: gitUsername(),
};
} catch (err) {
return {};
}
})();
Loading

0 comments on commit 8a6a2e9

Please sign in to comment.