Skip to content

Commit 427db6d

Browse files
authored
fix: use strategies for rust workspace plugin (#2320)
1 parent 88dc416 commit 427db6d

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/plugins/cargo-workspace.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import {BranchName} from '../util/branch-name';
3838
import {PatchVersionUpdate} from '../versioning-strategy';
3939
import {CargoLock} from '../updaters/rust/cargo-lock';
4040
import {ConfigurationError} from '../errors';
41+
import {Strategy} from '../strategy';
42+
import {Commit} from '../commit';
43+
import {Release} from '../release';
4144

4245
interface CrateInfo {
4346
/**
@@ -79,6 +82,9 @@ interface CrateInfo {
7982
* into a single rust package.
8083
*/
8184
export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
85+
private strategiesByPath: Record<string, Strategy> = {};
86+
private releasesByPath: Record<string, Release> = {};
87+
8288
protected async buildAllPackages(
8389
candidates: CandidateReleasePullRequest[]
8490
): Promise<{
@@ -252,6 +258,34 @@ export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
252258
originalManifest,
253259
updatedManifest
254260
);
261+
262+
const updatedPackage = {
263+
...pkg,
264+
version: version.toString(),
265+
};
266+
267+
const strategy = this.strategiesByPath[updatedPackage.path];
268+
const latestRelease = this.releasesByPath[updatedPackage.path];
269+
const basePullRequest = strategy
270+
? await strategy.buildReleasePullRequest([], latestRelease, false, [], {
271+
newVersion: version,
272+
})
273+
: undefined;
274+
275+
if (basePullRequest) {
276+
return this.updateCandidate(
277+
{
278+
path: pkg.path,
279+
pullRequest: basePullRequest,
280+
config: {
281+
releaseType: 'rust',
282+
},
283+
},
284+
pkg,
285+
updatedVersions
286+
);
287+
}
288+
255289
const pullRequest: ReleasePullRequest = {
256290
title: PullRequestTitle.ofTargetBranch(this.targetBranch),
257291
body: new PullRequestBody([
@@ -367,6 +401,18 @@ export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
367401
protected pathFromPackage(pkg: CrateInfo): string {
368402
return pkg.path;
369403
}
404+
405+
async preconfigure(
406+
strategiesByPath: Record<string, Strategy>,
407+
_commitsByPath: Record<string, Commit[]>,
408+
_releasesByPath: Record<string, Release>
409+
): Promise<Record<string, Strategy>> {
410+
// Using preconfigure to siphon releases and strategies.
411+
this.strategiesByPath = strategiesByPath;
412+
this.releasesByPath = _releasesByPath;
413+
414+
return strategiesByPath;
415+
}
370416
}
371417

372418
function getChangelogDepsNotes(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy