Skip to content

[feature] list, create and force sync remote mirrors for a project #273

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions src/GitLabApiClient/IProjectsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,30 @@ public interface IProjectsClient
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <returns>Status of the import</returns>
Task<ImportStatus> GetImportStatusAsync(ProjectId projectId);

/// <summary>
/// Gets the remote mirrors for a project.
/// </summary>
/// <param name="projectId">The project identifier.</param>
/// <returns>List of remote mirrors</returns>
Task<IList<RemoteMirror>> GetRemoteMirrorsAsync(ProjectId projectId);

/// <summary>
/// Creates a remote mirror in a project.
/// </summary>
/// <param name="projectId">The project identifier.</param>
/// <param name="request">The request <see cref="CreateRemoteMirrorRequest"/>.</param>
/// <returns>An instance of <see cref="RemoteMirror"/></returns>

Task<RemoteMirror> CreateRemoteMirrorAsync(ProjectId projectId, CreateRemoteMirrorRequest request);

/// <summary>
/// Forces the mirror to sync.
/// </summary>
/// <param name="projectId">The project identifier.</param>
/// <param name="mirrorId">The mirror identifier.</param>

Task ForceSyncMirrorAsync(ProjectId projectId, int mirrorId);

}
}
10 changes: 2 additions & 8 deletions src/GitLabApiClient/Internal/Paths/ProjectId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ public class ProjectId
/// </summary>
/// <param name="projectPath">The project path ie. 'group/project'</param>
/// <returns></returns>
public static implicit operator ProjectId(string projectPath)
{
return new ProjectId(projectPath.UrlEncode());
}
public static implicit operator ProjectId(string projectPath) => new ProjectId(projectPath.UrlEncode());

public static implicit operator ProjectId(int projectId)
{
return new ProjectId(projectId.ToString());
}
public static implicit operator ProjectId(int projectId) => new ProjectId(projectId.ToString());

public static implicit operator ProjectId(Project project)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Newtonsoft.Json;

namespace GitLabApiClient.Models.Projects.Requests
{
public class CreateRemoteMirrorRequest
{

[JsonProperty("url", NullValueHandling = NullValueHandling.Ignore)]
public string Url { get; set; }

[JsonProperty("enabled", NullValueHandling = NullValueHandling.Ignore)]
public bool? Enabled { get; set; }

/// <summary>
/// Gets or sets the authentication method.
/// </summary>
/// <value>
/// ssh_public_key or password
/// </value>
[JsonProperty("auth_method", NullValueHandling = NullValueHandling.Ignore)]
public string AuthMethod { get; set; }

[JsonProperty("only_protected_branches", NullValueHandling = NullValueHandling.Ignore)]
public bool? OnlyProtectedBranches { get; set; }

[JsonProperty("keep_divergent_refs", NullValueHandling = NullValueHandling.Ignore)]
public bool? KeepDivergentRefs { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Newtonsoft.Json;

namespace GitLabApiClient.Models.Projects.Requests
Expand Down
2 changes: 2 additions & 0 deletions src/GitLabApiClient/Models/Projects/Responses/ImportStatus.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Newtonsoft.Json;

namespace GitLabApiClient.Models.Projects.Responses
Expand Down Expand Up @@ -28,4 +29,5 @@ public sealed class ImportStatus
[JsonProperty("import_status")]
public ImportStatusEnum Status { get; set; }
}

}
41 changes: 41 additions & 0 deletions src/GitLabApiClient/Models/Projects/Responses/RemoteMirror.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using Newtonsoft.Json;

namespace GitLabApiClient.Models.Projects.Responses
{
public class RemoteMirror
{
[JsonProperty("enabled", NullValueHandling = NullValueHandling.Ignore)]
public bool? Enabled { get; set; }

[JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)]
public int? Id { get; set; }

[JsonProperty("auth_method", NullValueHandling = NullValueHandling.Ignore)]
public string AuthMethod { get; set; }

[JsonProperty("last_error", NullValueHandling = NullValueHandling.Ignore)]
public object LastError { get; set; }

[JsonProperty("last_successful_update_at", NullValueHandling = NullValueHandling.Ignore)]
public DateTime? LastSuccessfulUpdateAt { get; set; }

[JsonProperty("last_update_at", NullValueHandling = NullValueHandling.Ignore)]
public DateTime? LastUpdateAt { get; set; }

[JsonProperty("last_update_started_at", NullValueHandling = NullValueHandling.Ignore)]
public DateTime? LastUpdateStartedAt { get; set; }

[JsonProperty("only_protected_branches", NullValueHandling = NullValueHandling.Ignore)]
public bool? OnlyProtectedBranches { get; set; }

[JsonProperty("keep_divergent_refs", NullValueHandling = NullValueHandling.Ignore)]
public bool? KeepDivergentRefs { get; set; }

[JsonProperty("update_status", NullValueHandling = NullValueHandling.Ignore)]
public string UpdateStatus { get; set; }

[JsonProperty("url", NullValueHandling = NullValueHandling.Ignore)]
public string Url { get; set; }
}
}
30 changes: 29 additions & 1 deletion src/GitLabApiClient/ProjectsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public async Task<IList<Job>> GetJobsAsync(ProjectId projectId, Action<JobQueryO
var queryOptions = new JobQueryOptions();
options?.Invoke(queryOptions);

var url = _jobQueryBuilder.Build($"projects/{projectId}/jobs", queryOptions);
string url = _jobQueryBuilder.Build($"projects/{projectId}/jobs", queryOptions);
return await _httpFacade.GetPagedList<Job>(url);
}

Expand Down Expand Up @@ -335,5 +335,33 @@ public async Task<ImportStatus> GetImportStatusAsync(ProjectId projectId)
{
return await _httpFacade.Get<ImportStatus>($"projects/{projectId}/import");
}

/// <summary>
/// Gets the remote mirrors for a project.
/// </summary>
/// <param name="projectId">The project identifier.</param>
/// <returns>List of remote mirrors</returns>
public async Task<IList<RemoteMirror>> GetRemoteMirrorsAsync(ProjectId projectId)
{
return await _httpFacade.Get<IList<RemoteMirror>>($"projects/{projectId}/remote_mirrors");
}

/// <summary>
/// Creates a remote mirror in a project.
/// </summary>
/// <param name="projectId">The project identifier.</param>
/// <param name="request">The request <see cref="CreateRemoteMirrorRequest"/>.</param>
/// <returns></returns>
public async Task<RemoteMirror> CreateRemoteMirrorAsync(ProjectId projectId, CreateRemoteMirrorRequest request)
{
return await _httpFacade.Post<RemoteMirror>($"projects/{projectId}/remote_mirrors", request);
}

/// <summary>
/// Forces the mirror to sync.
/// </summary>
/// <param name="projectId">The project identifier.</param>
/// <param name="mirrorId">The mirror identifier.</param>
public async Task ForceSyncMirrorAsync(ProjectId projectId, int mirrorId) => await _httpFacade.Post($"projects/{projectId}/remote_mirrors/{mirrorId}/sync");
}
}