1
- import pMap from "p-map" ;
1
+ const pMap = require ( "p-map" ) ;
2
+ const { resolve, sep } = require ( "path" ) ;
3
+
2
4
import progressBar from "./progress-bar" ;
3
5
import { Configuration } from "./configuration" ;
6
+ import findPullRequestId from "./find-pull-request-id" ;
4
7
import * as Git from "./git" ;
5
8
import GithubAPI , { GitHubUserResponse } from "./github-api" ;
6
9
import { CommitInfo , Release } from "./interfaces" ;
7
10
import MarkdownRenderer from "./markdown-renderer" ;
8
11
9
- import { resolve , sep } from "path" ;
10
-
11
12
const UNRELEASED_TAG = "___unreleased___" ;
12
13
13
14
interface Options {
@@ -65,7 +66,7 @@ export default class Changelog {
65
66
const commits = await this . getCommitInfos ( from , to ) ;
66
67
67
68
// Step 6: Group commits by release (local)
68
- const releases = this . groupByRelease ( commits ) ;
69
+ let releases = this . groupByRelease ( commits ) ;
69
70
70
71
// Step 7: Compile list of committers in release (local + remote)
71
72
await this . fillInContributors ( releases ) ;
@@ -74,7 +75,8 @@ export default class Changelog {
74
75
}
75
76
76
77
private async getListOfUniquePackages ( sha : string ) : Promise < string [ ] > {
77
- const changedPaths = await Git . changedPaths ( sha ) ;
78
+ let changedPaths = await Git . changedPaths ( sha ) ;
79
+
78
80
return changedPaths
79
81
. map ( path => this . packageFromPath ( path ) )
80
82
. filter ( Boolean )
@@ -90,7 +92,7 @@ export default class Changelog {
90
92
// ember-fastboot
91
93
// ember-fastboot-2-fast-2-furious
92
94
const foundPackage = this . config . packages . find ( p => {
93
- const withSlash = p . path . endsWith ( sep ) ? p . path : `${ p . path } ${ sep } ` ;
95
+ let withSlash = p . path . endsWith ( sep ) ? p . path : `${ p . path } ${ sep } ` ;
94
96
95
97
return absolutePath . startsWith ( withSlash ) ;
96
98
} ) ;
@@ -128,7 +130,7 @@ export default class Changelog {
128
130
for ( const commit of commits ) {
129
131
const issue = commit . githubIssue ;
130
132
const login = issue && issue . user && issue . user . login ;
131
- // If a list of `ignoreCommitters` is provided in the lernaon config
133
+ // If a list of `ignoreCommitters` is provided in the lerna.json config
132
134
// check if the current committer should be kept or not.
133
135
const shouldKeepCommiter = login && ! this . ignoreCommitter ( login ) ;
134
136
if ( login && shouldKeepCommiter && ! committers [ login ] ) {
@@ -159,13 +161,15 @@ export default class Changelog {
159
161
. map ( ref => ref . substr ( TAG_PREFIX . length ) ) ;
160
162
}
161
163
164
+ const issueNumber = findPullRequestId ( message ) ;
165
+
162
166
return {
163
167
commitSHA : sha ,
164
168
message,
165
169
// Note: Only merge commits or commits referencing an issue / PR
166
170
// will be kept in the changelog.
167
171
tags : tagsInCommit ,
168
- issueNumber : null ,
172
+ issueNumber,
169
173
date,
170
174
} as CommitInfo ;
171
175
} ) ;
@@ -176,11 +180,8 @@ export default class Changelog {
176
180
await pMap (
177
181
commitInfos ,
178
182
async ( commitInfo : CommitInfo ) => {
179
- const issueData = await this . github . getPullRequest ( this . config . repo , commitInfo . commitSHA ) ;
180
-
181
- if ( issueData ) {
182
- commitInfo . issueNumber = issueData . number . toString ( ) ;
183
- commitInfo . githubIssue = issueData ;
183
+ if ( commitInfo . issueNumber ) {
184
+ commitInfo . githubIssue = await this . github . getIssueData ( this . config . repo , commitInfo . issueNumber ) ;
184
185
}
185
186
186
187
progressBar . tick ( ) ;
@@ -194,7 +195,7 @@ export default class Changelog {
194
195
// Analyze the commits and group them by tag.
195
196
// This is useful to generate multiple release logs in case there are
196
197
// multiple release tags.
197
- const releaseMap : { [ id : string ] : Release } = { } ;
198
+ let releaseMap : { [ id : string ] : Release } = { } ;
198
199
199
200
let currentTags = [ UNRELEASED_TAG ] ;
200
201
for ( const commit of commits ) {
@@ -209,11 +210,11 @@ export default class Changelog {
209
210
// referencing them.
210
211
for ( const currentTag of currentTags ) {
211
212
if ( ! releaseMap [ currentTag ] ) {
212
- const date = currentTag === UNRELEASED_TAG ? this . getToday ( ) : commit . date ;
213
+ let date = currentTag === UNRELEASED_TAG ? this . getToday ( ) : commit . date ;
213
214
releaseMap [ currentTag ] = { name : currentTag , date, commits : [ ] } ;
214
215
}
215
216
216
- const prUserLogin = commit . githubIssue ?. user ? .login ;
217
+ let prUserLogin = commit . githubIssue ?. user . login ;
217
218
if ( prUserLogin && ! this . ignoreCommitter ( prUserLogin ) ) {
218
219
releaseMap [ currentTag ] . commits . push ( commit ) ;
219
220
}
@@ -235,10 +236,10 @@ export default class Changelog {
235
236
const labels = commit . githubIssue . labels . map ( label => label . name . toLowerCase ( ) ) ;
236
237
237
238
if ( this . config . wildcardLabel ) {
238
- // check whether the commit has any of the labels from the learnaon config.
239
+ // check whether the commit has any of the labels from the learna.json config.
239
240
// If not, label this commit with the provided label
240
241
241
- const foundLabel = Object . keys ( this . config . labels ) . some ( label => labels . indexOf ( label . toLowerCase ( ) ) !== - 1 ) ;
242
+ let foundLabel = Object . keys ( this . config . labels ) . some ( label => labels . indexOf ( label . toLowerCase ( ) ) !== - 1 ) ;
242
243
243
244
if ( ! foundLabel ) {
244
245
labels . push ( this . config . wildcardLabel ) ;
0 commit comments