Skip to content

Commit

Permalink
fix: use strategies for rust workspace plugin (#2320)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukowa authored Sep 11, 2024
1 parent 88dc416 commit 427db6d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/plugins/cargo-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ import {BranchName} from '../util/branch-name';
import {PatchVersionUpdate} from '../versioning-strategy';
import {CargoLock} from '../updaters/rust/cargo-lock';
import {ConfigurationError} from '../errors';
import {Strategy} from '../strategy';
import {Commit} from '../commit';
import {Release} from '../release';

interface CrateInfo {
/**
Expand Down Expand Up @@ -79,6 +82,9 @@ interface CrateInfo {
* into a single rust package.
*/
export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
private strategiesByPath: Record<string, Strategy> = {};
private releasesByPath: Record<string, Release> = {};

protected async buildAllPackages(
candidates: CandidateReleasePullRequest[]
): Promise<{
Expand Down Expand Up @@ -252,6 +258,34 @@ export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
originalManifest,
updatedManifest
);

const updatedPackage = {
...pkg,
version: version.toString(),
};

const strategy = this.strategiesByPath[updatedPackage.path];
const latestRelease = this.releasesByPath[updatedPackage.path];
const basePullRequest = strategy
? await strategy.buildReleasePullRequest([], latestRelease, false, [], {
newVersion: version,
})
: undefined;

if (basePullRequest) {
return this.updateCandidate(
{
path: pkg.path,
pullRequest: basePullRequest,
config: {
releaseType: 'rust',
},
},
pkg,
updatedVersions
);
}

const pullRequest: ReleasePullRequest = {
title: PullRequestTitle.ofTargetBranch(this.targetBranch),
body: new PullRequestBody([
Expand Down Expand Up @@ -367,6 +401,18 @@ export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
protected pathFromPackage(pkg: CrateInfo): string {
return pkg.path;
}

async preconfigure(
strategiesByPath: Record<string, Strategy>,
_commitsByPath: Record<string, Commit[]>,
_releasesByPath: Record<string, Release>
): Promise<Record<string, Strategy>> {
// Using preconfigure to siphon releases and strategies.
this.strategiesByPath = strategiesByPath;
this.releasesByPath = _releasesByPath;

return strategiesByPath;
}
}

function getChangelogDepsNotes(
Expand Down

0 comments on commit 427db6d

Please sign in to comment.