Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce GitLab Releases Provider #3

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/gitlab_release_provider.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under both the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree and the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree.
*/

use std::path::Path;
use std::process::Command;

use serde::Deserialize;
use serde_jsonrc::value::Value;

use crate::config::ArtifactEntry;
use crate::provider::Provider;
use crate::util::file_lock::FileLock;

pub struct GitLabReleaseProvider {}

#[derive(Deserialize, Debug, PartialEq)]
struct GitLabReleaseProviderConfig {
tag: String,
repo: String,
name: String,
}

impl Provider for GitLabReleaseProvider {
fn fetch_artifact(
&self,
provider_config: &Value,
destination: &Path,
_fetch_lock: &FileLock,
_artifact_entry: &ArtifactEntry,
) -> anyhow::Result<()> {
let GitLabReleaseProviderConfig { tag, repo, name } =
GitLabReleaseProviderConfig::deserialize(provider_config)?;

let _output = Command::new("glab")
.arg("release")
.arg("download")
.arg(tag)
.arg("--repo")
.arg(repo)
.arg("--asset-name")
.arg(name)
.arg("--dir")
.arg(destination)
.output()?;

Ok(())
}
}
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod download;
mod execution;
mod fetch_method;
mod github_release_provider;
mod gitlab_release_provider;
mod http_provider;
mod platform;
mod print_entry_for_url;
Expand All @@ -30,6 +31,7 @@ use std::env;
use std::process::ExitCode;

use anyhow::format_err;
use gitlab_release_provider::GitLabReleaseProvider;

use crate::github_release_provider::GitHubReleaseProvider;
use crate::http_provider::HttpProvider;
Expand All @@ -49,6 +51,7 @@ impl ProviderFactory for DefaultProviderFactory {
match provider_type {
"http" => Ok(Box::new(HttpProvider {})),
"github-release" => Ok(Box::new(GitHubReleaseProvider {})),
"gitlab-release" => Ok(Box::new(GitLabReleaseProvider {})),
_ => Err(format_err!("unknown provider type: `{}`", provider_type)),
}
}
Expand Down