Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pr labels #75

Merged
merged 1 commit into from
Nov 1, 2019
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
41 changes: 30 additions & 11 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import { compareAsc, format, isBefore } from 'date-fns';
import gitRemoteOriginUrl from 'git-remote-origin-url';
import parseGithubUrl from 'parse-github-url';

const UNLABELLED = 'unlabelled';

const labelHeadings: { [label: string]: string } = {
breaking: ':boom: Breaking Change',
bug: ':bug: Bug Fix',
documentation: ':memo: Documentation',
enhancement: ':rocket: Enhancement',
internal: ':house: Internal',
unlabelled: ':question: Unlabelled'
};

const getRepoInfo = async () => {
const url = await gitRemoteOriginUrl();
const parsed = parseGithubUrl(url);
Expand Down Expand Up @@ -73,6 +84,7 @@ const changelog = async ({
const cleanedPulls = rawPulls
.filter(pull => Boolean(pull.merged_at))
.map(pull => ({
label: pull.labels.length ? pull.labels[0].name : UNLABELLED,
mergedAt: pull.merged_at,
number: pull.number,
title: pull.title,
Expand All @@ -92,7 +104,9 @@ const changelog = async ({
): Promise<{
date: string;
name: string;
pulls: typeof cleanedPulls;
pulls: {
[label: string]: typeof cleanedPulls;
};
}> => {
const existingTagCommit = rawCommits.find(
commit => commit.sha === tag.commit.sha
Expand All @@ -102,7 +116,7 @@ const changelog = async ({
return {
date: existingTagCommit.commit.committer.date,
name: tag.name,
pulls: []
pulls: {}
};
}

Expand All @@ -115,7 +129,7 @@ const changelog = async ({
return {
date: latestTagCommit.committer.date,
name: tag.name,
pulls: []
pulls: {}
};
};

Expand All @@ -128,7 +142,7 @@ const changelog = async ({
cleanedTags.unshift({
date: new Date().toISOString(),
name: futureRelease,
pulls: []
pulls: {}
});
}
cleanedTags.sort((a, b) => compareAsc(new Date(a.date), new Date(b.date)));
Expand All @@ -139,7 +153,7 @@ const changelog = async ({
);
/* istanbul ignore else */
if (tag) {
tag.pulls.unshift(p);
tag.pulls[p.label] = [p, ...(tag.pulls[p.label] || [])];
}
});

Expand All @@ -160,12 +174,17 @@ const changelog = async ({
result += `[Full Changelog](https://github.com/${owner}/${repo}/compare/${array[index + 1].name}...${tag.name})\n`;
}

tag.pulls.map((pull, index: number) => {
if (index === 0) {
result += `\n**Merged pull requests:**\n\n`;
}
result += `- ${pull.title} [\#${pull.number}](https://github.com/${owner}/${repo}/pull/${pull.number}) ([${pull.userLogin}](${pull.userHtmlUrl}))\n`;
});
result += Object.keys(tag.pulls)
.sort()
.reduce(
(result, label) =>
(result += tag.pulls[label].reduce(
(result, pull) =>
(result += `- [\#${pull.number}](https://github.com/${owner}/${repo}/pull/${pull.number}) ${pull.title} ([${pull.userLogin}](${pull.userHtmlUrl}))\n`),
`\n#### ${labelHeadings[label]}\n\n`
)),
''
);

return result;
})
Expand Down
82 changes: 58 additions & 24 deletions test/__snapshots__/changelog.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ exports[`can create a future release 1`] = `
## [v2.0.0](https://github.com/owner/repo/tree/v2.0.0) (2000-02-01)
[Full Changelog](https://github.com/owner/repo/compare/v1.0.0...v2.0.0)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 2 [#2](https://github.com/owner/repo/pull/2) ([user](https://github.com/user))
- [#2](https://github.com/owner/repo/pull/2) Pull request 2 ([user](https://github.com/user))

## [v1.0.0](https://github.com/owner/repo/tree/v1.0.0) (2000-01-31)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 1 [#1](https://github.com/owner/repo/pull/1) ([user](https://github.com/user))
- [#1](https://github.com/owner/repo/pull/1) Pull request 1 ([user](https://github.com/user))
"
`;

Expand All @@ -23,9 +23,9 @@ exports[`can infer repo info 1`] = `

## [v1.0.0](https://github.com/owner/repo/tree/v1.0.0) (2000-01-31)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 1 [#1](https://github.com/owner/repo/pull/1) ([user](https://github.com/user))
- [#1](https://github.com/owner/repo/pull/1) Pull request 1 ([user](https://github.com/user))
"
`;

Expand All @@ -35,15 +35,49 @@ exports[`handles GitHub API pagination 1`] = `
## [v2.0.0](https://github.com/owner/repo/tree/v2.0.0) (2000-02-01)
[Full Changelog](https://github.com/owner/repo/compare/v1.0.0...v2.0.0)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 2 [#2](https://github.com/owner/repo/pull/2) ([user](https://github.com/user))
- [#2](https://github.com/owner/repo/pull/2) Pull request 2 ([user](https://github.com/user))

## [v1.0.0](https://github.com/owner/repo/tree/v1.0.0) (2000-01-31)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 1 [#1](https://github.com/owner/repo/pull/1) ([user](https://github.com/user))
- [#1](https://github.com/owner/repo/pull/1) Pull request 1 ([user](https://github.com/user))
"
`;

exports[`handles PR labels 1`] = `
"# Changelog

## [v2.0.0](https://github.com/owner/repo/tree/v2.0.0) (2000-02-01)
[Full Changelog](https://github.com/owner/repo/compare/v1.0.0...v2.0.0)

#### :boom: Breaking Change

- [#6](https://github.com/owner/repo/pull/6) Pull request 6 ([user](https://github.com/user))

#### :bug: Bug Fix

- [#5](https://github.com/owner/repo/pull/5) Pull request 5 ([user](https://github.com/user))

#### :memo: Documentation

- [#4](https://github.com/owner/repo/pull/4) Pull request 4 ([user](https://github.com/user))

## [v1.0.0](https://github.com/owner/repo/tree/v1.0.0) (2000-01-31)

#### :rocket: Enhancement

- [#3](https://github.com/owner/repo/pull/3) Pull request 3 ([user](https://github.com/user))

#### :house: Internal

- [#2](https://github.com/owner/repo/pull/2) Pull request 2 ([user](https://github.com/user))

#### :question: Unlabelled

- [#1](https://github.com/owner/repo/pull/1) Pull request 1 ([user](https://github.com/user))
"
`;

Expand All @@ -53,17 +87,17 @@ exports[`handles multiple PRs per tag 1`] = `
## [v2.0.0](https://github.com/owner/repo/tree/v2.0.0) (2000-02-01)
[Full Changelog](https://github.com/owner/repo/compare/v1.0.0...v2.0.0)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 4 [#4](https://github.com/owner/repo/pull/4) ([user](https://github.com/user))
- Pull request 3 [#3](https://github.com/owner/repo/pull/3) ([user](https://github.com/user))
- [#4](https://github.com/owner/repo/pull/4) Pull request 4 ([user](https://github.com/user))
- [#3](https://github.com/owner/repo/pull/3) Pull request 3 ([user](https://github.com/user))

## [v1.0.0](https://github.com/owner/repo/tree/v1.0.0) (2000-01-31)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 2 [#2](https://github.com/owner/repo/pull/2) ([user](https://github.com/user))
- Pull request 1 [#1](https://github.com/owner/repo/pull/1) ([user](https://github.com/user))
- [#2](https://github.com/owner/repo/pull/2) Pull request 2 ([user](https://github.com/user))
- [#1](https://github.com/owner/repo/pull/1) Pull request 1 ([user](https://github.com/user))
"
`;

Expand All @@ -73,15 +107,15 @@ exports[`only uses merged PRs 1`] = `
## [v2.0.0](https://github.com/owner/repo/tree/v2.0.0) (2000-01-31)
[Full Changelog](https://github.com/owner/repo/compare/v1.0.0...v2.0.0)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 2 [#2](https://github.com/owner/repo/pull/2) ([user](https://github.com/user))
- [#2](https://github.com/owner/repo/pull/2) Pull request 2 ([user](https://github.com/user))

## [v1.0.0](https://github.com/owner/repo/tree/v1.0.0) (2000-01-30)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 1 [#1](https://github.com/owner/repo/pull/1) ([user](https://github.com/user))
- [#1](https://github.com/owner/repo/pull/1) Pull request 1 ([user](https://github.com/user))
"
`;

Expand All @@ -91,14 +125,14 @@ exports[`refetches missing tag commits 1`] = `
## [v2.0.0](https://github.com/owner/repo/tree/v2.0.0) (2000-02-01)
[Full Changelog](https://github.com/owner/repo/compare/v1.0.0...v2.0.0)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 1 [#1](https://github.com/owner/repo/pull/1) ([user](https://github.com/user))
- [#1](https://github.com/owner/repo/pull/1) Pull request 1 ([user](https://github.com/user))

## [v1.0.0](https://github.com/owner/repo/tree/v1.0.0) (2000-01-31)

**Merged pull requests:**
#### :question: Unlabelled

- Pull request 2 [#2](https://github.com/owner/repo/pull/2) ([user](https://github.com/user))
- [#2](https://github.com/owner/repo/pull/2) Pull request 2 ([user](https://github.com/user))
"
`;
Loading