Allow repo names with underscores (#737)

Such repos exist in practice.

Test plan: Unit tests
This commit is contained in:
Dandelion Mané 2018-08-30 19:29:20 -07:00 committed by GitHub
parent d8a16a4def
commit 84d505ab12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -6,11 +6,12 @@ export opaque type Repo: {|+name: string, +owner: string|} = {|
|};
export function makeRepo(owner: string, name: string): Repo {
const validRe = /^[A-Za-z0-9-.]+$/;
if (!owner.match(validRe)) {
const validOwner = /^[A-Za-z0-9-]+$/;
const validRepo = /^[A-Za-z0-9-._]+$/;
if (!owner.match(validOwner)) {
throw new Error(`Invalid repository owner: ${JSON.stringify(owner)}`);
}
if (!name.match(validRe)) {
if (!name.match(validRepo)) {
throw new Error(`Invalid repository name: ${JSON.stringify(name)}`);
}
return {owner, name};

View File

@ -14,7 +14,7 @@ describe("core/repo", () => {
const _unused_name: string = repo.name;
});
});
describe("makeRepoRepo", () => {
describe("makeRepo", () => {
it("allows a simple repo", () => {
makeRepo("sourcecred", "sourcecred");
});
@ -30,8 +30,14 @@ describe("core/repo", () => {
it("disallows a repo with no name", () => {
expect(() => makeRepo("foo", "")).toThrow("Invalid");
});
it("disallows a repo with underscores", () => {
expect(() => makeRepo("yep", "something_bad")).toThrow("Invalid");
it("disallows an owner with periods", () => {
expect(() => makeRepo("fo.o", "bar")).toThrow("Invalid");
});
it("disallows an owner with underscores", () => {
expect(() => makeRepo("fo_o", "bar")).toThrow("Invalid");
});
it("allows a repo with underscores", () => {
makeRepo("foo", "still_good");
});
});
describe("repo<->string", () => {
@ -45,7 +51,7 @@ describe("core/repo", () => {
testInvertible("sourcecred", "sourcecred");
});
it("works for a complicated case", () => {
testInvertible("fooolio", "foo-bar.bar-99");
testInvertible("fooolio", "foo-bar.bar-99_x");
});
});
});