Skip to content

Commit 2ae5ce0

Browse files
authored
Make it possible to create discusion for a specific change (#647)
* Make it possible to create discusion for a specific change * Update PublicAPI.Unshipped.txt * Update MergeRequestDiscussionCreate.cs and PublicAPI.Unshipped.txt
1 parent 204a795 commit 2ae5ce0

File tree

7 files changed

+51
-0
lines changed

7 files changed

+51
-0
lines changed

NGitLab.Mock/Clients/MergeRequestCommentClient.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ public Models.MergeRequestComment Add(MergeRequestCommentCreate commentCreate)
7171
}
7272
}
7373

74+
public Models.MergeRequestComment Add(string discussionId, MergeRequestCommentCreate commentCreate)
75+
{
76+
EnsureUserIsAuthenticated();
77+
78+
using (Context.BeginOperationScope())
79+
{
80+
var project = GetProject(_projectId, ProjectPermission.View);
81+
if (project.Archived)
82+
throw new GitLabForbiddenException();
83+
84+
var comment = new MergeRequestComment
85+
{
86+
Author = Context.User,
87+
Body = commentCreate.Body,
88+
};
89+
90+
GetMergeRequest().Comments.Add(comment);
91+
return comment.ToMergeRequestCommentClient();
92+
}
93+
}
94+
7495
public Models.MergeRequestComment Edit(long id, MergeRequestCommentEdit edit)
7596
{
7697
using (Context.BeginOperationScope())

NGitLab/IMergeRequestCommentClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public interface IMergeRequestCommentClient
1515

1616
MergeRequestComment Add(MergeRequestCommentCreate comment);
1717

18+
MergeRequestComment Add(string discussionId, MergeRequestCommentCreate comment);
19+
1820
MergeRequestComment Edit(long id, MergeRequestCommentEdit comment);
1921

2022
void Delete(long id);

NGitLab/Impl/MergeRequestCommentClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public MergeRequestCommentClient(API api, string projectPath, int mergeRequestIi
2525

2626
public MergeRequestComment Add(MergeRequestCommentCreate comment) => _api.Post().With(comment).To<MergeRequestComment>(_notesPath);
2727

28+
public MergeRequestComment Add(string discussionId, MergeRequestCommentCreate comment) => _api.Post().With(comment).To<MergeRequestComment>(_discussionsPath + "/" + discussionId + "/notes");
29+
2830
public MergeRequestComment Edit(long id, MergeRequestCommentEdit comment) => _api.Put().With(comment).To<MergeRequestComment>(_notesPath + "/" + id.ToString(CultureInfo.InvariantCulture));
2931

3032
public void Delete(long id) => _api.Delete().Execute(_notesPath + "/" + id.ToString(CultureInfo.InvariantCulture));

NGitLab/Models/MergeRequestDiscussionCreate.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ public class MergeRequestDiscussionCreate
1010

1111
[JsonPropertyName("created_at")]
1212
public DateTime? CreatedAt;
13+
14+
[JsonPropertyName("position")]
15+
public Position Position { get; set; }
1316
}

NGitLab/Models/Position.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,13 @@ public class Position
2121

2222
[JsonPropertyName("line_range")]
2323
public LineRange LineRange { get; set; }
24+
25+
[JsonPropertyName("base_sha")]
26+
public Sha1 BaseSha { get; set; }
27+
28+
[JsonPropertyName("head_sha")]
29+
public Sha1 HeadSha { get; set; }
30+
31+
[JsonPropertyName("start_sha")]
32+
public Sha1 StartSha { get; set; }
2433
}

NGitLab/Models/PositionType.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
using System.Runtime.Serialization;
2+
13
namespace NGitLab.Models;
24

35
public enum PositionType
46
{
7+
[EnumMember(Value = "text")]
58
Text,
9+
[EnumMember(Value = "image")]
610
Image,
711
}

NGitLab/PublicAPI.Unshipped.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ NGitLab.IMergeRequestClient.Update(int mergeRequestIid, NGitLab.Models.MergeRequ
414414
NGitLab.IMergeRequestCommentClient
415415
NGitLab.IMergeRequestCommentClient.Add(NGitLab.Models.MergeRequestComment comment) -> NGitLab.Models.MergeRequestComment
416416
NGitLab.IMergeRequestCommentClient.Add(NGitLab.Models.MergeRequestCommentCreate comment) -> NGitLab.Models.MergeRequestComment
417+
NGitLab.IMergeRequestCommentClient.Add(string discussionId, NGitLab.Models.MergeRequestCommentCreate comment) -> NGitLab.Models.MergeRequestComment
417418
NGitLab.IMergeRequestCommentClient.All.get -> System.Collections.Generic.IEnumerable<NGitLab.Models.MergeRequestComment>
418419
NGitLab.IMergeRequestCommentClient.Delete(long id) -> void
419420
NGitLab.IMergeRequestCommentClient.Discussions.get -> System.Collections.Generic.IEnumerable<NGitLab.Models.MergeRequestDiscussion>
@@ -688,6 +689,7 @@ NGitLab.Impl.MergeRequestClient.Update(int mergeRequestIid, NGitLab.Models.Merge
688689
NGitLab.Impl.MergeRequestCommentClient
689690
NGitLab.Impl.MergeRequestCommentClient.Add(NGitLab.Models.MergeRequestComment comment) -> NGitLab.Models.MergeRequestComment
690691
NGitLab.Impl.MergeRequestCommentClient.Add(NGitLab.Models.MergeRequestCommentCreate comment) -> NGitLab.Models.MergeRequestComment
692+
NGitLab.Impl.MergeRequestCommentClient.Add(string discussionId, NGitLab.Models.MergeRequestCommentCreate comment) -> NGitLab.Models.MergeRequestComment
691693
NGitLab.Impl.MergeRequestCommentClient.All.get -> System.Collections.Generic.IEnumerable<NGitLab.Models.MergeRequestComment>
692694
NGitLab.Impl.MergeRequestCommentClient.Delete(long id) -> void
693695
NGitLab.Impl.MergeRequestCommentClient.Discussions.get -> System.Collections.Generic.IEnumerable<NGitLab.Models.MergeRequestDiscussion>
@@ -2376,6 +2378,8 @@ NGitLab.Models.MergeRequestDiscussionCreate
23762378
NGitLab.Models.MergeRequestDiscussionCreate.Body -> string
23772379
NGitLab.Models.MergeRequestDiscussionCreate.CreatedAt -> System.DateTime?
23782380
NGitLab.Models.MergeRequestDiscussionCreate.MergeRequestDiscussionCreate() -> void
2381+
NGitLab.Models.MergeRequestDiscussionCreate.Position.get -> NGitLab.Models.Position
2382+
NGitLab.Models.MergeRequestDiscussionCreate.Position.set -> void
23792383
NGitLab.Models.MergeRequestDiscussionResolve
23802384
NGitLab.Models.MergeRequestDiscussionResolve.Id -> string
23812385
NGitLab.Models.MergeRequestDiscussionResolve.MergeRequestDiscussionResolve() -> void
@@ -2698,6 +2702,10 @@ NGitLab.Models.PipelineVariable.PipelineVariable() -> void
26982702
NGitLab.Models.PipelineVariable.Value -> string
26992703
NGitLab.Models.PipelineVariable.VariableType -> string
27002704
NGitLab.Models.Position
2705+
NGitLab.Models.Position.BaseSha.get -> NGitLab.Sha1
2706+
NGitLab.Models.Position.BaseSha.set -> void
2707+
NGitLab.Models.Position.HeadSha.get -> NGitLab.Sha1
2708+
NGitLab.Models.Position.HeadSha.set -> void
27012709
NGitLab.Models.Position.LineRange.get -> NGitLab.Models.LineRange
27022710
NGitLab.Models.Position.LineRange.set -> void
27032711
NGitLab.Models.Position.NewLine.get -> int?
@@ -2711,6 +2719,8 @@ NGitLab.Models.Position.OldPath.set -> void
27112719
NGitLab.Models.Position.Position() -> void
27122720
NGitLab.Models.Position.PositionType.get -> NGitLab.DynamicEnum<NGitLab.Models.PositionType>
27132721
NGitLab.Models.Position.PositionType.set -> void
2722+
NGitLab.Models.Position.StartSha.get -> NGitLab.Sha1
2723+
NGitLab.Models.Position.StartSha.set -> void
27142724
NGitLab.Models.PositionType
27152725
NGitLab.Models.PositionType.Image = 1 -> NGitLab.Models.PositionType
27162726
NGitLab.Models.PositionType.Text = 0 -> NGitLab.Models.PositionType

0 commit comments

Comments
 (0)