diff --git a/src/GitLabApiClient/FilesClient.cs b/src/GitLabApiClient/FilesClient.cs index 57e14f8c..01aedafc 100644 --- a/src/GitLabApiClient/FilesClient.cs +++ b/src/GitLabApiClient/FilesClient.cs @@ -2,6 +2,7 @@ using GitLabApiClient.Internal.Http; using GitLabApiClient.Internal.Paths; using GitLabApiClient.Internal.Utilities; +using GitLabApiClient.Models.Files.Request; using GitLabApiClient.Models.Files.Responses; namespace GitLabApiClient @@ -16,5 +17,10 @@ public async Task GetAsync(ProjectId projectId, string filePath, string re { return await _httpFacade.Get($"projects/{projectId}/repository/files/{filePath.UrlEncode()}?ref={reference}"); } + + public async Task UpdateAsync(ProjectId projectId, string filePath, UpdateFileRequest request) + { + return await _httpFacade.Put($"projects/{projectId}/repository/files/{filePath}", request); + } } } diff --git a/src/GitLabApiClient/IFilesClient.cs b/src/GitLabApiClient/IFilesClient.cs index f848d759..9521066c 100644 --- a/src/GitLabApiClient/IFilesClient.cs +++ b/src/GitLabApiClient/IFilesClient.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using GitLabApiClient.Internal.Paths; +using GitLabApiClient.Models.Files.Request; using GitLabApiClient.Models.Files.Responses; namespace GitLabApiClient @@ -7,5 +8,8 @@ namespace GitLabApiClient public interface IFilesClient { Task GetAsync(ProjectId projectId, string filePath, string reference = "master"); + + Task UpdateAsync(ProjectId projectId, string filePath, UpdateFileRequest request); + } } diff --git a/src/GitLabApiClient/IProjectsClient.cs b/src/GitLabApiClient/IProjectsClient.cs index 75df4984..7c1b57d5 100644 --- a/src/GitLabApiClient/IProjectsClient.cs +++ b/src/GitLabApiClient/IProjectsClient.cs @@ -106,6 +106,19 @@ public interface IProjectsClient /// Newly created milestone. Task CreateMilestoneAsync(ProjectId projectId, CreateProjectMilestoneRequest request); + /// + /// Forks a project into the user namespace of the authenticated user or the one provided. + /// + /// Fork Project request. + /// + Task ForkAsync(ForkProjectRequest request); + + /// + /// Delete an existing forked from relationship + /// + /// The ID or URL-encoded path of the project. + Task DeleteForkedRelationshipAsync(ProjectId projectId); + /// /// Updates existing project. /// diff --git a/src/GitLabApiClient/Models/Files/Request/UpdateFileRequest.cs b/src/GitLabApiClient/Models/Files/Request/UpdateFileRequest.cs new file mode 100644 index 00000000..b49f39c0 --- /dev/null +++ b/src/GitLabApiClient/Models/Files/Request/UpdateFileRequest.cs @@ -0,0 +1,40 @@ +using Newtonsoft.Json; + +namespace GitLabApiClient.Models.Files.Request +{ + public class UpdateFileRequest + { + public UpdateFileRequest(string branch) => Branch = branch; + + /// + /// Name of the branch + /// + [JsonProperty("branch")] + public string Branch { get; private set; } + + /// + /// Specify the commit author’s email address + /// + [JsonProperty("author_email")] + public string AuthorEmail { get; set; } + + /// + /// Specify the commit author’s name + /// + [JsonProperty("author_name")] + public string AuthorName { get; set; } + + /// + /// New file content + /// + [JsonProperty("content")] + public string Content { get; set; } + + /// + /// Commit message + /// + [JsonProperty("commit_message")] + public string CommitMessage { get; set; } + + } +} diff --git a/src/GitLabApiClient/Models/Files/Responses/UpdateFileResponse.cs b/src/GitLabApiClient/Models/Files/Responses/UpdateFileResponse.cs new file mode 100644 index 00000000..0034aff0 --- /dev/null +++ b/src/GitLabApiClient/Models/Files/Responses/UpdateFileResponse.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace GitLabApiClient.Models.Files.Responses +{ + public class UpdateFileResponse + { + /// + /// URL encoded full path to new file. Ex. lib%2Fclass%2Erb + /// + [JsonProperty("file_path")] + public string FilePath { get; set; } + + /// + /// Name of the branch + /// + [JsonProperty("branch")] + public string Branch { get; set; } + } +} diff --git a/src/GitLabApiClient/Models/Projects/Requests/ForkProjectRequest.cs b/src/GitLabApiClient/Models/Projects/Requests/ForkProjectRequest.cs new file mode 100644 index 00000000..69aa1129 --- /dev/null +++ b/src/GitLabApiClient/Models/Projects/Requests/ForkProjectRequest.cs @@ -0,0 +1,58 @@ +using Newtonsoft.Json; + +namespace GitLabApiClient.Models.Projects.Requests +{ + public class ForkProjectRequest + { + public ForkProjectRequest(int id) => Id = id; + + /// + /// The ID or URL-encoded path of the project. + /// + [JsonProperty("id")] + public int Id { get; private set; } + + /// + /// The name assigned to the resultant project after forking. + /// + [JsonProperty("name")] + public string Name { get; private set; } + + /// + /// The ID of the namespace that the project is forked to. + /// + [JsonProperty("namespace_id")] + public int? NamespaceId { get; set; } + + /// + /// The path of the namespace that the project is forked to. + /// + [JsonProperty("namespace_path")] + public string NamespacePath { get; set; } + + /// + /// (Deprecated) The ID or path of the namespace that the project is forked to. + /// + [JsonProperty("namespace")] + public string Namespace { get; set; } + + /// + /// The path assigned to the resultant project after forking. + /// + [JsonProperty("path")] + public string Path { get; set; } + + /// + /// The description assigned to the resultant project after forking. + /// + [JsonProperty("description")] + public string Description { get; set; } + + /// + /// The visibility level assigned to the resultant project after forking. + /// + [JsonProperty("visibility")] + public bool? Visibility { get; set; } + + } +} diff --git a/src/GitLabApiClient/ProjectsClient.cs b/src/GitLabApiClient/ProjectsClient.cs index ffd52c0f..5bdf837c 100644 --- a/src/GitLabApiClient/ProjectsClient.cs +++ b/src/GitLabApiClient/ProjectsClient.cs @@ -172,6 +172,27 @@ public async Task CreateMilestoneAsync(ProjectId projectId, CreatePro return await _httpFacade.Post($"projects/{projectId}/milestones", request); } + /// + /// Forks a project into the user namespace of the authenticated user or the one provided. + /// + /// Fork Project request. + /// Newly Project + public async Task ForkAsync(ForkProjectRequest request) + { + Guard.NotNull(request, nameof(request)); + return await _httpFacade.Post($"projects/{request.Id}/fork", request); + } + + /// + /// Delete an existing forked from relationship + /// + /// The ID or URL-encoded path of the project. + public async Task DeleteForkedRelationshipAsync(ProjectId projectId) + { + Guard.NotNull(projectId, nameof(projectId)); + await _httpFacade.Delete($"projects/{projectId}/fork"); + } + /// /// Updates existing project. ///