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: use strategies for cargo workspace plugin (rust) #2320

Merged
merged 2 commits into from
Sep 11, 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
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
Loading