Skip to content
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

Implement some api from https://docs.gitlab.com/ee/api/api_resources.… #217

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
6 changes: 6 additions & 0 deletions src/GitLabApiClient/FilesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,5 +17,10 @@ public async Task<File> GetAsync(ProjectId projectId, string filePath, string re
{
return await _httpFacade.Get<File>($"projects/{projectId}/repository/files/{filePath.UrlEncode()}?ref={reference}");
}

public async Task<UpdateFileResponse> UpdateAsync(ProjectId projectId, string filePath, UpdateFileRequest request)
{
return await _httpFacade.Put<UpdateFileResponse>($"projects/{projectId}/repository/files/{filePath}", request);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to encode file path, like in Get method

}
}
}
4 changes: 4 additions & 0 deletions src/GitLabApiClient/IFilesClient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System.Threading.Tasks;
using GitLabApiClient.Internal.Paths;
using GitLabApiClient.Models.Files.Request;
using GitLabApiClient.Models.Files.Responses;

namespace GitLabApiClient
{
public interface IFilesClient
{
Task<File> GetAsync(ProjectId projectId, string filePath, string reference = "master");

Task<UpdateFileResponse> UpdateAsync(ProjectId projectId, string filePath, UpdateFileRequest request);

}
}
13 changes: 13 additions & 0 deletions src/GitLabApiClient/IProjectsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ public interface IProjectsClient
/// <returns>Newly created milestone.</returns>
Task<Milestone> CreateMilestoneAsync(ProjectId projectId, CreateProjectMilestoneRequest request);

/// <summary>
/// Forks a project into the user namespace of the authenticated user or the one provided.
/// </summary>
/// <param name="request">Fork Project request.</param>
/// <returns></returns>
Task<Project> ForkAsync(ForkProjectRequest request);

/// <summary>
/// Delete an existing forked from relationship
/// </summary>
/// <param name="projectId">The ID or URL-encoded path of the project.</param>
Task DeleteForkedRelationshipAsync(ProjectId projectId);

/// <summary>
/// Updates existing project.
/// </summary>
Expand Down
40 changes: 40 additions & 0 deletions src/GitLabApiClient/Models/Files/Request/UpdateFileRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Newtonsoft.Json;

namespace GitLabApiClient.Models.Files.Request
{
public class UpdateFileRequest
{
public UpdateFileRequest(string branch) => Branch = branch;

/// <summary>
/// Name of the branch
/// </summary>
[JsonProperty("branch")]
public string Branch { get; private set; }

/// <summary>
/// Specify the commit author’s email address
/// </summary>
[JsonProperty("author_email")]
public string AuthorEmail { get; set; }

/// <summary>
/// Specify the commit author’s name
/// </summary>
[JsonProperty("author_name")]
public string AuthorName { get; set; }

/// <summary>
/// New file content
/// </summary>
[JsonProperty("content")]
public string Content { get; set; }

/// <summary>
/// Commit message
/// </summary>
[JsonProperty("commit_message")]
public string CommitMessage { get; set; }

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

namespace GitLabApiClient.Models.Files.Responses
{
public class UpdateFileResponse
{
/// <summary>
/// URL encoded full path to new file. Ex. lib%2Fclass%2Erb
/// </summary>
[JsonProperty("file_path")]
public string FilePath { get; set; }

/// <summary>
/// Name of the branch
/// </summary>
[JsonProperty("branch")]
public string Branch { get; set; }
}
}
58 changes: 58 additions & 0 deletions src/GitLabApiClient/Models/Projects/Requests/ForkProjectRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Newtonsoft.Json;

namespace GitLabApiClient.Models.Projects.Requests
{
public class ForkProjectRequest
{
public ForkProjectRequest(int id) => Id = id;

/// <summary>
/// The ID or URL-encoded path of the project.
/// </summary>
[JsonProperty("id")]
public int Id { get; private set; }

/// <summary>
/// The name assigned to the resultant project after forking.
/// </summary>
[JsonProperty("name")]
public string Name { get; private set; }

/// <summary>
/// The ID of the namespace that the project is forked to.
/// </summary>
[JsonProperty("namespace_id")]
public int? NamespaceId { get; set; }

/// <summary>
/// The path of the namespace that the project is forked to.
/// </summary>
[JsonProperty("namespace_path")]
public string NamespacePath { get; set; }

/// <summary>
/// (Deprecated) The ID or path of the namespace that the project is forked to.
/// </summary>
[JsonProperty("namespace")]
public string Namespace { get; set; }

/// <summary>
/// The path assigned to the resultant project after forking.
/// </summary>
[JsonProperty("path")]
public string Path { get; set; }

/// <summary>
/// The description assigned to the resultant project after forking.
/// </summary>
[JsonProperty("description")]
public string Description { get; set; }

/// <summary>
/// The visibility level assigned to the resultant project after forking.
/// </summary>
[JsonProperty("visibility")]
public bool? Visibility { get; set; }

}
}
21 changes: 21 additions & 0 deletions src/GitLabApiClient/ProjectsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ public async Task<Milestone> CreateMilestoneAsync(ProjectId projectId, CreatePro
return await _httpFacade.Post<Milestone>($"projects/{projectId}/milestones", request);
}

/// <summary>
/// Forks a project into the user namespace of the authenticated user or the one provided.
/// </summary>
/// <param name="request">Fork Project request.</param>
/// <returns>Newly Project</returns>
public async Task<Project> ForkAsync(ForkProjectRequest request)
{
Guard.NotNull(request, nameof(request));
return await _httpFacade.Post<Project>($"projects/{request.Id}/fork", request);
}

/// <summary>
/// Delete an existing forked from relationship
/// </summary>
/// <param name="projectId">The ID or URL-encoded path of the project.</param>
public async Task DeleteForkedRelationshipAsync(ProjectId projectId)
{
Guard.NotNull(projectId, nameof(projectId));
await _httpFacade.Delete($"projects/{projectId}/fork");
}

/// <summary>
/// Updates existing project.
/// </summary>
Expand Down