Skip to content

Commit

Permalink
Fix comparison link generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Oct 31, 2024
1 parent 34ba5e6 commit 553026c
Showing 1 changed file with 30 additions and 39 deletions.
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

0 comments on commit 553026c

Please sign in to comment.