Skip to content

Commit

Permalink
Use eslint-config-joyn
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Sep 27, 2020
1 parent 8e82807 commit 715d69a
Show file tree
Hide file tree
Showing 22 changed files with 1,008 additions and 422 deletions.
25 changes: 11 additions & 14 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
{
"extends": "holidaycheck/es2015",

"env": {
"node": true
},

"parserOptions": {
"ecmaVersion": "2017",
"ecmaFeatures": {
"globalReturn": false
}
},
"extends": ["joyn", "joyn/presets/node"],

"rules": {
"camelcase": "off"
},

"overrides": [
{
"files": [ "test/**/*.js" ],
"plugins": [ "ava" ],
"files": ["prettier.config.js"],
"extends": ["joyn/presets/commonjs"]
},
{
"files": ["bin/**/*.js", "lib/**/*.js", "test/**/*.js"],
"extends": ["joyn/presets/esm"]
},
{
"files": ["test/**/*.js"],
"plugins": ["ava"],
"rules": {
"max-statements": "off",
"ava/no-only-test": "error"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./build/coverage/lcov.info
path-to-lcov: ./target/coverage/lcov.info
parallel: true
coverage:
needs: build
Expand Down
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
*.iml
.idea
build
dist
node_modules
npm-debug.log
.nyc_output
target
dist
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
297 changes: 147 additions & 150 deletions CHANGELOG.md

Large diffs are not rendered by default.

103 changes: 52 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
[![Coverage Status](https://img.shields.io/coveralls/lo1tuma/pr-log/master.svg?style=flat)](https://coveralls.io/r/lo1tuma/pr-log)
[![Dependencies](https://img.shields.io/david/lo1tuma/pr-log.svg?style=flat)](https://david-dm.org/lo1tuma/pr-log)

-----
---

# pr-log

> Changelog generator based on GitHub Pull Requests
The main features:

* Writes in a `CHANGELOG.md` from merged GitHub pull requests since the last tag. This works by
* first getting a list of all tags
* than removing all tags that are not compatible to [semver versioning](http://semver.org/)
* sort the tags
* getting the git log from the last tag until now
* If no `CHANGELOG.md` existed, it will create the file else it will write prepending to it
* Friendly CLI
* Get usage by running `pr-log --help`
* Error messages that help correcting usage mistakes. E.g.
* Missing first command line argument: `Error: version-number not specified`
* Local branch is outdated compared to the remote branch: `Error: Local git master branch is 0 commits ahead and 2 commits behind of origin/master`
* The current working directory is not clean (e.g. contains files that are modified): `Error: Local copy is not clean`
* Well tested
- Writes in a `CHANGELOG.md` from merged GitHub pull requests since the last tag. This works by
- first getting a list of all tags
- than removing all tags that are not compatible to [semver versioning](http://semver.org/)
- sort the tags
- getting the git log from the last tag until now
- If no `CHANGELOG.md` existed, it will create the file else it will write prepending to it
- Friendly CLI
- Get usage by running `pr-log --help`
- Error messages that help correcting usage mistakes. E.g.
- Missing first command line argument: `Error: version-number not specified`
- Local branch is outdated compared to the remote branch: `Error: Local git master branch is 0 commits ahead and 2 commits behind of origin/master`
- The current working directory is not clean (e.g. contains files that are modified): `Error: Local copy is not clean`
- Well tested

## Install

Expand All @@ -41,48 +41,48 @@ You have to follow these steps to use `pr-log` without problems.

The following categories are defined by default:

| GitHub label | Human friendly name | Description |
| -------------:|:------------- | ------ |
| `breaking` | Breaking Changes | Backwards-incompatible changes |
| `bug` | Bug Fixes | Changes that only fix a bug |
| `feature` | Features | New features |
| `enhancement` | Enhancements | Non-breaking improvements of existing features |
| `documentation` | Documentation | Changes to documentation and/or README |
| `upgrade` | Dependency Upgrades | Any kind of dependency updates |
| `refactor` | Code Refactoring | Changes that don’t affect the behavior but improve the code quality |
| `build` | Build-Related | Changes related to the build process and/or CI/CD pipeline |
| GitHub label | Human friendly name | Description |
| --------------: | :------------------ | ------------------------------------------------------------------- |
| `breaking` | Breaking Changes | Backwards-incompatible changes |
| `bug` | Bug Fixes | Changes that only fix a bug |
| `feature` | Features | New features |
| `enhancement` | Enhancements | Non-breaking improvements of existing features |
| `documentation` | Documentation | Changes to documentation and/or README |
| `upgrade` | Dependency Upgrades | Any kind of dependency updates |
| `refactor` | Code Refactoring | Changes that don’t affect the behavior but improve the code quality |
| `build` | Build-Related | Changes related to the build process and/or CI/CD pipeline |

However, you can also create a custom mapping by adding a `pr-log.validLabels` section to your `package.json`.
`validLabels` must be specified as an array of key, value pairs. The same order will be used to format the changelog sections.
For example:

```json
{
"pr-log": {
"validLabels": [
[ "core", "Core features" ],
[ "addon", "Addons" ]
]
}
"pr-log": {
"validLabels": [
["core", "Core features"],
["addon", "Addons"]
]
}
}
```

To use `pr-log` your GitHub project needs some small configuration:

* Create the labels mentioned above (you can create GitHub labels from `Issues -> Labels -> New Label`)
* Set the correct label on your pull requests - you need to set exactly one label, multiple labels or one that is not recognized will throw an error
* Use correct semver versioning for your tags (e.g. `2.4.7`)
- Create the labels mentioned above (you can create GitHub labels from `Issues -> Labels -> New Label`)
- Set the correct label on your pull requests - you need to set exactly one label, multiple labels or one that is not recognized will throw an error
- Use correct semver versioning for your tags (e.g. `2.4.7`)

### Project

As `pr-log` reads repository information from your project you have to add the `repository` information in your `package.json`

```json
{
"repository": {
"type": "git",
"url": "https://github.com/<your username>/<your repository name>.git"
}
"repository": {
"type": "git",
"url": "https://github.com/<your username>/<your repository name>.git"
}
}
```

Expand All @@ -94,7 +94,7 @@ If you want to use a custom date format you can configure `pr-log.dateFormat` in

```json
{
"pr-log": { "dateFormat": "dd.MM.yyyy" }
"pr-log": { "dateFormat": "dd.MM.yyyy" }
}
```

Expand All @@ -110,9 +110,9 @@ Example:

Given the following setup:

* In GitHub a tag named `2.0.0` exists that is behind `master`
* A pull request (#13) was created since the last tag that has the label `breaking`
* A pull request (#22) was created since the last tag that has the label `documentation`
- In GitHub a tag named `2.0.0` exists that is behind `master`
- A pull request (#13) was created since the last tag that has the label `breaking`
- A pull request (#22) was created since the last tag that has the label `documentation`

`pr-log 2.0.0` creates a changelog with the following example content:

Expand All @@ -121,11 +121,11 @@ Given the following setup:

### Breaking Changes

* Use new (backwards incompatible) version of module XYZ (#13)
- Use new (backwards incompatible) version of module XYZ (#13)

### Documentation

* Fix some spelling mistakes in documentation. (#22)
- Fix some spelling mistakes in documentation. (#22)
```

### Options
Expand Down Expand Up @@ -156,13 +156,13 @@ If you need to authenticate `pr-log`, e.g. to access a private repo, you can set

Many projects have problems with their changelogs. Most of them try one of the following ways

* manually write change logs: This is error-prone and the log will not be consistent
* generating it from commit messages: As there are often far more commits than useful messages for the changelog, this will hide important features because there are too many to read everything
- manually write change logs: This is error-prone and the log will not be consistent
- generating it from commit messages: As there are often far more commits than useful messages for the changelog, this will hide important features because there are too many to read everything

Other challenges for good changelogs:

* Different categories (e.g. breaking changes)
* Only include changes starting from a certain tag
- Different categories (e.g. breaking changes)
- Only include changes starting from a certain tag

### More complete example `CHANGELOG.md`

Expand All @@ -173,15 +173,16 @@ After working for some time with the tool and having e.g. two releases, the file

### Breaking Changes

* Use new (backwards incompatible) version of module XYZ (#13)
- Use new (backwards incompatible) version of module XYZ (#13)

### Features

* Add fancy feature (#2)
*
- Add fancy feature (#2)
-

### Documentation

* Fix some spelling mistakes in documentation. (#22)
- Fix some spelling mistakes in documentation. (#22)

## 1.1.0 (November 3, 2014)
```
45 changes: 24 additions & 21 deletions bin/pr-log.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#!/usr/bin/env node

import path from 'path';
import { promisify } from 'util';
import program from 'commander';
import createGithubClient from '@octokit/rest';
import config from '../../package.json';
import createCliAgent from '../cli';
import path from 'path';
import prepend from 'prepend';
import { promisify } from 'util';
import ensureCleanLocalGitState from '../ensureCleanLocalGitState';
import getMergedPullRequestsFactory from '../getMergedPullRequests';
import createChangelogFactory from '../createChangelog';
import findRemoteAliasFactory from '../findRemoteAlias';
import git from 'git-promise';
import getPullRequestLabel from '../getPullRequestLabel';
import config from '../../package.json'; // eslint-disable-line import/no-unresolved
import createCliAgent from '../cli'; // eslint-disable-line import/no-unresolved

import ensureCleanLocalGitState from '../ensureCleanLocalGitState'; // eslint-disable-line import/no-unresolved

import getMergedPullRequestsFactory from '../getMergedPullRequests'; // eslint-disable-line import/no-unresolved

import createChangelogFactory from '../createChangelog'; // eslint-disable-line import/no-unresolved

import findRemoteAliasFactory from '../findRemoteAlias'; // eslint-disable-line import/no-unresolved

import getPullRequestLabel from '../getPullRequestLabel'; // eslint-disable-line import/no-unresolved

program
.version(config.version)
Expand All @@ -21,7 +26,7 @@ program
.usage('<version-number>')
.parse(process.argv);

// eslint-disable-next-line no-process-env
// eslint-disable-next-line node/no-process-env
const { GH_TOKEN } = process.env;

const changelogPath = path.join(process.cwd(), 'CHANGELOG.md');
Expand All @@ -44,16 +49,14 @@ const dependencies = {
};
const cliAgent = createCliAgent(dependencies);

cliAgent
.run(program.args[0], options, dependencies)
.catch((error) => {
let message = `Error: ${error.message}`;
cliAgent.run(program.args[0], options, dependencies).catch((error) => {
let message = `Error: ${error.message}`;

if (program.trace) {
message = error.stack;
}
if (program.trace) {
message = error.stack;
}

// eslint-disable-next-line no-console, no-warning-comments
console.error(message);
process.exitCode = 1;
});
// eslint-disable-next-line no-console
console.error(message);
process.exitCode = 1;
});
8 changes: 1 addition & 7 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ function validateVersionnumber(versionNumber) {
}

export default function createCliAgent(dependencies) {
const {
ensureCleanLocalGitState,
getMergedPullRequests,
createChangelog,
packageInfo,
prependFile
} = dependencies;
const { ensureCleanLocalGitState, getMergedPullRequests, createChangelog, packageInfo, prependFile } = dependencies;

async function generateChangelog(options, githubRepo, validLabels, newVersionNumber) {
if (!options.sloppy) {
Expand Down
6 changes: 3 additions & 3 deletions lib/createChangelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function formatSection(displayLabel, pullRequests, repo) {
return `### ${displayLabel}\n\n${formatListOfPullRequests(pullRequests, repo)}\n`;
}

export default ({ getCurrentDate, packageInfo }) => {
export default function createModule({ getCurrentDate, packageInfo }) {
const defaultDateFormat = 'MMMM d, yyyy';
const { dateFormat = defaultDateFormat } = packageInfo['pr-log'] || {};

Expand All @@ -29,7 +29,7 @@ export default ({ getCurrentDate, packageInfo }) => {

let changelog = `${title}\n\n`;

for (const [ label, displayLabel ] of validLabels) {
for (const [label, displayLabel] of validLabels) {
const pullRequests = groupedPullRequests[label];

if (pullRequests) {
Expand All @@ -39,4 +39,4 @@ export default ({ getCurrentDate, packageInfo }) => {

return changelog;
};
};
}
Loading

0 comments on commit 715d69a

Please sign in to comment.