Skip to main content

lib_remotebuild_rs/
aur.rs

1use crate::{
2    jobs::{Type, UploadType},
3    librb, request, request_error, responses,
4};
5
6use std::collections::HashMap;
7
8pub const DM_TOKEN: &str = "DM_Token"; // DMToken session token for DManager
9pub const DM_USER: &str = "DM_USER"; // DMUser username for DManger
10pub const DM_HOST: &str = "DM_HOST"; // DMHost Dmanager host
11pub const DM_NAMESPACE: &str = "DM_NAMESPACE"; // DMHost Dmanager host
12pub const AUR_PACKAGE: &str = "REPO"; // AUR package to build
13
14/// Stores data relevant for AUR build jobs
15pub struct AURBuild<'a> {
16    pub librb: &'a librb::LibRb,
17    pub args: HashMap<String, String>,
18    pub upload_type: UploadType,
19    pub disable_ccache: bool,
20}
21
22impl<'a> AURBuild<'a> {
23    /// Turn of ccache usage
24    pub fn without_ccache(mut self) -> Self {
25        self.disable_ccache = true;
26        self
27    }
28
29    /// Add dmanager upload data to the job
30    pub fn with_dmanager(
31        mut self,
32        username: String,
33        token: String,
34        host: String,
35        namespace: String,
36    ) -> Self {
37        self.upload_type = UploadType::DataManager;
38        self.args.insert(DM_TOKEN.to_owned(), token);
39        self.args.insert(DM_USER.to_owned(), username);
40        self.args.insert(DM_HOST.to_owned(), host);
41
42        if !namespace.is_empty() {
43            self.args.insert(DM_NAMESPACE.to_owned(), namespace);
44        }
45
46        self
47    }
48
49    /// Create a new AUR build job
50    pub async fn create_job(
51        self,
52    ) -> Result<request::RequestResult<responses::AddJob>, request_error::Error> {
53        self.librb
54            .add_job(
55                Type::JobAUR,
56                self.upload_type,
57                self.args,
58                self.disable_ccache,
59            )
60            .await
61    }
62}