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

Add GetDiffData method #18

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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;
Comment on lines +106 to +107
Copy link
Member

Choose a reason for hiding this comment

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

What happens if a request fails? E.g. 401, 404, 500, etc.

Copy link
Author

Choose a reason for hiding this comment

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

It looks like the GIthub plugin gets back text indicating the error message ("Not Found", etc.) and shows an error dialog indicating that it couldn't parse the diff.

I need to debug this further, as it seems even sending the PAT in the headers is not enough for one particular organization.

}

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