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

only use go import updaters when there is a major version update #188

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
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
50 changes: 26 additions & 24 deletions src/strategies/go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,36 @@ export class Go extends BaseStrategy {
}),
});

updates.push({
path: this.addPath('go.mod'),
createIfMissing: false,
updater: new GoModUpdater({
version,
}),
});

const goFiles = await this.github.findFilesByGlobAndRef(
'**/*.go',
this.changesBranch
);

// handle code snippets in markdown files as well
const mdFiles = await this.github.findFilesByGlobAndRef(
'**/*.md',
this.changesBranch
);

for (const file of [...goFiles, ...mdFiles]) {
if (version.major >= 2 && options.latestVersion?.major !== version.major) {
updates.push({
path: this.addPath(file),
createIfMissing: true,
updater: new GithubImportsGo({
path: this.addPath('go.mod'),
createIfMissing: false,
updater: new GoModUpdater({
version,
repository: this.repository,
}),
});

const goFiles = await this.github.findFilesByGlobAndRef(
'**/*.go',
this.changesBranch
);

// handle code snippets in markdown files as well
const mdFiles = await this.github.findFilesByGlobAndRef(
'**/*.md',
this.changesBranch
);

for (const file of [...goFiles, ...mdFiles]) {
updates.push({
path: this.addPath(file),
createIfMissing: true,
updater: new GithubImportsGo({
version,
repository: this.repository,
}),
});
}
}

return updates;
Expand Down
18 changes: 14 additions & 4 deletions test/strategies/go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const COMMITS = [
...buildMockConventionalCommit('chore: update common templates'),
];

const BREAKING_CHANGE = buildMockConventionalCommit('feat!: breaking change');

describe('Go', () => {
let github: GitHub;
beforeEach(async () => {
Expand Down Expand Up @@ -121,9 +123,13 @@ describe('Go', () => {
)
);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = undefined;
const latestRelease = {
tag: new TagName(Version.parse('1.0.0'), 'some-go-package'),
sha: 'abc123',
notes: 'some notes',
};
const release = await strategy.buildReleasePullRequest({
commits: COMMITS,
commits: [...COMMITS, ...BREAKING_CHANGE],
latestRelease,
});
const updates = release!.updates;
Expand All @@ -144,9 +150,13 @@ describe('Go', () => {
)
);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = undefined;
const latestRelease = {
tag: new TagName(Version.parse('1.0.0'), 'some-go-package'),
sha: 'abc123',
notes: 'some notes',
};
const release = await strategy.buildReleasePullRequest({
commits: COMMITS,
commits: [...COMMITS, ...BREAKING_CHANGE],
latestRelease,
});
const updates = release!.updates;
Expand Down
Loading