Skip to content

Commit 52ca9f6

Browse files
authored
only use go import updaters when there is a major version update (#188)
* only use go import updaters when there is a major version update * fix tests
1 parent af737fd commit 52ca9f6

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

src/strategies/go.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,36 @@ export class Go extends BaseStrategy {
3535
}),
3636
});
3737

38-
updates.push({
39-
path: this.addPath('go.mod'),
40-
createIfMissing: false,
41-
updater: new GoModUpdater({
42-
version,
43-
}),
44-
});
45-
46-
const goFiles = await this.github.findFilesByGlobAndRef(
47-
'**/*.go',
48-
this.changesBranch
49-
);
50-
51-
// handle code snippets in markdown files as well
52-
const mdFiles = await this.github.findFilesByGlobAndRef(
53-
'**/*.md',
54-
this.changesBranch
55-
);
56-
57-
for (const file of [...goFiles, ...mdFiles]) {
38+
if (version.major >= 2 && options.latestVersion?.major !== version.major) {
5839
updates.push({
59-
path: this.addPath(file),
60-
createIfMissing: true,
61-
updater: new GithubImportsGo({
40+
path: this.addPath('go.mod'),
41+
createIfMissing: false,
42+
updater: new GoModUpdater({
6243
version,
63-
repository: this.repository,
6444
}),
6545
});
46+
47+
const goFiles = await this.github.findFilesByGlobAndRef(
48+
'**/*.go',
49+
this.changesBranch
50+
);
51+
52+
// handle code snippets in markdown files as well
53+
const mdFiles = await this.github.findFilesByGlobAndRef(
54+
'**/*.md',
55+
this.changesBranch
56+
);
57+
58+
for (const file of [...goFiles, ...mdFiles]) {
59+
updates.push({
60+
path: this.addPath(file),
61+
createIfMissing: true,
62+
updater: new GithubImportsGo({
63+
version,
64+
repository: this.repository,
65+
}),
66+
});
67+
}
6668
}
6769

6870
return updates;

test/strategies/go.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const COMMITS = [
3737
...buildMockConventionalCommit('chore: update common templates'),
3838
];
3939

40+
const BREAKING_CHANGE = buildMockConventionalCommit('feat!: breaking change');
41+
4042
describe('Go', () => {
4143
let github: GitHub;
4244
beforeEach(async () => {
@@ -121,9 +123,13 @@ describe('Go', () => {
121123
)
122124
);
123125
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
124-
const latestRelease = undefined;
126+
const latestRelease = {
127+
tag: new TagName(Version.parse('1.0.0'), 'some-go-package'),
128+
sha: 'abc123',
129+
notes: 'some notes',
130+
};
125131
const release = await strategy.buildReleasePullRequest({
126-
commits: COMMITS,
132+
commits: [...COMMITS, ...BREAKING_CHANGE],
127133
latestRelease,
128134
});
129135
const updates = release!.updates;
@@ -144,9 +150,13 @@ describe('Go', () => {
144150
)
145151
);
146152
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
147-
const latestRelease = undefined;
153+
const latestRelease = {
154+
tag: new TagName(Version.parse('1.0.0'), 'some-go-package'),
155+
sha: 'abc123',
156+
notes: 'some notes',
157+
};
148158
const release = await strategy.buildReleasePullRequest({
149-
commits: COMMITS,
159+
commits: [...COMMITS, ...BREAKING_CHANGE],
150160
latestRelease,
151161
});
152162
const updates = release!.updates;

0 commit comments

Comments
 (0)