Support other git hosting services (#312)

* Impl new mod `hosting` for detecting git hosting services
* Refactor: Make `guess_git_hosting_services` associated fn of `GitHostingService`
* Set default value of `PkgMeta::pkg_url` to `None`
* Impl new method `get_redirected_final_url`
* Use `get_redirected_final_url` in `GhCrateMeta::find` to make `guess_git_hosting_services` more accurate.
* Use redirected `repo` in `GhCrateMeta::launch_baseline_find_tasks`
* Refactor `<GhCrateMeta as Fetcher>::find`
* Mod `get_default_pkg_url_template` to ret `&[&str]`
* Add more default `pkg-url` templates
* Rm `pkg-url` in `bin/Cargo.toml`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-08-24 17:16:26 +10:00 committed by GitHub
parent 6b5e8f6875
commit 846e7ead91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 251 additions and 44 deletions

View file

@ -11,10 +11,6 @@ pub use package_formats::*;
mod package_formats;
/// Default package path template (may be overridden in package Cargo.toml)
pub const DEFAULT_PKG_URL: &str =
"{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.{ archive-format }";
/// Default binary name template (may be overridden in package Cargo.toml)
pub const DEFAULT_BIN_DIR: &str = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }";
@ -34,7 +30,7 @@ pub struct Meta {
#[serde(rename_all = "kebab-case", default)]
pub struct PkgMeta {
/// URL template for package downloads
pub pkg_url: String,
pub pkg_url: Option<String>,
/// Format for package downloads
pub pkg_fmt: Option<PkgFmt>,
@ -52,7 +48,7 @@ pub struct PkgMeta {
impl Default for PkgMeta {
fn default() -> Self {
Self {
pkg_url: DEFAULT_PKG_URL.to_string(),
pkg_url: None,
pkg_fmt: None,
bin_dir: DEFAULT_BIN_DIR.to_string(),
pub_key: None,
@ -75,7 +71,7 @@ impl PkgMeta {
/// Merge configuration overrides into object
pub fn merge(&mut self, pkg_override: &PkgOverride) {
if let Some(o) = &pkg_override.pkg_url {
self.pkg_url = o.clone();
self.pkg_url = Some(o.clone());
}
if let Some(o) = &pkg_override.pkg_fmt {
self.pkg_fmt = Some(*o);