Skip to content
Open
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
102 changes: 87 additions & 15 deletions src/Bitbucket.Net/Core/Projects/BitbucketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,49 @@ private IFlurlRequest GetProjectUrl(string projectKey) => GetProjectsUrl()
private IFlurlRequest GetProjectsReposUrl(string projectKey, string repositorySlug, string path) => GetProjectsReposUrl(projectKey, repositorySlug)
.AppendPathSegment(path);

private static object GetCreatePullRequestCommentPayload(
string text,
string parentId = null,
DiffTypes? diffType = null,
string fromHash = null,
string path = null,
string srcPath = null,
string toHash = null,
int? line = null,
FileTypes? fileType = null,
LineTypes? lineType = null)
{
var parent = parentId == null ? null : new { id = parentId };

// We only want to include the anchor if there's anchor data available. Otherwise we'll get a 500 HTTP response when POSTing
if (diffType != null || fromHash != null || path != null || srcPath != null
|| toHash != null || line != null || fileType != null || lineType != null)
{
return new
{
text,
parent,
anchor = new
{
diffType = BitbucketHelpers.DiffTypeToString(diffType),
fromHash,
path,
srcPath,
toHash,
line,
fileType = BitbucketHelpers.FileTypeToString(fileType),
lineType = BitbucketHelpers.LineTypeToString(lineType)
}
};
}

return new
{
text,
parent,
};
}

public async Task<IEnumerable<Project>> GetProjectsAsync(
int? maxPages = null,
int? limit = null,
Expand Down Expand Up @@ -1254,22 +1297,18 @@ public async Task<CommentRef> CreatePullRequestCommentAsync(string projectKey, s
FileTypes? fileType = null,
LineTypes? lineType = null)
{
var data = new
{
var data = GetCreatePullRequestCommentPayload(
text,
parent = parentId == null ? null : new { id = parentId },
anchor = new
{
diffType = BitbucketHelpers.DiffTypeToString(diffType),
fromHash,
path,
srcPath,
toHash,
line,
fileType = BitbucketHelpers.FileTypeToString(fileType),
lineType = BitbucketHelpers.LineTypeToString(lineType)
}
};
parentId,
diffType,
fromHash,
path,
srcPath,
toHash,
line,
fileType,
lineType
);

var response = await GetProjectsReposUrl(projectKey, repositorySlug)
.AppendPathSegment($"/pull-requests/{pullRequestId}/comments")
Expand Down Expand Up @@ -1350,6 +1389,39 @@ public async Task<bool> DeletePullRequestCommentAsync(string projectKey, string
return await HandleResponseAsync(response).ConfigureAwait(false);
}

public async Task<CommentRef> CreatePullRequestBlockerCommentAsync(string projectKey, string repositorySlug, long pullRequestId,
string text,
string parentId = null,
DiffTypes? diffType = null,
string fromHash = null,
string path = null,
string srcPath = null,
string toHash = null,
int? line = null,
FileTypes? fileType = null,
LineTypes? lineType = null)
{
var data = GetCreatePullRequestCommentPayload(
text,
parentId,
diffType,
fromHash,
path,
srcPath,
toHash,
line,
fileType,
lineType
);

var response = await GetProjectsReposUrl(projectKey, repositorySlug)
.AppendPathSegment($"/pull-requests/{pullRequestId}/blocker-comments")
.PostJsonAsync(data)
.ConfigureAwait(false);

return await HandleResponseAsync<CommentRef>(response).ConfigureAwait(false);
}

public async Task<IEnumerable<Commit>> GetPullRequestCommitsAsync(string projectKey, string repositorySlug, long pullRequestId,
bool withCounts = false,
int? maxPages = null,
Expand Down