Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comparison link generation #1378

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
69 changes: 30 additions & 39 deletions .github/scripts/generate-release-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,49 @@ import path from "path";
type Await<T> = T extends PromiseLike<infer U> ? U : T;
type Commits = Await<ReturnType<Octokit["rest"]["repos"]["compareCommits"]>>["data"]["commits"];

function getCompareLink(packageName: string, previousTag: string, newTag: string) {
// Previous
let previousPackage: string;
function getPackageInfo(tag: string, packageName: string) {
let packageInfo: string;
try {
previousPackage = execSync(
`git show ${previousTag}:../../Cargo.lock | grep ${packageName}? | head -1 | grep -o '".*"'`
packageInfo = execSync(
`git show ${tag}:../../Cargo.lock | grep ${packageName}? | grep source | head -1 | grep -o '".*"'`
).toString();
} catch (error) {
console.error('An error occurred while executing the shell command:', error);
return ""
return null;
}

const previousCommitTmp = /#([0-9a-f]*)/g.exec(previousPackage);
if (previousCommitTmp == null) { // regexp didn't match
return ""
};
const previousCommit = previousCommitTmp[1].slice(0, 8);

const previousRepoTmp = /(https:\/\/.*)\?/g.exec(previousPackage);
if (previousRepoTmp == null) {
return ""
};
const previousRepo = previousRepoTmp[1];
const commitMatch = /#([0-9a-f]*)/g.exec(packageInfo);
if (commitMatch == null) {
return null;
}
const commit = commitMatch[1].slice(0, 8);

// New
let newPackage: string;
try {
newPackage = execSync(
`git show ${newTag}:../../Cargo.lock | grep ${packageName}? | head -1 | grep -o '".*"'`
).toString();
} catch (error) {
console.error('An error occurred while executing the shell command:', error);
return ""
const repoMatch = /(https:\/\/.*)\?/g.exec(packageInfo);
if (repoMatch == null) {
return null;
}
const repo = repoMatch[1];

const newCommitTmp = /#([0-9a-f]*)/g.exec(newPackage)
if (newCommitTmp == null) {
return ""
};
const newCommit = newCommitTmp[1].slice(0, 8);
return { commit, repo };
}

const newRepoTmp = /(https:\/\/.*)\?/g.exec(newPackage);
if (newRepoTmp == null) {
return ""
function getCompareLink(packageName: string, previousTag: string, newTag: string) {
const previousPackageInfo = getPackageInfo(previousTag, packageName);
if (previousPackageInfo == null) {
return "";
}
const newRepo = newRepoTmp[1];
const newRepoOrganization = /github.com\/([^\/]*)/g.exec(newRepo)[1];

const newPackageInfo = getPackageInfo(newTag, packageName);
if (newPackageInfo == null) {
return "";
}

const newRepoOrganization = /github.com\/([^\/]*)/g.exec(newPackageInfo.repo)[1];

const diffLink =
previousRepo !== newRepo
? `${previousRepo}/compare/${previousCommit}...${newRepoOrganization}:${newCommit}`
: `${previousRepo}/compare/${previousCommit}...${newCommit}`;
previousPackageInfo.repo !== newPackageInfo.repo
? `${previousPackageInfo.repo}/compare/${previousPackageInfo.commit}...${newRepoOrganization}:${newPackageInfo.commit}`
: `${previousPackageInfo.repo}/compare/${previousPackageInfo.commit}...${newPackageInfo.commit}`;

return diffLink;
}
Expand Down
Loading