Skip to content

Commit

Permalink
Add GetDiffData method
Browse files Browse the repository at this point in the history
Add GetDiffData method so that clients can request PR diff data
using RestClient with authentication.
  • Loading branch information
nyankoframe committed May 2, 2021
1 parent 3ebf19b commit 7f497dc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Git.hub/PullRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using RestSharp;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Git.hub
{
Expand Down Expand Up @@ -89,6 +90,23 @@ public List<PullRequestCommit> GetCommits()
return _client.GetList<PullRequestCommit>(request);
}

/// <summary>
/// Retrieves diff data for all Commits associated with this pull request.
/// </summary>
/// <param name="diffUrl">URL for diff data to retrieve</param>
/// <returns><see cref="string"/> that contains diff data</returns>
public async Task<string> GetDiffData(string diffUrl)
{
if (string.IsNullOrEmpty(diffUrl))
{
throw new ArgumentException("Empty diff URL: ", nameof(diffUrl));
}

var request = new RestRequest(diffUrl);
var diffData = await _client.ExecuteGetAsync<string>(request);
return diffData.Content;
}

public Issue ToIssue()
{
return new Issue { _client = _client, Repository = Repository, Number = Number };
Expand Down

0 comments on commit 7f497dc

Please sign in to comment.