The URLs of Hosting services such as GitHub, GitLab and Bitbucket have their patterns. Thus we can use these patterns to programably compose the URL of a file or the repo on a specific commit rather than manually clicking through several links in a row to get what we want. They also provide their own APIs for doing that, which sometimes are more intuitive to use.
Below is a collection of the patterns and APIs that are used in MLHub to construct the URLs for MLHub package installation from these hosting services.
:owner-- Account/Username, such assimonzhaoms:repo-- Repo name, such astips:branch-- Branch name, such asmaster:sha-- Commit hash, such as093fc07:path-- File/directory path, such astips/github/compose-github-links.md:tag-- Tag name, such asv1.0:release-- Release name, such asv2.0:number-- Pull request number, such as9
- Repo webpage:
- https://github.com/:owner/:repo (Default)
- https://github.com/:owner/:repo/tree/:branch (Branch)
- https://github.com/:owner/:repo/tree/:sha (Commit)
- File webpage:
- Raw file:
- https://raw.githubusercontent.com/:owner/:repo/master/:path (Default)
- https://github.com/:owner/:repo/raw/master/:path (Default)
- https://raw.githubusercontent.com/:owner/:repo/:branch/:path (Branch)
- https://github.com/:owner/:repo/raw/:branch/:path (Branch)
- https://raw.githubusercontent.com/:owner/:repo/:sha/:path (Commit)
- https://github.com/:owner/:repo/raw/:sha/:path (Commit)
- Directory:
- Commit:
- https://github.com/:owner/:repo/commit/:sha (From commit list)
- Repo zip:
- Git clone:
- Tag:
- https://github.com/:owner/:repo/tree/:tag (Webpage)
- https://github.com/:owner/:repo/blob/:tag/:path (File webpage)
- https://github.com/:owner/:repo/raw/:tag/:path (Raw file)
- https://github.com/:owner/:repo/tree/:tag/:path (Directory)
- Release:
- Pull request:
- https://github.com/:owner/:repo/pull/:number (From pull request list)
- https://github.com/:owner/:repo/pull/:number/commits (Pull request commits)
- https://github.com/:owner/:repo/pull/:number/commits/:sha (A single commit in pull request)
- File:
- https://api.github.com/repos/:owner/:repo/contents/:path
- Reponse contains the
typeof the path (file or dir),name, encodedcontentof the file anddownload_url. There is no specific API for directly getting raw content of a file.
- Reponse contains the
- https://api.github.com/repos/:owner/:repo/contents/:path
- Directory:
- https://api.github.com/repos/:owner/:repo/contents/:path
- Response is an array of JSON objects which contains the
typeof the object (file or dir),name, encodedcontentof the file (if it is file) anddownload_url(if it is a file).
- Response is an array of JSON objects which contains the
- https://api.github.com/repos/:owner/:repo/contents/:path
- Repo zip:
- https://api.github.com/repos/:owner/:repo/zipball/:ref
- Response contains
locationof the redirected link of the repo's zipball referred by:refwhich may be a commit, tag, release or branch, I think.
- Response contains
- https://api.github.com/repos/:owner/:repo/zipball/:ref
- Pull request commits list:
- GitHub REST API v3
- Repo webpage:
- https://gitlab.com/:owner/:repo (Default)
- https://gitlab.com/:owner/:repo/tree/:branch (Branch)
- https://gitlab.com/:owner/:repo/tree/:sha (Commit)
- File webpage:
- Raw file:
- https://gitlab.com/:owner/:repo/raw/master/:path (Default)
- https://gitlab.com/:owner/:repo/raw/master/:path?inline=false (Default download)
- https://gitlab.com/:owner/:repo/raw/:branch/:path (Branch)
- https://gitlab.com/:owner/:repo/raw/:branch/:path?inline=false (Branch download)
- https://gitlab.com/:owner/:repo/raw/:sha/:path (Commit)
- https://gitlab.com/:owner/:repo/raw/:sha/:path?inline=false (Commit download)
- Directory:
- Commit:
- https://gitlab.com/:owner/:repo/commit/:sha (From commit list)
- Repo zip:
- Git clone:
- Tag:
- https://gitlab.com/:owner/:repo/tree/:tag (Webpage)
- https://gitlab.com/:owner/:repo/blob/:tag/:path (File webpage)
- https://gitlab.com/:owner/:repo/raw/:tag/:path (Raw file)
- https://gitlab.com/:owner/:repo/raw/:tag/:path?inline=false (Raw file download)
- https://gitlab.com/:owner/:repo/tree/:tag/:path (Directory)
- Release: Created by API, not directly in webpage. And a release seems to be referred by the tag it relies on not its release name.
- Merge request:
- https://gitlab.com/:owner/:repo/merge_requests/:number (From merge request list)
- https://gitlab.com/:owner/:repo/merge_requests/:number/commits (Merge request commits)
- https://gitlab.com/:owner/:repo/merge_requests/:number/diffs?commit_id=:sha (A single commit in merge request)
- File info:
- https://gitlab.com/api/v4/projects/:id/repository/files/:path?ref=:ref
- Response contains the
sizeof the file, encondedcontent. Note::idis:owner/:repobut needs to be encoded as:owner%2F:repo, where/is replaced by%2. Similarly,:pathsuch asmlhub/commands.pyneeds to be encoded asmlhub%2Fcommands%2Epy.:refcan be a branch, commit, tag, etc.
- Response contains the
- https://gitlab.com/api/v4/projects/:id/repository/files/:path?ref=:ref
- Raw file:
- Directory:
- https://gitlab.com/api/v4/projects/:id/repository/tree?path=:path&ref=:ref
- Response is an array of JSON objects which contains the
typeof the object (blob or tree) andnameof the file or directory.
- Response is an array of JSON objects which contains the
- https://gitlab.com/api/v4/projects/:id/repository/tree?path=:path&ref=:ref
- Repo zip:
- Merge request commits list:
- GitLab REST API v4
- Repo webpage:
- https://bitbucket.org/:owner/:repo/src/master/ (Default source)
- https://bitbucket.org/:owner/:repo/src/:branch/ (Branch source)
- https://bitbucket.org/:owner/:repo/branch/:branch (Branch)
- https://bitbucket.org/:owner/:repo/src/:sha/ (Commit source)
- https://bitbucket.org/:owner/:repo/commits/:sha (Commit)
- https://bitbucket.org/:owner/:repo/commits/:sha?at=:branch (Commit on a branch)
- File webpage:
- Raw file:
- Directory:
- Commit:
- https://bitbucket.org/:owner/:repo/commits/:sha (From commit list)
- Repo zip:
- Git clone:
- Tag:
- https://bitbucket.org/:owner/:repo/src/:tag/ (Webpage)
- https://bitbucket.org/:owner/:repo/src/:tag/:path (File webpage)
- https://bitbucket.org/:owner/:repo/raw/:tag/:path (Raw file)
- https://bitbucket.org/:owner/:repo/src/:tag/:path/ (Directory)
- Release: There seems no release. But there are downloads which seems to be any files not only repo archives.
- Pull request:
- https://bitbucket.org/:owner/:repo/pull-requests/:number (From pull request list)
- https://bitbucket.org/:owner/:repo/pull-requests/:number/:branch/diff (Redirection from above)
- https://bitbucket.org/:owner/:repo/pull-requests/:number/:branch/commits (Pull request commits)
- https://bitbucket.org/:owner/:repo/commits/:sha?at=:branch (A single commit in pull request): It rolls back to a plain commit. So the SHA of the commit needs to be known beforehand.
- File:
- Directory: The same as file.
- Repo zip: There seems no relevant API.
- Pull request: There seems no relevant API.
- BitBucket REST API v2