Skip to content

Commit

Permalink
Merge pull request #1039 from gabrielweyer/fix-api-fields
Browse files Browse the repository at this point in the history
Added missing fields from API and removed fields that are not returned by API
  • Loading branch information
haacked committed Jan 2, 2016
2 parents 87b460c + 34d1374 commit 0b5bb00
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 27 deletions.
16 changes: 16 additions & 0 deletions Octokit.Tests.Integration/Clients/IssuesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ public IssuesClientTests()
_context = github.CreateRepositoryContext(new NewRepository(repoName)).Result;
}

[IntegrationTest]
public async Task CanDeserializeIssue()
{
const string title = "a test issue";
const string description = "A new unassigned issue";
var newIssue = new NewIssue(title) { Body = description };
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number);

Assert.NotNull(retrieved);
Assert.NotEqual(0, issue.Id);
Assert.Equal(false, issue.Locked);
Assert.Equal(title, retrieved.Title);
Assert.Equal(description, retrieved.Body);
}

[IntegrationTest]
public async Task CanCreateRetrieveAndCloseIssue()
{
Expand Down
25 changes: 18 additions & 7 deletions Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

public class IssuesEventsClientTests : IDisposable
{
private readonly IIssuesEventsClient _issuesEventsClientClient;
private readonly IIssuesEventsClient _issuesEventsClient;
private readonly IIssuesClient _issuesClient;
private readonly RepositoryContext _context;

public IssuesEventsClientTests()
{
var github = Helper.GetAuthenticatedClient();

_issuesEventsClientClient = github.Issue.Events;
_issuesEventsClient = github.Issue.Events;
_issuesClient = github.Issue;
var repoName = Helper.MakeNameWithTimestamp("public-repo");

Expand All @@ -30,13 +30,13 @@ public async Task CanListEventInfoForAnIssue()
var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" };
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);

var issueEventInfo = await _issuesEventsClientClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
var issueEventInfo = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
Assert.Empty(issueEventInfo);

var closed = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed);
issueEventInfo = await _issuesEventsClientClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
issueEventInfo = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);

Assert.Equal(1, issueEventInfo.Count);
Assert.Equal(EventInfoState.Closed, issueEventInfo[0].Event);
Expand Down Expand Up @@ -67,7 +67,7 @@ public async Task CanListIssueEventsForARepository()
.Result;
Assert.NotNull(closed2);

var issueEvents = await _issuesEventsClientClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);
var issueEvents = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);

Assert.Equal(3, issueEvents.Count);
Assert.Equal(2, issueEvents.Count(issueEvent => issueEvent.Issue.Body == "Everything's coming up Millhouse"));
Expand All @@ -81,10 +81,10 @@ public async Task CanRetrieveIssueEventById()
var closed = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed);
var issueEvents = await _issuesEventsClientClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);
var issueEvents = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);
int issueEventId = issueEvents[0].Id;

var issueEventLookupById = await _issuesEventsClientClient.Get(_context.RepositoryOwner, _context.RepositoryName, issueEventId);
var issueEventLookupById = await _issuesEventsClient.Get(_context.RepositoryOwner, _context.RepositoryName, issueEventId);

Assert.Equal(issueEventId, issueEventLookupById.Id);
Assert.Equal(issueEvents[0].Event, issueEventLookupById.Event);
Expand All @@ -98,6 +98,17 @@ public async Task CanDeserializeUnsubscribeEvent()
Assert.Equal(EventInfoState.Unsubscribed, issue.Event);
}

[IntegrationTest]
public async Task CanDeserializeMergedEvent()
{
var issueEvent = await _issuesEventsClient.Get("octokit", "octokit.net", 490490630);

Assert.NotNull(issueEvent);
Assert.Equal(EventInfoState.Merged, issueEvent.Event);
Assert.Equal("0bb8747a0ad1a9efff201ea017a0a6a4f69b797e", issueEvent.CommitId);
Assert.Equal(new Uri("https://api.github.com/repos/octokit/octokit.net/commits/0bb8747a0ad1a9efff201ea017a0a6a4f69b797e"), issueEvent.CommitUrl);
}

public void Dispose()
{
_context.Dispose();
Expand Down
26 changes: 13 additions & 13 deletions Octokit.Tests/Clients/EventsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,18 +360,18 @@ public async Task DeserializesIssueEventCorrectly()
{
"payload", new
{
action = "assigned",
action = "created",
issue = new
{
number = 1337
},
assignee = new
{
id = 1337
},
label = new
{
name = "bug"
number = 1337,
assignee = new
{
id = 1337
},
labels = new[]
{
new { name = "bug"}
}
}
}
}
Expand All @@ -382,10 +382,10 @@ public async Task DeserializesIssueEventCorrectly()
Assert.Equal(1, activities.Count);

var payload = activities.FirstOrDefault().Payload as IssueEventPayload;
Assert.Equal("assigned", payload.Action);
Assert.Equal("created", payload.Action);
Assert.Equal(1337, payload.Issue.Number);
Assert.Equal(1337, payload.Assignee.Id);
Assert.Equal("bug", payload.Label.Name);
Assert.Equal(1337, payload.Issue.Assignee.Id);
Assert.Equal("bug", payload.Issue.Labels.First().Name);
}

[Fact]
Expand Down
5 changes: 2 additions & 3 deletions Octokit/Clients/IssuesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,9 @@ public Task<Issue> Create(string owner, string name, NewIssue newIssue)
}

/// <summary>
/// Creates an issue for the specified repository. Any user with pull access to a repository can create an
/// issue.
/// Updates an issue for the specified repository. Issue owners and users with push access can edit an issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/#create-an-issue</remarks>
/// <remarks>https://developer.github.com/v3/issues/#edit-an-issue</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The issue number</param>
Expand Down
2 changes: 0 additions & 2 deletions Octokit/Models/Response/ActivityPayloads/IssueEventPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ public class IssueEventPayload : ActivityPayload
{
public string Action { get; protected set; }
public Issue Issue { get; protected set; }
public User Assignee { get; protected set; }
public Label Label { get; protected set; }
}
}
14 changes: 13 additions & 1 deletion Octokit/Models/Response/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public class Issue
{
public Issue() { }

public Issue(Uri url, Uri htmlUrl, Uri commentsUrl, Uri eventsUrl, int number, ItemState state, string title, string body, User user, IReadOnlyList<Label> labels, User assignee, Milestone milestone, int comments, PullRequest pullRequest, DateTimeOffset? closedAt, DateTimeOffset createdAt, DateTimeOffset? updatedAt)
public Issue(Uri url, Uri htmlUrl, Uri commentsUrl, Uri eventsUrl, int number, ItemState state, string title, string body, User user, IReadOnlyList<Label> labels, User assignee, Milestone milestone, int comments, PullRequest pullRequest, DateTimeOffset? closedAt, DateTimeOffset createdAt, DateTimeOffset? updatedAt, int id, bool locked)
{
Id = id;
Url = url;
HtmlUrl = htmlUrl;
CommentsUrl = commentsUrl;
Expand All @@ -29,8 +30,14 @@ public Issue(Uri url, Uri htmlUrl, Uri commentsUrl, Uri eventsUrl, int number, I
ClosedAt = closedAt;
CreatedAt = createdAt;
UpdatedAt = updatedAt;
Locked = locked;
}

/// <summary>
/// The Id for this issue
/// </summary>
public int Id { get; protected set; }

/// <summary>
/// The URL for this issue.
/// </summary>
Expand Down Expand Up @@ -113,6 +120,11 @@ public Issue(Uri url, Uri htmlUrl, Uri commentsUrl, Uri eventsUrl, int number, I
/// </summary>
public DateTimeOffset? UpdatedAt { get; protected set; }

/// <summary>
/// If the issue is locked or not
/// </summary>
public bool Locked { get; protected set; }

internal string DebuggerDisplay
{
get
Expand Down
8 changes: 7 additions & 1 deletion Octokit/Models/Response/IssueEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class IssueEvent
{
public IssueEvent() { }

public IssueEvent(int id, Uri url, User actor, User assignee, Label label, EventInfoState @event, string commitId, DateTimeOffset createdAt, Issue issue)
public IssueEvent(int id, Uri url, User actor, User assignee, Label label, EventInfoState @event, string commitId, DateTimeOffset createdAt, Issue issue, Uri commitUrl)
{
Id = id;
Url = url;
Expand All @@ -20,6 +20,7 @@ public IssueEvent(int id, Uri url, User actor, User assignee, Label label, Event
CommitId = commitId;
CreatedAt = createdAt;
Issue = issue;
CommitUrl = commitUrl;
}

/// <summary>
Expand Down Expand Up @@ -57,6 +58,11 @@ public IssueEvent(int id, Uri url, User actor, User assignee, Label label, Event
/// </summary>
public string CommitId { get; protected set; }

/// <summary>
/// The commit URL of a commit that referenced this issue.
/// </summary>
public Uri CommitUrl { get; protected set; }

/// <summary>
/// Date the event occurred for the issue/pull request.
/// </summary>
Expand Down

0 comments on commit 0b5bb00

Please sign in to comment.