Skip to content

Commit bfe4bee

Browse files
authored
update go import regex to consider pre v2 (#174)
* update go import regex to consider pre v2 * add missing file
1 parent 919b93a commit bfe4bee

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import {DefaultUpdater} from '../default';
22

33
export class GithubImportsGo extends DefaultUpdater {
44
updateContent(content: string): string {
5+
if (this.version.major < 2) {
6+
return content;
7+
}
8+
59
return content.replace(
6-
/"github\.com\/([^/]+)\/([^/]+)\/v([1-9]\d*)\/(.+)"/g,
7-
(_, user, repo, __, path) =>
10+
/"github\.com\/([^/]+)\/([^/]+)(\/v([1-9]\d*))?\/(.+)"/g,
11+
(_, user, repo, __, ___, path) =>
812
`"github.com/${user}/${repo}/v${this.version.major.toString()}/${path}"`
913
);
1014
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package accounts
2+
3+
import (
4+
"context"
5+
"errors"
6+
"fmt"
7+
"net/http"
8+
"net/url"
9+
"time"
10+
11+
"github.com/cloudflare/cloudflare-go/internal/apijson"
12+
"github.com/cloudflare/cloudflare-go/internal/apiquery"
13+
"github.com/cloudflare/cloudflare-go/internal/pagination"
14+
"github.com/cloudflare/cloudflare-go/internal/param"
15+
"github.com/cloudflare/cloudflare-go/internal/requestconfig"
16+
"github.com/cloudflare/cloudflare-go/option"
17+
"github.com/cloudflare/cloudflare-go/shared"
18+
)

test/updaters/go-imports.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import {GithubImportsGo} from '../../src/updaters/go/github-imports-go';
88
const fixturesPath = './test/updaters/fixtures';
99

1010
describe('GithubImportsGo', () => {
11+
const v1File = readFileSync(
12+
resolve(fixturesPath, 'file-with-imports-v1.go'),
13+
'utf8'
14+
);
15+
1116
const v2File = readFileSync(
1217
resolve(fixturesPath, 'file-with-imports-v2.go'),
1318
'utf8'
@@ -18,14 +23,28 @@ describe('GithubImportsGo', () => {
1823
'utf8'
1924
);
2025

21-
it('makes no changes if the new version has a major version of 2', async () => {
26+
it('makes no changes if the old version has a major version of 1 and the new version also has a major version of 1', async () => {
27+
const readmeUpdater = new GithubImportsGo({
28+
version: Version.parse('1.0.0'),
29+
});
30+
expect(readmeUpdater.updateContent(v1File)).to.equal(v1File);
31+
});
32+
33+
it('updates the version in the imports if the old version has a major version of 1 and the new version has a major version of 2', async () => {
34+
const readmeUpdater = new GithubImportsGo({
35+
version: Version.parse('2.0.0'),
36+
});
37+
expect(readmeUpdater.updateContent(v1File)).to.equal(v2File);
38+
});
39+
40+
it('makes no changes if the old version has a major version of 2 and the new version also has a major version of 2', async () => {
2241
const readmeUpdater = new GithubImportsGo({
2342
version: Version.parse('2.0.0'),
2443
});
2544
expect(readmeUpdater.updateContent(v2File)).to.equal(v2File);
2645
});
2746

28-
it('updates the version in the imports if the new version has a major version of 3', async () => {
47+
it('updates the version in the imports if the old version has a major version of 2 and the new version has a major version of 3', async () => {
2948
const readmeUpdater = new GithubImportsGo({
3049
version: Version.parse('3.0.0'),
3150
});

0 commit comments

Comments
 (0)