mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Sort things by public/private
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
@@ -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
@@ -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();
|
||||||
|
});
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user