-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { splitOwnerAndRepository } from "@/common" | ||
|
||
test("It returns undefined when string includes no slash", async () => { | ||
const result = splitOwnerAndRepository("foo") | ||
expect(result).toBeUndefined() | ||
}) | ||
|
||
test("It returns undefined when repository is empty", async () => { | ||
const result = splitOwnerAndRepository("foo/") | ||
expect(result).toBeUndefined() | ||
}) | ||
|
||
test("It returns undefined when owner is empty", async () => { | ||
const result = splitOwnerAndRepository("/foo") | ||
expect(result).toBeUndefined() | ||
}) | ||
|
||
test("It splits owner and repository", async () => { | ||
const result = splitOwnerAndRepository("acme/foo") | ||
expect(result).toEqual({ owner: "acme", repository: "foo" }) | ||
}) | ||
|
||
test("It splits owner and repository for repository name containing a slash", async () => { | ||
const result = splitOwnerAndRepository("acme/foo/bar") | ||
expect(result).toEqual({ owner: "acme", repository: "foo/bar" }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Split full repository names into owner and repository. | ||
// shapehq/foo becomes { owner: "shapehq", "repository": "foo" } | ||
export default (str: string) => { | ||
const index = str.indexOf("/") | ||
if (index === -1) { | ||
return undefined | ||
} | ||
const owner = str.substring(0, index) | ||
const repository = str.substring(index + 1) | ||
if (owner.length == 0 || repository.length == 0) { | ||
return undefined | ||
} | ||
return { owner, repository } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters