Skip to content
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@
"terser": "5.7.1",
"terser-webpack-plugin": "5.1.4",
"text-table": "0.2.0",
"through2": "^4.0.0",
"tree-kill": "1.2.2",
"ts-api-guardian": "0.6.0",
"ts-node": "^10.0.0",
Expand Down
63 changes: 35 additions & 28 deletions scripts/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as semver from 'semver';
import { Transform } from 'stream';
import { packages } from '../lib/packages';

const conventionalCommitsParser = require('conventional-commits-parser');
const ghGot = require('gh-got');
const gitRawCommits = require('git-raw-commits');
const through = require('through2');
const changelogTemplate = require('./templates/changelog').default;

export interface ChangelogOptions {
Expand Down Expand Up @@ -77,23 +77,27 @@ export default async function (args: ChangelogOptions, logger: logging.Logger) {
}

return new Promise((resolve) => {
(gitRawCommits({
from: args.from,
to: args.to || 'HEAD',
format: '%B%n-hash-%n%H%n-gitTags-%n%D%n-committerDate-%n%ci%n-authorName-%n%aN%n',
}) as NodeJS.ReadStream)
(
gitRawCommits({
from: args.from,
to: args.to || 'HEAD',
format: '%B%n-hash-%n%H%n-gitTags-%n%D%n-committerDate-%n%ci%n-authorName-%n%aN%n',
}) as NodeJS.ReadStream
)
.on('error', (err) => {
logger.fatal('An error happened: ' + err.message);
process.exit(1);
})
.pipe(
through((chunk: Buffer, enc: string, callback: Function) => {
// Replace github URLs with `@XYZ#123`
const commit = chunk
.toString('utf-8')
.replace(/https?:\/\/github.com\/(.*?)\/issues\/(\d+)/g, '@$1#$2');

callback(undefined, Buffer.from(commit));
new Transform({
transform(chunk, encoding, callback) {
// Replace github URLs with `@XYZ#123`
const commit = chunk
.toString('utf-8')
.replace(/https?:\/\/github.com\/(.*?)\/issues\/(\d+)/g, '@$1#$2');

callback(undefined, Buffer.from(commit));
},
}),
)
.pipe(
Expand All @@ -106,22 +110,25 @@ export default async function (args: ChangelogOptions, logger: logging.Logger) {
}),
)
.pipe(
through.obj((chunk: JsonObject, _: string, cb: Function) => {
try {
const maybeTag = chunk.gitTags && (chunk.gitTags as string).match(/tag: (.*)/);
const tags = maybeTag && maybeTag[1].split(/,/g);
chunk['tags'] = tags;

if (tags && tags.find((x) => x == args.to)) {
toSha = chunk.hash as string;
}
if (!cherryPicked.has(chunk.hash as string)) {
commits.push(chunk);
new Transform({
objectMode: true,
transform(chunk: JsonObject, encoding, callback) {
try {
const maybeTag = chunk.gitTags && (chunk.gitTags as string).match(/tag: (.*)/);
const tags = maybeTag && maybeTag[1].split(/,/g);
chunk['tags'] = tags;

if (tags && tags.find((x) => x == args.to)) {
toSha = chunk.hash as string;
}
if (!cherryPicked.has(chunk.hash as string)) {
commits.push(chunk);
}
callback();
} catch (err) {
callback(err);
}
cb();
} catch (err) {
cb(err);
}
},
}),
)
.on('finish', resolve);
Expand Down