You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-09 10:22:46 +03:00
When merging release notes, allow considering later versions in the same release cycle (#4085)
* When merging release notes, allow considering later versions in the same major.minor.patch set Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Tweak comments Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
b2e09250d9
commit
e4d4628cc8
@@ -2,23 +2,28 @@
|
|||||||
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
// Dependency can be the name of an entry in package.json, in which case the owner, repo & version will be looked up in its own package.json
|
async function listReleases(github, owner, repo) {
|
||||||
// Or it can be a string in the form owner/repo@tag
|
const response = await github.rest.repos.listReleases({
|
||||||
// Or it can be a tuple of dependency, from version, to version, in which case a list of releases in that range (to inclusive) will be returned
|
owner,
|
||||||
|
repo,
|
||||||
|
per_page: 100,
|
||||||
|
});
|
||||||
|
// Filters out draft releases
|
||||||
|
return response.data.filter((release) => !release.draft);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dependency can be a tuple of dependency, from version, to version, in which case a list of releases in that range (to inclusive) will be returned
|
||||||
|
// Or it can be a string in the form accepted by `getRelease`
|
||||||
async function getReleases(github, dependency) {
|
async function getReleases(github, dependency) {
|
||||||
if (Array.isArray(dependency)) {
|
if (Array.isArray(dependency)) {
|
||||||
const [dep, fromVersion, toVersion] = dependency;
|
const [dep, fromVersion, toVersion] = dependency;
|
||||||
const upstreamPackageJson = getDependencyPackageJson(dep);
|
const upstreamPackageJson = getDependencyPackageJson(dep);
|
||||||
const [owner, repo] = upstreamPackageJson.repository.url.split("/").slice(-2);
|
const [owner, repo] = upstreamPackageJson.repository.url.split("/").slice(-2);
|
||||||
|
|
||||||
const response = await github.rest.repos.listReleases({
|
const unfilteredReleases = await listReleases(github, owner, repo);
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
per_page: 100,
|
|
||||||
});
|
|
||||||
// Only include non-draft & non-prerelease releases, unless the to-release is a pre-release, include that one
|
// Only include non-draft & non-prerelease releases, unless the to-release is a pre-release, include that one
|
||||||
const releases = response.data.filter(
|
const releases = unfilteredReleases.filter(
|
||||||
(release) => !release.draft && (!release.prerelease || release.tag_name === `v${toVersion}`),
|
(release) => !release.prerelease || release.tag_name === `v${toVersion}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const fromVersionIndex = releases.findIndex((release) => release.tag_name === `v${fromVersion}`);
|
const fromVersionIndex = releases.findIndex((release) => release.tag_name === `v${fromVersion}`);
|
||||||
@@ -30,14 +35,35 @@ async function getReleases(github, dependency) {
|
|||||||
return [await getRelease(github, dependency)];
|
return [await getRelease(github, dependency)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dependency can be the name of an entry in package.json, in which case the owner, repo & version will be looked up in its own package.json
|
||||||
|
// Or it can be a string in the form owner/repo@tag - in this case the tag is used exactly to find the release
|
||||||
|
// Or it can be a string in the form owner/repo~tag - in this case the latest tag in the same major.minor.patch set is used to find the release
|
||||||
async function getRelease(github, dependency) {
|
async function getRelease(github, dependency) {
|
||||||
let owner;
|
let owner;
|
||||||
let repo;
|
let repo;
|
||||||
let tag;
|
let tag;
|
||||||
if (dependency.includes("/") && dependency.includes("@")) {
|
|
||||||
owner = dependency.split("/")[0];
|
if (dependency.includes("/")) {
|
||||||
repo = dependency.split("/")[1].split("@")[0];
|
let rest;
|
||||||
tag = dependency.split("@")[1];
|
[owner, rest] = dependency.split("/")[0];
|
||||||
|
|
||||||
|
if (dependency.includes("@")) {
|
||||||
|
[repo, tag] = rest.split("@");
|
||||||
|
} else if (dependency.includes("~")) {
|
||||||
|
[repo, tag] = rest.split("~");
|
||||||
|
|
||||||
|
if (tag.includes("-rc.")) {
|
||||||
|
// If the tag is an RC, find the latest matching RC in the set
|
||||||
|
try {
|
||||||
|
const releases = await listReleases(github, owner, repo);
|
||||||
|
const baseVersion = tag.split("-rc.")[0];
|
||||||
|
const release = releases.find((release) => release.tag_name.startsWith(baseVersion));
|
||||||
|
if (release) return release;
|
||||||
|
} catch (e) {
|
||||||
|
// Fall back to getReleaseByTag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const upstreamPackageJson = getDependencyPackageJson(dependency);
|
const upstreamPackageJson = getDependencyPackageJson(dependency);
|
||||||
[owner, repo] = upstreamPackageJson.repository.url.split("/").slice(-2);
|
[owner, repo] = upstreamPackageJson.repository.url.split("/").slice(-2);
|
||||||
@@ -129,7 +155,7 @@ if (require.main === module) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const [releaseId, ...dependencies] = process.argv.slice(2);
|
const [releaseId, ...dependencies] = process.argv.slice(2);
|
||||||
main({ github, releaseId, dependencies: ["matrix-react-sdk"] }).then((output) => {
|
main({ github, releaseId, dependencies }).then((output) => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(output);
|
console.log(output);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user