From 2238df955e907c55c71a28d3149462a2df648941 Mon Sep 17 00:00:00 2001 From: Bukowa Date: Tue, 25 Jun 2024 21:01:02 +0200 Subject: [PATCH] fix: use strategies for rust workspace plugin --- src/plugins/cargo-workspace.ts | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/plugins/cargo-workspace.ts b/src/plugins/cargo-workspace.ts index aa3f65784..0a6efe6f2 100644 --- a/src/plugins/cargo-workspace.ts +++ b/src/plugins/cargo-workspace.ts @@ -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 { /** @@ -79,6 +82,9 @@ interface CrateInfo { * into a single rust package. */ export class CargoWorkspace extends WorkspacePlugin { + private strategiesByPath: Record = {}; + private releasesByPath: Record = {}; + protected async buildAllPackages( candidates: CandidateReleasePullRequest[] ): Promise<{ @@ -252,6 +258,34 @@ export class CargoWorkspace extends WorkspacePlugin { 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([ @@ -367,6 +401,18 @@ export class CargoWorkspace extends WorkspacePlugin { protected pathFromPackage(pkg: CrateInfo): string { return pkg.path; } + + async preconfigure( + strategiesByPath: Record, + _commitsByPath: Record, + _releasesByPath: Record + ): Promise> { + // Using preconfigure to siphon releases and strategies. + this.strategiesByPath = strategiesByPath; + this.releasesByPath = _releasesByPath; + + return strategiesByPath; + } } function getChangelogDepsNotes(