Skip to content

Commit

Permalink
issue-54: preserve project name in backup repository. (#57)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Tikhonov <[email protected]>
  • Loading branch information
e-ma-a2 and Ivan Tikhonov authored Feb 14, 2023
1 parent 3ef36f9 commit 4c91fe1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/gitlab/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Client {

pub async fn make_project(
&self,
name: String,
slug: String,
group_id: types::GroupId,
info: &types::Project,
) -> reqwest::Result<types::Project> {
Expand All @@ -168,7 +168,8 @@ impl Client {
namespace_id: types::GroupId,
}

let path = name.clone();
let name = info.name.clone();
let path = slug.clone();
let namespace_id = group_id;
let description = self.make_project_description(info.description.clone());

Expand Down Expand Up @@ -252,7 +253,7 @@ impl Client {
project_info: &types::Project,
) -> reqwest::Result<types::Project> {
let mut parent_id = root_group.as_ref().map(|gr| gr.id);
let project_name = path.pop().expect("invalid project path");
let project_slug = path.pop().expect("invalid project path");
let mut current_namespace = root_group
.as_ref()
.map(|gr| gr.full_path.clone())
Expand All @@ -274,13 +275,13 @@ impl Client {
}

match self
.project_exist(format!("{}/{}", current_namespace, project_name))
.project_exist(format!("{}/{}", current_namespace, project_slug))
.await?
{
Some(p) => self.update_project(&p, project_info).await,
None => {
self.make_project(
project_name,
project_slug,
parent_id.unwrap_or_else(|| {
panic!(
"Parent group for project {} not found",
Expand Down
10 changes: 8 additions & 2 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mod tests {
#[derive(Deserialize)]
struct Project {
description: String,
name: String,
}

let url_prefix = format!("{}api/v4/projects", GITLAB_HOST);
Expand Down Expand Up @@ -90,14 +91,19 @@ mod tests {
}

// check description
let projects = vec![p1_name, p2_name, p3_name];
for project in projects {
let projects = vec![
(p1_name, "project_1"),
(p2_name, "Project 2"),
(p3_name, "project_3"),
];
for (project, project_name) in projects {
let url = format!("{}/{}?access_token={}", url_prefix, project, gitlab_token);
let resp = client.get(url).send().unwrap().error_for_status().unwrap();
let p = resp.json::<Project>().unwrap();
let d_time_str = p.description.split(" 🦞 Synced: ").last().unwrap();
let d_time = DateTime::parse_from_rfc3339(d_time_str).unwrap();
assert!(d_time >= start_time);
assert!(p.name == project_name);
}
}

Expand Down

0 comments on commit 4c91fe1

Please sign in to comment.