@artsy/changelog 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/dist/changelogTemplateSections.d.ts +6 -0
- package/dist/changelogTemplateSections.js +9 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/parsePRDescription.d.ts +14 -0
- package/dist/parsePRDescription.js +70 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @artsy/changelog
|
|
2
|
+
|
|
3
|
+
Shared parser for Artsy's PR-description changelog convention. A single source of truth used by
|
|
4
|
+
both [eigen](https://github.com/artsy/eigen) (Danger + `generate-changelog`) and
|
|
5
|
+
[release-lookout](https://github.com/artsy/release-lookout) (release-candidate PR descriptions).
|
|
6
|
+
|
|
7
|
+
Artsy PRs declare release notes in four `####`-headed sections inside the PR body:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
#### Cross-platform user-facing changes
|
|
11
|
+
#### iOS user-facing changes
|
|
12
|
+
#### Android user-facing changes
|
|
13
|
+
#### Dev changes
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
This package parses a raw PR body into a structured result. It is intentionally **I/O-free** —
|
|
17
|
+
fetching PRs / determining ranges is left to each consumer.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { parsePRDescription, changelogTemplateSections } from "@artsy/changelog"
|
|
23
|
+
|
|
24
|
+
const result = parsePRDescription(pr.body)
|
|
25
|
+
|
|
26
|
+
switch (result.type) {
|
|
27
|
+
case "no_changes": // PR contains `#nochangelog`
|
|
28
|
+
break
|
|
29
|
+
case "error": // no changelog sections found / all empty
|
|
30
|
+
break
|
|
31
|
+
case "changes":
|
|
32
|
+
result.crossPlatformUserFacingChanges // string[]
|
|
33
|
+
result.iOSUserFacingChanges
|
|
34
|
+
result.androidUserFacingChanges
|
|
35
|
+
result.devChanges
|
|
36
|
+
break
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
- `parsePRDescription(body: string): ParseResult` — parse a PR body.
|
|
43
|
+
- `ParseResult` — `{ type: "no_changes" } | { type: "error" } | ({ type: "changes" } & ParseResultChanges)`.
|
|
44
|
+
- `changelogTemplateSections` — the section-key → section-title map.
|
|
45
|
+
|
|
46
|
+
## Development
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
yarn # install
|
|
50
|
+
yarn test # jest
|
|
51
|
+
yarn build # tsc → dist
|
|
52
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.changelogTemplateSections = void 0;
|
|
4
|
+
exports.changelogTemplateSections = {
|
|
5
|
+
androidUserFacingChanges: "Android user-facing changes",
|
|
6
|
+
crossPlatformUserFacingChanges: "Cross-platform user-facing changes",
|
|
7
|
+
devChanges: "Dev changes",
|
|
8
|
+
iOSUserFacingChanges: "iOS user-facing changes",
|
|
9
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.changelogTemplateSections = exports.parsePRDescription = void 0;
|
|
4
|
+
var parsePRDescription_1 = require("./parsePRDescription");
|
|
5
|
+
Object.defineProperty(exports, "parsePRDescription", { enumerable: true, get: function () { return parsePRDescription_1.parsePRDescription; } });
|
|
6
|
+
var changelogTemplateSections_1 = require("./changelogTemplateSections");
|
|
7
|
+
Object.defineProperty(exports, "changelogTemplateSections", { enumerable: true, get: function () { return changelogTemplateSections_1.changelogTemplateSections; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const parsePRDescription: (description: string) => ParseResult;
|
|
2
|
+
export declare type ParseResult = {
|
|
3
|
+
type: "error";
|
|
4
|
+
} | {
|
|
5
|
+
type: "no_changes";
|
|
6
|
+
} | ({
|
|
7
|
+
type: "changes";
|
|
8
|
+
} & ParseResultChanges);
|
|
9
|
+
export interface ParseResultChanges {
|
|
10
|
+
crossPlatformUserFacingChanges: string[];
|
|
11
|
+
iOSUserFacingChanges: string[];
|
|
12
|
+
androidUserFacingChanges: string[];
|
|
13
|
+
devChanges: string[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePRDescription = void 0;
|
|
4
|
+
const changelogTemplateSections_1 = require("./changelogTemplateSections");
|
|
5
|
+
const parsePRDescription = (description) => {
|
|
6
|
+
description = stripComments(description);
|
|
7
|
+
if (description.includes("#nochangelog")) {
|
|
8
|
+
return { type: "no_changes" };
|
|
9
|
+
}
|
|
10
|
+
const lines = description.split("\n").map((line) => line.trim());
|
|
11
|
+
const result = {
|
|
12
|
+
androidUserFacingChanges: [],
|
|
13
|
+
crossPlatformUserFacingChanges: [],
|
|
14
|
+
devChanges: [],
|
|
15
|
+
iOSUserFacingChanges: [],
|
|
16
|
+
type: "changes",
|
|
17
|
+
};
|
|
18
|
+
for (const [sectionKey, sectionTitle] of Object.entries(changelogTemplateSections_1.changelogTemplateSections)) {
|
|
19
|
+
let i = lines.indexOf("#### " + sectionTitle);
|
|
20
|
+
if (i === -1) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
i++;
|
|
24
|
+
// either a single text paragraph or a list.
|
|
25
|
+
const sectionLines = [];
|
|
26
|
+
while (i < lines.length && lines[i].match(/^( *\w|-[\w ]|\*[\w ]|\s*$)/)) {
|
|
27
|
+
sectionLines.push(lines[i]);
|
|
28
|
+
i++;
|
|
29
|
+
}
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
result[sectionKey] = groupItems(sectionLines);
|
|
32
|
+
}
|
|
33
|
+
if (result.androidUserFacingChanges.length === 0 &&
|
|
34
|
+
result.crossPlatformUserFacingChanges.length === 0 &&
|
|
35
|
+
result.devChanges.length === 0 &&
|
|
36
|
+
result.iOSUserFacingChanges.length === 0) {
|
|
37
|
+
return { type: "error" };
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
exports.parsePRDescription = parsePRDescription;
|
|
42
|
+
function stripComments(text) {
|
|
43
|
+
return text.replace(/<!--.*?-->/g, "");
|
|
44
|
+
}
|
|
45
|
+
function groupItems(lines) {
|
|
46
|
+
const result = [];
|
|
47
|
+
let group = [];
|
|
48
|
+
for (const line of lines) {
|
|
49
|
+
if (line.startsWith("-") || line.startsWith("*")) {
|
|
50
|
+
if (group.length) {
|
|
51
|
+
result.push(group.join("\n"));
|
|
52
|
+
}
|
|
53
|
+
group = [line.slice(1).trim()];
|
|
54
|
+
}
|
|
55
|
+
else if (line.match(/^\s*$/)) {
|
|
56
|
+
// paragraph
|
|
57
|
+
if (group.length) {
|
|
58
|
+
result.push(group.join("\n"));
|
|
59
|
+
}
|
|
60
|
+
group = [];
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
group.push(line.trim());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (group.length) {
|
|
67
|
+
result.push(group.join("\n"));
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@artsy/changelog",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared parser for Artsy PR-description changelog sections (used by eigen and release-lookout).",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"clean": "rm -rf dist",
|
|
12
|
+
"build": "npm run clean && tsc -p .",
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"watch": "tsc -w -p .",
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"type-check": "tsc --noEmit --pretty",
|
|
17
|
+
"release": "auto shipit"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/artsy/artsy-changelog.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"artsy",
|
|
25
|
+
"changelog",
|
|
26
|
+
"release"
|
|
27
|
+
],
|
|
28
|
+
"author": "Mounir Dhahri <mounir.dhahri@artsymail.com>",
|
|
29
|
+
"contributors": [
|
|
30
|
+
"Art.sy Inc <it@artsymail.com>"
|
|
31
|
+
],
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/artsy/artsy-changelog/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/artsy/artsy-changelog#readme",
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/jest": "^29.5.13",
|
|
39
|
+
"jest": "^29.7.0",
|
|
40
|
+
"ts-jest": "^29.2.5",
|
|
41
|
+
"typescript": "4.8.4"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"registry": "https://registry.npmjs.org/",
|
|
45
|
+
"access": "public"
|
|
46
|
+
}
|
|
47
|
+
}
|