Skip to content

Commit

Permalink
Add Participant and Unsubscribe functionnalities (#726)
Browse files Browse the repository at this point in the history
* Add Parcipant and Unsubscrib functionnalities

* use ProjectId instead of regular int

* add Test

* remove Unsubscribe test method as we don't know if we are subscrib (method is missing

* use incorrect IssueId parameter

---------

Co-authored-by: Thibault Bavard <[email protected]>
  • Loading branch information
tbavard and Thibault Bavard authored Jul 23, 2024
1 parent e5a18c5 commit 1039141
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
10 changes: 10 additions & 0 deletions NGitLab.Mock/Clients/IssueClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,14 @@ private IEnumerable<Issue> FilterByQuery(IEnumerable<Issue> issues, IssueQuery q

return issues;
}

public IEnumerable<Participant> GetParticipants(ProjectId projectId, int issueIid)
{
throw new NotImplementedException();
}

public Models.Issue Unsubscribe(ProjectId projectId, int issueIid)
{
throw new NotImplementedException();
}
}
14 changes: 14 additions & 0 deletions NGitLab.Tests/IssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,18 @@ public async Task Test_get_linked_issue()
// for now, no API to link issues so not links exist but API should not throw
Assert.That(issues, Has.Count.EqualTo(1), $"Expected 1. Got {issues.Count}");
}

[Test]
[NGitLabRetry]
public async Task Test_getparticipants_issue()
{
using var context = await GitLabTestContext.CreateAsync();
var project = context.CreateProject();
var issuesClient = context.Client.Issues;
var issue1 = issuesClient.Create(new IssueCreate { ProjectId = project.Id, Title = "title1", Confidential = true });

var participant = issuesClient.GetParticipants(project.Id, issue1.IssueId);

Assert.That(participant.Count, Is.EqualTo(1));
}
}
16 changes: 16 additions & 0 deletions NGitLab/IIssueClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,20 @@ public interface IIssueClient
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<Issue> CloneAsync(int projectId, int issueIid, IssueClone issueClone, CancellationToken cancellationToken = default);

/// <summary>
/// Get Participants
/// </summary>
/// <param name="projectId">The project id</param>
/// <param name="issueIid">The id of the issue in the project's scope.</param>
/// <returns>The participants of the issue.</returns>
IEnumerable<Participant> GetParticipants(ProjectId projectId, int issueIid);

/// <summary>
/// Unsubscribe to the issue
/// </summary>
/// <param name="projectId">The project id</param>
/// <param name="issueIid">The id of the issue in the project's scope.</param>
/// <returns>The issue that corresponds to the project id and issue id</returns>
Issue Unsubscribe(ProjectId projectId, int issueIid);
}
12 changes: 12 additions & 0 deletions NGitLab/Impl/IssueClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class IssueClient : IIssueClient
private const string ClosedByUrl = "/projects/{0}/issues/{1}/closed_by";
private const string TimeStatsUrl = "/projects/{0}/issues/{1}/time_stats";
private const string CloneIssueUrl = "/projects/{0}/issues/{1}/clone";
private const string ParticipantsUrl = "/projects/{0}/issues/{1}/participants";
private const string UnsubscribeUrl = "/projects/{0}/issues/{1}/unsubscribe";

private readonly API _api;

Expand Down Expand Up @@ -192,6 +194,16 @@ public Task<Issue> CloneAsync(int projectId, int issueIid, IssueClone issueClone
return _api.Post().With(issueClone).ToAsync<Issue>(string.Format(CultureInfo.InvariantCulture, CloneIssueUrl, projectId, issueIid), cancellationToken);
}

public IEnumerable<Participant> GetParticipants(ProjectId projectId, int issueIid)
{
return _api.Get().GetAll<Participant>(string.Format(CultureInfo.InvariantCulture, ParticipantsUrl, projectId.ValueAsUriParameter(), issueIid));
}

public Issue Unsubscribe(ProjectId projectId, int issueIid)
{
return _api.Post().To<Issue>(string.Format(CultureInfo.InvariantCulture, UnsubscribeUrl, projectId.ValueAsUriParameter(), issueIid));
}

private GitLabCollectionResponse<Issue> Get(string url, IssueQuery query)
{
url = AddIssueQueryParameters(url, query);
Expand Down
24 changes: 24 additions & 0 deletions NGitLab/Models/Participant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Text.Json.Serialization;

namespace NGitLab.Models;

public class Participant
{
[JsonPropertyName("id")]
public int Id { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("username")]
public string Username { get; set; }

[JsonPropertyName("state")]
public string State { get; set; }

[JsonPropertyName("avatar_url")]
public string AvatarURL { get; set; }

[JsonPropertyName("web_url")]
public string WebUrl { get; set; }
}
18 changes: 18 additions & 0 deletions NGitLab/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ NGitLab.IIssueClient.GetAsync(int projectId, NGitLab.Models.IssueQuery query) ->
NGitLab.IIssueClient.GetAsync(NGitLab.Models.IssueQuery query) -> NGitLab.GitLabCollectionResponse<NGitLab.Models.Issue>
NGitLab.IIssueClient.GetById(int issueId) -> NGitLab.Models.Issue
NGitLab.IIssueClient.GetByIdAsync(int issueId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<NGitLab.Models.Issue>
NGitLab.IIssueClient.GetParticipants(NGitLab.Models.ProjectId projectId, int issueIid) -> System.Collections.Generic.IEnumerable<NGitLab.Models.Participant>
NGitLab.IIssueClient.LinkedToAsync(int projectId, int issueId) -> NGitLab.GitLabCollectionResponse<NGitLab.Models.Issue>
NGitLab.IIssueClient.Owned.get -> System.Collections.Generic.IEnumerable<NGitLab.Models.Issue>
NGitLab.IIssueClient.RelatedTo(int projectId, int issueIid) -> System.Collections.Generic.IEnumerable<NGitLab.Models.MergeRequest>
Expand All @@ -358,6 +359,7 @@ NGitLab.IIssueClient.ResourceMilestoneEventsAsync(int projectId, int issueIid) -
NGitLab.IIssueClient.ResourceStateEvents(int projectId, int issueIid) -> System.Collections.Generic.IEnumerable<NGitLab.Models.ResourceStateEvent>
NGitLab.IIssueClient.ResourceStateEventsAsync(int projectId, int issueIid) -> NGitLab.GitLabCollectionResponse<NGitLab.Models.ResourceStateEvent>
NGitLab.IIssueClient.TimeStatsAsync(int projectId, int issueIid, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<NGitLab.Models.TimeStats>
NGitLab.IIssueClient.Unsubscribe(NGitLab.Models.ProjectId projectId, int issueIid) -> NGitLab.Models.Issue
NGitLab.IJobClient
NGitLab.IJobClient.Get(int jobId) -> NGitLab.Models.Job
NGitLab.IJobClient.GetAsync(int jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<NGitLab.Models.Job>
Expand Down Expand Up @@ -640,6 +642,7 @@ NGitLab.Impl.IssueClient.GetAsync(int projectId, NGitLab.Models.IssueQuery query
NGitLab.Impl.IssueClient.GetAsync(NGitLab.Models.IssueQuery query) -> NGitLab.GitLabCollectionResponse<NGitLab.Models.Issue>
NGitLab.Impl.IssueClient.GetById(int issueId) -> NGitLab.Models.Issue
NGitLab.Impl.IssueClient.GetByIdAsync(int issueId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<NGitLab.Models.Issue>
NGitLab.Impl.IssueClient.GetParticipants(NGitLab.Models.ProjectId projectId, int issueIid) -> System.Collections.Generic.IEnumerable<NGitLab.Models.Participant>
NGitLab.Impl.IssueClient.IssueClient(NGitLab.Impl.API api) -> void
NGitLab.Impl.IssueClient.LinkedToAsync(int projectId, int issueId) -> NGitLab.GitLabCollectionResponse<NGitLab.Models.Issue>
NGitLab.Impl.IssueClient.Owned.get -> System.Collections.Generic.IEnumerable<NGitLab.Models.Issue>
Expand All @@ -652,6 +655,7 @@ NGitLab.Impl.IssueClient.ResourceMilestoneEventsAsync(int projectId, int issueIi
NGitLab.Impl.IssueClient.ResourceStateEvents(int projectId, int issueIid) -> System.Collections.Generic.IEnumerable<NGitLab.Models.ResourceStateEvent>
NGitLab.Impl.IssueClient.ResourceStateEventsAsync(int projectId, int issueIid) -> NGitLab.GitLabCollectionResponse<NGitLab.Models.ResourceStateEvent>
NGitLab.Impl.IssueClient.TimeStatsAsync(int projectId, int issueIid, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<NGitLab.Models.TimeStats>
NGitLab.Impl.IssueClient.Unsubscribe(NGitLab.Models.ProjectId projectId, int issueIid) -> NGitLab.Models.Issue
NGitLab.Impl.JobClient
NGitLab.Impl.JobClient.Get(int jobId) -> NGitLab.Models.Job
NGitLab.Impl.JobClient.GetAsync(int jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<NGitLab.Models.Job>
Expand Down Expand Up @@ -2750,6 +2754,20 @@ NGitLab.Models.PageQuery<TQueryType>
NGitLab.Models.PageQuery<TQueryType>.PageQuery(int page = 1, int perPage = 20, TQueryType query = default(TQueryType)) -> void
NGitLab.Models.PageQuery<TQueryType>.Query.get -> TQueryType
NGitLab.Models.PageQuery<TQueryType>.Query.set -> void
NGitLab.Models.Participant
NGitLab.Models.Participant.Participant() -> void
NGitLab.Models.Participant.Id.get -> int
NGitLab.Models.Participant.Id.set -> void
NGitLab.Models.Participant.AvatarURL.get -> string
NGitLab.Models.Participant.AvatarURL.set -> void
NGitLab.Models.Participant.Name.get -> string
NGitLab.Models.Participant.Name.set -> void
NGitLab.Models.Participant.State.get -> string
NGitLab.Models.Participant.State.set -> void
NGitLab.Models.Participant.Username.get -> string
NGitLab.Models.Participant.Username.set -> void
NGitLab.Models.Participant.WebUrl.get -> string
NGitLab.Models.Participant.WebUrl.set -> void
NGitLab.Models.PersonInfo
NGitLab.Models.PersonInfo.Email -> string
NGitLab.Models.PersonInfo.Name -> string
Expand Down

0 comments on commit 1039141

Please sign in to comment.