diff --git a/.changeset/ten-jokes-boil.md b/.changeset/ten-jokes-boil.md new file mode 100644 index 0000000..1db28f3 --- /dev/null +++ b/.changeset/ten-jokes-boil.md @@ -0,0 +1,5 @@ +--- +"@manypkg/cli": patch +--- + +Add special logic for `INCORRECT_REPOSITORY_FIELD` check to handle github repository separately from azure diff --git a/packages/cli/src/checks/INCORRECT_REPOSITORY_FIELD.ts b/packages/cli/src/checks/INCORRECT_REPOSITORY_FIELD.ts index e52316b..9d23c08 100644 --- a/packages/cli/src/checks/INCORRECT_REPOSITORY_FIELD.ts +++ b/packages/cli/src/checks/INCORRECT_REPOSITORY_FIELD.ts @@ -17,9 +17,16 @@ export default makeCheck({ if (typeof rootRepositoryField === "string") { let result = parseGithubUrl(rootRepositoryField); - if (result !== null) { + if (result !== null && (result.host === 'github.com' || result.host === 'dev.azure.com')) { + let baseRepositoryUrl = ""; + if (result.host === "github.com") { + baseRepositoryUrl = `${result.protocol}//${result.host}/${result.owner}/${result.name}`; + } else if (result.host === "dev.azure.com") { + baseRepositoryUrl = `${result.protocol}//${result.host}/${result.owner}/${result.name}/_git/${result.filepath}`; + } + if (workspace === rootWorkspace) { - let correctRepositoryField = `https://github.com/${result.owner}/${result.name}`; + let correctRepositoryField = baseRepositoryUrl; if (rootRepositoryField !== correctRepositoryField) { return [ { @@ -32,11 +39,18 @@ export default makeCheck({ } } else { // TODO: handle default branches that aren't master - let correctRepositoryField = `https://github.com/${result.owner}/${ - result.name - }/tree/master/${normalizePath( - path.relative(rootWorkspace.dir, workspace.dir) - )}`; + let correctRepositoryField = ""; + + if (result.host === "github.com") { + correctRepositoryField = `${baseRepositoryUrl}/tree/master/${normalizePath( + path.relative(rootWorkspace.dir, workspace.dir) + )}`; + } else if (result.host === "dev.azure.com") { + correctRepositoryField = `${baseRepositoryUrl}?path=${normalizePath( + path.relative(rootWorkspace.dir, workspace.dir) + )}&version=GBmaster&_a=contents`; + } + let currentRepositoryField = (workspace.config as any).repository; if (correctRepositoryField !== currentRepositoryField) { return [ diff --git a/packages/cli/src/checks/__tests__/INCORRECT_REPOSITORY_FIELD.ts b/packages/cli/src/checks/__tests__/INCORRECT_REPOSITORY_FIELD.ts index 401d98a..c58ec7b 100644 --- a/packages/cli/src/checks/__tests__/INCORRECT_REPOSITORY_FIELD.ts +++ b/packages/cli/src/checks/__tests__/INCORRECT_REPOSITORY_FIELD.ts @@ -3,61 +3,169 @@ import check from "../INCORRECT_REPOSITORY_FIELD"; import { getWS, getFakeWS } from "../../test-helpers"; describe("incorrect repository field", () => { - it("should work", () => { - let ws = getWS(); - let rootWorkspace = getFakeWS("root"); - - (rootWorkspace.config as any).repository = - "https://github.com/Thinkmill/manypkg"; - rootWorkspace.dir = __dirname; - let workspace = getFakeWS("no-repository-field"); - workspace.dir = path.join(__dirname, "packages/no-repository-field"); - ws.set("depends-on-one", workspace); - ws.set("root", rootWorkspace); - let errors = check.validate(workspace, ws, rootWorkspace); - expect(errors.map(({ workspace, ...x }: any) => x)).toMatchInlineSnapshot(` - Array [ - Object { - "correctRepositoryField": "https://github.com/Thinkmill/manypkg/tree/master/packages/no-repository-field", - "currentRepositoryField": undefined, - "type": "INCORRECT_REPOSITORY_FIELD", - }, - ] - `); - - check.fix(errors[0]); - - expect((workspace.config as any).repository).toBe( - "https://github.com/Thinkmill/manypkg/tree/master/packages/no-repository-field" - ); + describe("github", () => { + it("should work", () => { + let ws = getWS(); + let rootWorkspace = getFakeWS("root"); + + (rootWorkspace.config as any).repository = + "https://github.com/Thinkmill/manypkg"; + rootWorkspace.dir = __dirname; + let workspace = getFakeWS("no-repository-field"); + workspace.dir = path.join(__dirname, "packages/no-repository-field"); + ws.set("depends-on-one", workspace); + ws.set("root", rootWorkspace); + let errors = check.validate(workspace, ws, rootWorkspace); + expect(errors.map(({ workspace, ...x }: any) => x)) + .toMatchInlineSnapshot(` + Array [ + Object { + "correctRepositoryField": "https://github.com/Thinkmill/manypkg/tree/master/packages/no-repository-field", + "currentRepositoryField": undefined, + "type": "INCORRECT_REPOSITORY_FIELD", + }, + ] + `); + + check.fix(errors[0]); + + expect((workspace.config as any).repository).toBe( + "https://github.com/Thinkmill/manypkg/tree/master/packages/no-repository-field" + ); + }); + it("should fix root in a different format", () => { + let ws = getWS(); + let rootWorkspace = getFakeWS("root"); + + (rootWorkspace.config as any).repository = + "https://github.com/Thinkmill/manypkg.git"; + + rootWorkspace.dir = __dirname; + let workspace = getFakeWS("no-repository-field"); + workspace.dir = path.join(__dirname, "packages/no-repository-field"); + ws.set("depends-on-one", workspace); + ws.set("root", rootWorkspace); + let errors = check.validate(rootWorkspace, ws, rootWorkspace); + expect(errors.map(({ workspace, ...x }: any) => x)) + .toMatchInlineSnapshot(` + Array [ + Object { + "correctRepositoryField": "https://github.com/Thinkmill/manypkg", + "currentRepositoryField": "https://github.com/Thinkmill/manypkg.git", + "type": "INCORRECT_REPOSITORY_FIELD", + }, + ] + `); + + check.fix(errors[0]); + + expect((rootWorkspace.config as any).repository).toBe( + "https://github.com/Thinkmill/manypkg" + ); + }); + it("should do nothing if already in good format", () => { + let ws = getWS(); + let rootWorkspace = getFakeWS("root"); + + (rootWorkspace.config as any).repository = + "https://github.com/Thinkmill/manypkg"; + + rootWorkspace.dir = __dirname; + let workspace = getFakeWS("no-repository-field"); + workspace.dir = path.join(__dirname, "packages/no-repository-field"); + ws.set("depends-on-one", workspace); + ws.set("root", rootWorkspace); + let errors = check.validate(rootWorkspace, ws, rootWorkspace); + expect(errors.map(({ workspace, ...x }: any) => x)).toMatchInlineSnapshot( + `Array []` + ); + + expect((rootWorkspace.config as any).repository).toBe( + "https://github.com/Thinkmill/manypkg" + ); + }); }); - it("should fix root in a different format", () => { - let ws = getWS(); - let rootWorkspace = getFakeWS("root"); - - (rootWorkspace.config as any).repository = - "https://github.com/Thinkmill/manypkg.git"; - - rootWorkspace.dir = __dirname; - let workspace = getFakeWS("no-repository-field"); - workspace.dir = path.join(__dirname, "packages/no-repository-field"); - ws.set("depends-on-one", workspace); - ws.set("root", rootWorkspace); - let errors = check.validate(rootWorkspace, ws, rootWorkspace); - expect(errors.map(({ workspace, ...x }: any) => x)).toMatchInlineSnapshot(` - Array [ - Object { - "correctRepositoryField": "https://github.com/Thinkmill/manypkg", - "currentRepositoryField": "https://github.com/Thinkmill/manypkg.git", - "type": "INCORRECT_REPOSITORY_FIELD", - }, - ] - `); - - check.fix(errors[0]); - - expect((rootWorkspace.config as any).repository).toBe( - "https://github.com/Thinkmill/manypkg" - ); + + describe("azure devops", () => { + it("should work", () => { + let ws = getWS(); + let rootWorkspace = getFakeWS("root"); + + (rootWorkspace.config as any).repository = + "https://dev.azure.com/Thinkmill/monorepos/_git/manypkg"; + rootWorkspace.dir = __dirname; + let workspace = getFakeWS("no-repository-field"); + workspace.dir = path.join(__dirname, "packages/no-repository-field"); + ws.set("depends-on-one", workspace); + ws.set("root", rootWorkspace); + let errors = check.validate(workspace, ws, rootWorkspace); + expect(errors.map(({ workspace, ...x }: any) => x)) + .toMatchInlineSnapshot(` + Array [ + Object { + "correctRepositoryField": "https://dev.azure.com/Thinkmill/monorepos/_git/manypkg?path=packages/no-repository-field&version=GBmaster&_a=contents", + "currentRepositoryField": undefined, + "type": "INCORRECT_REPOSITORY_FIELD", + }, + ] + `); + + check.fix(errors[0]); + + expect((workspace.config as any).repository).toBe( + "https://dev.azure.com/Thinkmill/monorepos/_git/manypkg?path=packages/no-repository-field&version=GBmaster&_a=contents" + ); + }); + it("should fix root in a different format", () => { + let ws = getWS(); + let rootWorkspace = getFakeWS("root"); + + (rootWorkspace.config as any).repository = + "https://Thinkmill@dev.azure.com/Thinkmill/monorepos/_git/manypkg"; + + rootWorkspace.dir = __dirname; + let workspace = getFakeWS("no-repository-field"); + workspace.dir = path.join(__dirname, "packages/no-repository-field"); + ws.set("depends-on-one", workspace); + ws.set("root", rootWorkspace); + let errors = check.validate(rootWorkspace, ws, rootWorkspace); + expect(errors.map(({ workspace, ...x }: any) => x)) + .toMatchInlineSnapshot(` + Array [ + Object { + "correctRepositoryField": "https://dev.azure.com/Thinkmill/monorepos/_git/manypkg", + "currentRepositoryField": "https://Thinkmill@dev.azure.com/Thinkmill/monorepos/_git/manypkg", + "type": "INCORRECT_REPOSITORY_FIELD", + }, + ] + `); + + check.fix(errors[0]); + + expect((rootWorkspace.config as any).repository).toBe( + "https://dev.azure.com/Thinkmill/monorepos/_git/manypkg" + ); + }); + it("should do nothing if already in good format", () => { + let ws = getWS(); + let rootWorkspace = getFakeWS("root"); + + (rootWorkspace.config as any).repository = + "https://dev.azure.com/Thinkmill/monorepos/_git/manypkg"; + + rootWorkspace.dir = __dirname; + let workspace = getFakeWS("no-repository-field"); + workspace.dir = path.join(__dirname, "packages/no-repository-field"); + ws.set("depends-on-one", workspace); + ws.set("root", rootWorkspace); + let errors = check.validate(rootWorkspace, ws, rootWorkspace); + expect(errors.map(({ workspace, ...x }: any) => x)).toMatchInlineSnapshot( + `Array []` + ); + + expect((rootWorkspace.config as any).repository).toBe( + "https://dev.azure.com/Thinkmill/monorepos/_git/manypkg" + ); + }); }); });