Sort things by public/private

This commit is contained in:
mitchellhamilton
2019-09-17 12:43:32 +10:00
parent 902339ecb3
commit 564f71feba
5 changed files with 70 additions and 5 deletions
+20
View File
@@ -1,5 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`it sorts the things right 1`] = `
Array [
Object {
"highestLevel": 3,
"name": "c",
"private": false,
},
Object {
"highestLevel": 1,
"name": "b",
"private": false,
},
Object {
"highestLevel": 3,
"name": "a",
"private": true,
},
]
`;
exports[`it works 1`] = ` exports[`it works 1`] = `
"### Major Changes "### Major Changes
+2 -2
View File
File diff suppressed because one or more lines are too long
+8 -2
View File
@@ -4,7 +4,12 @@ import * as github from "@actions/github";
import fs from "fs-extra"; import fs from "fs-extra";
import getWorkspaces, { Workspace } from "get-workspaces"; import getWorkspaces, { Workspace } from "get-workspaces";
import path from "path"; import path from "path";
import { getChangelogEntry, execWithOutput, getChangedPackages } from "./utils"; import {
getChangelogEntry,
execWithOutput,
getChangedPackages,
sortTheThings
} from "./utils";
import * as semver from "semver"; import * as semver from "semver";
(async () => { (async () => {
@@ -223,6 +228,7 @@ import * as semver from "semver";
); );
return { return {
highestLevel: entry.highestLevel, highestLevel: entry.highestLevel,
private: !!workspace.config.private,
content: content:
`## ${workspace.name}@${workspace.config.version}\n\n` + `## ${workspace.name}@${workspace.config.version}\n\n` +
entry.content entry.content
@@ -230,7 +236,7 @@ import * as semver from "semver";
}) })
)) ))
.filter(x => x) .filter(x => x)
.sort((a, b) => b.highestLevel - a.highestLevel) .sort(sortTheThings)
.map(x => x.content) .map(x => x.content)
.join("\n ") .join("\n ")
); );
+27 -1
View File
@@ -1,4 +1,9 @@
import { getChangelogEntry, BumpLevels, getChangedPackages } from "./utils"; import {
getChangelogEntry,
BumpLevels,
getChangedPackages,
sortTheThings
} from "./utils";
import tempy from "tempy"; import tempy from "tempy";
import { exec } from "@actions/exec"; import { exec } from "@actions/exec";
import * as fs from "fs-extra"; import * as fs from "fs-extra";
@@ -106,3 +111,24 @@ test("getChangedPackages works", async () => {
{ name: "some-package", dir, config: workspace } { name: "some-package", dir, config: workspace }
]); ]);
}); });
test("it sorts the things right", () => {
let things = [
{
name: "a",
highestLevel: BumpLevels.major,
private: true
},
{
name: "b",
highestLevel: BumpLevels.patch,
private: false
},
{
name: "c",
highestLevel: BumpLevels.major,
private: false
}
];
expect(things.sort(sortTheThings)).toMatchSnapshot();
});
+13
View File
@@ -124,3 +124,16 @@ export async function execWithOutput(
stderr: myError stderr: myError
}; };
} }
export function sortTheThings(
a: { private: boolean; highestLevel: number },
b: { private: boolean; highestLevel: number }
) {
if (a.private === b.private) {
return b.highestLevel - a.highestLevel;
}
if (a.private) {
return 1;
}
return -1;
}