|
| 1 | +open Base |
| 2 | +open Printf |
| 3 | +open Lib |
| 4 | +open Github |
| 5 | +open Github_t |
| 6 | + |
| 7 | +let mk_repo ?(scheme = "https") prefix prefix_api : repository = |
| 8 | + { |
| 9 | + name = "monorepo"; |
| 10 | + full_name = "ahrefs/monorepo"; |
| 11 | + url = sprintf "%s://%s/ahrefs/monorepo" scheme prefix; |
| 12 | + commits_url = sprintf "%s://%s/repos/ahrefs/monorepo/commits{/sha}" scheme prefix_api; |
| 13 | + contents_url = sprintf "%s://%s/repos/ahrefs/monorepo/contents/{+path}" scheme prefix_api; |
| 14 | + } |
| 15 | + |
| 16 | +let enterprise_repo1 = mk_repo "example.org" "example.org/api/v3" |
| 17 | + |
| 18 | +let enterprise_repo2 = mk_repo "example.org/path/to/git" "example.org/path/to/git/api/v3" |
| 19 | + |
| 20 | +let enterprise_repo_insecure = mk_repo ~scheme:"http" "example.org" "example.org/api/v3" |
| 21 | + |
| 22 | +let github_repo = mk_repo "github.com" "api.github.com" |
| 23 | + |
| 24 | +let commit_cases prefix repo = |
| 25 | + [ |
| 26 | + sprintf "https://%s/ahrefs/monorepo/commit/69c42640" prefix, Some (Commit (repo, "69c42640")); |
| 27 | + sprintf "https://%s/ahrefs/monorepo/commit/69c42640/" prefix, Some (Commit (repo, "69c42640")); |
| 28 | + sprintf "https://%s/ahrefs/monorepo/commit/69c42640?arg1=123" prefix, Some (Commit (repo, "69c42640")); |
| 29 | + sprintf "https://%s/ahrefs/monorepo/commit/" prefix, None; |
| 30 | + sprintf "https://%s/ahrefs/monorepo/commit" prefix, None; |
| 31 | + ] |
| 32 | + |
| 33 | +let other_cases = |
| 34 | + [ |
| 35 | + "http://github.com/ahrefs/monorepo/commit/69c42640", Some (Commit (github_repo, "69c42640")); |
| 36 | + "http://example.org/ahrefs/monorepo/commit/69c42640", Some (Commit (enterprise_repo_insecure, "69c42640")); |
| 37 | + "abc", None; |
| 38 | + ] |
| 39 | + |
| 40 | +let cases = |
| 41 | + List.concat |
| 42 | + [ |
| 43 | + commit_cases "github.com" github_repo; |
| 44 | + commit_cases "www.github.com" github_repo; |
| 45 | + commit_cases "example.org" enterprise_repo1; |
| 46 | + commit_cases "example.org/path/to/git" enterprise_repo2; |
| 47 | + other_cases; |
| 48 | + ] |
| 49 | + |
| 50 | +let () = List.iter cases ~f:(fun (input, expected) -> assert (Poly.equal (gh_link_of_string input) expected)) |
0 commit comments