Skip to content

Commit b40c6fe

Browse files
authored
updates (#175)
1 parent bfe4bee commit b40c6fe

File tree

12 files changed

+116
-43
lines changed

12 files changed

+116
-43
lines changed

src/strategies/go-yoshi.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,18 @@ export class GoYoshi extends BaseStrategy {
7171
}),
7272
});
7373

74-
const allFiles = await this.github.findFilesByGlobAndRef(
74+
const goFiles = await this.github.findFilesByGlobAndRef(
7575
'**/*.go',
7676
this.changesBranch
7777
);
7878

79-
for (const file of allFiles) {
79+
// handle code snippets in markdown files as well
80+
const mdFiles = await this.github.findFilesByGlobAndRef(
81+
'**/*.md',
82+
this.changesBranch
83+
);
84+
85+
for (const file of [...goFiles, ...mdFiles]) {
8086
updates.push({
8187
path: this.addPath(file),
8288
createIfMissing: false,

src/strategies/go.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ export class Go extends BaseStrategy {
3434
}),
3535
});
3636

37-
const allFiles = await this.github.findFilesByGlobAndRef(
37+
const goFiles = await this.github.findFilesByGlobAndRef(
3838
'**/*.go',
3939
this.changesBranch
4040
);
4141

42-
for (const file of allFiles) {
42+
// handle code snippets in markdown files as well
43+
const mdFiles = await this.github.findFilesByGlobAndRef(
44+
'**/*.md',
45+
this.changesBranch
46+
);
47+
48+
for (const file of [...goFiles, ...mdFiles]) {
4349
updates.push({
4450
path: this.addPath(file),
4551
createIfMissing: true,

src/updaters/go/github-imports-go.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ export class GithubImportsGo extends DefaultUpdater {
77
}
88

99
return content.replace(
10-
/"github\.com\/([^/]+)\/([^/]+)(\/v([1-9]\d*))?\/(.+)"/g,
11-
(_, user, repo, __, ___, path) =>
12-
`"github.com/${user}/${repo}/v${this.version.major.toString()}/${path}"`
10+
/"(https:\/\/pkg.go.dev\/)?github\.com\/([^/]+)\/([^/]+)(\/v([1-9]\d*))?(\/[^"]+)?"/g,
11+
(_, prefix, user, repo, ___, ____, path) =>
12+
`"${prefix ?? ''}github.com/${user}/${repo}${
13+
this.version.major < 2 ? '' : '/v' + this.version.major.toString()
14+
}${path ?? ''}"`
1315
);
1416
}
1517
}

test/strategies/go-yoshi.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ describe('GoYoshi', () => {
4747

4848
sandbox
4949
.stub(github, 'findFilesByGlobAndRef')
50-
.resolves(['file-with-imports-v2.go']);
50+
.withArgs('**/*.go', 'main')
51+
.resolves(['file-with-imports-v2.go'])
52+
.withArgs('**/*.md', 'main')
53+
.resolves([]);
5154
});
5255
afterEach(() => {
5356
sandbox.restore();

test/strategies/go.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ describe('Go', () => {
4747

4848
sandbox
4949
.stub(github, 'findFilesByGlobAndRef')
50-
.resolves(['file-with-imports-v2.go']);
50+
.withArgs('**/*.go', 'main')
51+
.resolves(['file-with-imports-v2.go'])
52+
.withArgs('**/*.md', 'main')
53+
.resolves([]);
5154
});
5255
afterEach(() => {
5356
sandbox.restore();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/shared">shared</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/shared#ASNParam">ASNParam</a>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/shared">shared</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/shared#ASNParam">ASNParam</a>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/shared">shared</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/shared#ASNParam">ASNParam</a>

test/updaters/fixtures/file-with-imports-v1.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ import (
1515
"github.com/cloudflare/cloudflare-go/internal/requestconfig"
1616
"github.com/cloudflare/cloudflare-go/option"
1717
"github.com/cloudflare/cloudflare-go/shared"
18+
"github.com/cloudflare/cloudflare-go"
1819
)

test/updaters/fixtures/file-with-imports-v2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ import (
1515
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
1616
"github.com/cloudflare/cloudflare-go/v2/option"
1717
"github.com/cloudflare/cloudflare-go/v2/shared"
18+
"github.com/cloudflare/cloudflare-go/v2"
1819
)

0 commit comments

Comments
 (0)