Skip to content

Commit

Permalink
only use go import updaters when there is a major version update (#188)
Browse files Browse the repository at this point in the history
* only use go import updaters when there is a major version update

* fix tests
  • Loading branch information
meorphis authored Nov 8, 2024
1 parent af737fd commit 52ca9f6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
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

0 comments on commit 52ca9f6

Please sign in to comment.