Skip to content

Commit b1fe33f

Browse files
committed
Refactor out the OBS interaction code into a new obs-commander crate
This is largely just a rename, as well as the slightly-silly `obs-commander-test-support` crate that exists to avoid making the primary `obs-commander` crate depend on testing dependencies.
1 parent 68ce7f3 commit b1fe33f

File tree

20 files changed

+256
-110
lines changed

20 files changed

+256
-110
lines changed

Cargo.lock

Lines changed: 41 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,30 @@
1-
[package]
2-
name = "obs-gitlab-runner"
3-
version = "0.1.8"
4-
edition = "2024"
5-
license = "MIT OR Apache-2.0"
1+
[workspace]
2+
resolver = "3"
3+
members = [
4+
"obs-commander",
5+
"obs-commander-test-support",
6+
"obs-gitlab-runner"
7+
]
68

7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8-
9-
[dependencies]
9+
[workspace.dependencies]
1010
async-trait = "0.1"
11-
base16ct = { version = "0.2", features = ["std"] }
12-
bytes = "1.10"
1311
camino = "1.1"
12+
claims = "0.8"
1413
clap = { version = "4.5", features = ["default", "derive", "env"] }
1514
color-eyre = "0.6"
1615
derivative = "2.2"
1716
futures-util = "0.3"
18-
md-5 = "0.10"
19-
reqwest = "0.12"
20-
rfc822-like = "0.2"
17+
open-build-service-api = { git = "https://github.com/collabora/open-build-service-rs" }
18+
# open-build-service-api = { path = "../open-build-service-rs/open-build-service-api" }
19+
open-build-service-mock = { git = "https://github.com/collabora/open-build-service-rs" }
20+
# open-build-service-mock = { path = "../open-build-service-rs/open-build-service-api" }
21+
rstest = "0.26"
2122
serde = "1.0"
2223
serde_yaml = "0.9"
23-
shellexpand = "3.1"
2424
shell-words = "1.1"
25-
strum = { version = "0.27", features = ["derive"] }
2625
tempfile = "3.20"
26+
thiserror = "2.0"
2727
tokio = { version = "1.45", features = ["full"] }
28-
tokio-retry2 = { version = "0.5.7", features = ["jitter"] }
2928
tokio-util = { version = "0.7", features = ["full"] }
3029
tracing = "0.1"
31-
tracing-error = "0.2"
32-
tracing-subscriber = { version = "0.3", features = ["default", "json"] }
33-
url = "2.5"
34-
35-
gitlab-runner = "0.3.0-rc1"
36-
# gitlab-runner = { path = "../gitlab-runner-rs/gitlab-runner" }
37-
open-build-service-api = { git = "https://github.com/collabora/open-build-service-rs" }
38-
thiserror = "2.0.12"
39-
# open-build-service-api = { path = "../open-build-service-rs/open-build-service-api" }
40-
41-
[dev-dependencies]
42-
claims = "0.8"
43-
rstest = "0.26"
4430
wiremock = "0.6"
45-
zip = "4.1"
46-
47-
gitlab-runner-mock = "0.2.1"
48-
# gitlab-runner-mock = { path = "../gitlab-runner-rs/gitlab-runner-mock" }
49-
open-build-service-mock = { git = "https://github.com/collabora/open-build-service-rs" }
50-
# open-build-service-mock = { path = "../open-build-service-rs/open-build-service-mock" }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "obs-commander-test-support"
3+
version = "0.1.0"
4+
edition = "2024"
5+
license = "MIT OR Apache-2.0"
6+
7+
[dependencies]
8+
open-build-service-api.workspace = true
9+
open-build-service-mock.workspace = true
File renamed without changes.

obs-commander/Cargo.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[package]
2+
name = "obs-commander"
3+
version = "0.1.0"
4+
edition = "2024"
5+
license = "MIT OR Apache-2.0"
6+
7+
[dependencies]
8+
async-trait.workspace = true
9+
base16ct = { version = "0.2", features = ["std"] }
10+
bytes = "1.10"
11+
camino.workspace = true
12+
clap.workspace = true
13+
color-eyre.workspace = true
14+
derivative.workspace = true
15+
futures-util.workspace = true
16+
md-5 = "0.10"
17+
obs-commander-test-support = { path = "../obs-commander-test-support" }
18+
open-build-service-api.workspace = true
19+
reqwest = "0.12"
20+
rfc822-like = "0.2"
21+
serde.workspace = true
22+
serde_yaml.workspace = true
23+
shell-words.workspace = true
24+
tempfile.workspace = true
25+
thiserror.workspace = true
26+
tokio.workspace = true
27+
tokio-retry2 = { version = "0.5.7", features = ["jitter"] }
28+
tokio-util.workspace = true
29+
tracing.workspace = true
30+
31+
[dev-dependencies]
32+
claims.workspace = true
33+
rstest.workspace = true
34+
open-build-service-mock.workspace = true
35+
wiremock.workspace = true
36+

src/actions.rs renamed to obs-commander/src/actions.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ impl FlagSupportingExplicitValue for clap::Arg {
4141
}
4242
}
4343

44+
#[derive(Debug)]
45+
struct CommandBuilder {
46+
args: Vec<String>,
47+
}
48+
49+
impl CommandBuilder {
50+
fn new(name: String) -> Self {
51+
Self { args: vec![name] }
52+
}
53+
54+
fn add(&mut self, arg: &str, value: &str) -> &mut Self {
55+
self.args
56+
.push(format!("--{arg}={}", shell_words::quote(value)));
57+
self
58+
}
59+
60+
fn build(self) -> String {
61+
self.args.join(" ")
62+
}
63+
}
64+
4465
#[derive(Parser, Debug)]
4566
pub struct DputAction {
4667
pub project: String,
@@ -73,6 +94,24 @@ pub struct MonitorAction {
7394
pub build_log_out: String,
7495
}
7596

97+
impl MonitorAction {
98+
pub fn generate_command(&self) -> String {
99+
let mut builder = CommandBuilder::new("monitor".to_owned());
100+
builder
101+
.add("project", &self.project)
102+
.add("package", &self.package)
103+
.add("rev", &self.rev)
104+
.add("srcmd5", &self.srcmd5)
105+
.add("repository", &self.repository)
106+
.add("arch", &self.arch)
107+
.add("build-log-out", &self.build_log_out);
108+
if let Some(endtime) = &self.prev_endtime_for_commit {
109+
builder.add("prev-endtime-for-commit", &endtime.to_string());
110+
}
111+
builder.build()
112+
}
113+
}
114+
76115
#[derive(Parser, Debug)]
77116
pub struct DownloadBinariesAction {
78117
#[clap(long)]
@@ -87,6 +126,19 @@ pub struct DownloadBinariesAction {
87126
pub build_results_dir: Utf8PathBuf,
88127
}
89128

129+
impl DownloadBinariesAction {
130+
pub fn generate_command(&self) -> String {
131+
let mut builder = CommandBuilder::new("download-binaries".to_owned());
132+
builder
133+
.add("project", &self.project)
134+
.add("package", &self.package)
135+
.add("repository", &self.repository)
136+
.add("arch", &self.arch)
137+
.add("build-results-dir", self.build_results_dir.as_str());
138+
builder.build()
139+
}
140+
}
141+
90142
#[derive(Parser, Debug)]
91143
pub struct PruneAction {
92144
#[clap(long, default_value_t = DEFAULT_BUILD_INFO.to_owned())]

src/artifacts.rs renamed to obs-commander/src/artifacts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ pub trait ArtifactDirectory: Send + Sync {
9797
}
9898
}
9999

100-
#[cfg(test)]
101100
pub mod test_support {
102101
use std::collections::HashMap;
103102

src/binaries.rs renamed to obs-commander/src/binaries.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ mod tests {
7777
use std::time::SystemTime;
7878

7979
use claims::*;
80+
use obs_commander_test_support::*;
8081
use open_build_service_mock::*;
8182

82-
use crate::{artifacts::test_support::MockArtifactDirectory, test_support::*};
83+
use crate::artifacts::test_support::MockArtifactDirectory;
8384

8485
use super::*;
8586

src/build_meta.rs renamed to obs-commander/src/build_meta.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,10 @@ mod tests {
265265
use std::time::{Duration, SystemTime};
266266

267267
use claims::*;
268+
use obs_commander_test_support::*;
268269
use open_build_service_mock::*;
269270
use rstest::rstest;
270271

271-
use crate::test_support::*;
272-
273272
use super::*;
274273

275274
#[tokio::test]
File renamed without changes.

0 commit comments

Comments
 (0)