Skip to content

Commit

Permalink
add active lock reason to PR (#2543)
Browse files Browse the repository at this point in the history
* add active lock reason to PR

* update docs

* refactor: extract lock and unlock from IIssuesClient
create ILockUnlockClient so both IIssuesClient and IPullRequestClient can
access lock and unlock methods.

* refactor LockUnlock for reactive clients

* Update doc to include lock unlock sample code

* Use Assert.Null to check null value in test

Co-authored-by: notauserx <[email protected]>
  • Loading branch information
notauserx and notauserx authored Aug 19, 2022
1 parent b866d66 commit 595e35d
Show file tree
Hide file tree
Showing 20 changed files with 405 additions and 255 deletions.
41 changes: 5 additions & 36 deletions Octokit.Reactive/Clients/IObservableIssuesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public interface IObservableIssuesClient
/// </summary>
IObservableIssueTimelineClient Timeline { get; }

/// <summary>
/// Client for locking/unlocking conversation on an issue
/// </summary>
IObservableLockUnlockClient LockUnlock { get; }

/// <summary>
/// Gets a single Issue by number.
/// </summary>
Expand Down Expand Up @@ -316,41 +321,5 @@ public interface IObservableIssuesClient
/// <param name="issueUpdate">An <see cref="IssueUpdate"/> instance describing the changes to make to the issue
/// </param>
IObservable<Issue> Update(long repositoryId, int number, IssueUpdate issueUpdate);

/// <summary>
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#lock-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>
/// <param name="lockReason">The reason for locking the issue</param>
IObservable<Unit> Lock(string owner, string name, int number, LockReason? lockReason = null);

/// <summary>
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#lock-an-issue</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The issue number</param>
/// <param name="lockReason">The reason for locking the issue</param>
IObservable<Unit> Lock(long repositoryId, int number, LockReason? lockReason = null);

/// <summary>
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#unlock-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>
IObservable<Unit> Unlock(string owner, string name, int number);

/// <summary>
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#unlock-an-issue</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The issue number</param>
IObservable<Unit> Unlock(long repositoryId, int number);
}
}
47 changes: 47 additions & 0 deletions Octokit.Reactive/Clients/IObservableLockUnlockClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Reactive;

namespace Octokit.Reactive
{
/// <summary>
/// Client to manage locking/unlocking a conversation for an Issue or a Pull request
/// </summary>
public interface IObservableLockUnlockClient
{
/// <summary>
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#lock-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>
/// <param name="lockReason">The reason for locking the issue</param>
IObservable<Unit> Lock(string owner, string name, int number, LockReason? lockReason = null);

/// <summary>
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#lock-an-issue</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The issue number</param>
/// <param name="lockReason">The reason for locking the issue</param>
IObservable<Unit> Lock(long repositoryId, int number, LockReason? lockReason = null);

/// <summary>
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#unlock-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>
IObservable<Unit> Unlock(string owner, string name, int number);

/// <summary>
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#unlock-an-issue</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The issue number</param>
IObservable<Unit> Unlock(long repositoryId, int number);
}
}
5 changes: 5 additions & 0 deletions Octokit.Reactive/Clients/IObservablePullRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public interface IObservablePullRequestsClient
/// </summary>
IObservablePullRequestReviewRequestsClient ReviewRequest { get; }

/// <summary>
/// Client for locking/unlocking a conversation on a pull request
/// </summary>
IObservableLockUnlockClient LockUnlock { get; }

/// <summary>
/// Gets a single Pull Request by number.
/// </summary>
Expand Down
60 changes: 7 additions & 53 deletions Octokit.Reactive/Clients/ObservableIssuesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public class ObservableIssuesClient : IObservableIssuesClient
/// </summary>
public IObservableIssueTimelineClient Timeline { get; private set; }

/// <summary>
/// Client for locking/unlocking conversation on an issue
/// </summary>
public IObservableLockUnlockClient LockUnlock { get; protected set; }

public ObservableIssuesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
Expand All @@ -60,6 +65,7 @@ public ObservableIssuesClient(IGitHubClient client)
Milestone = new ObservableMilestonesClient(client);
Comment = new ObservableIssueCommentsClient(client);
Timeline = new ObservableIssueTimelineClient(client);
LockUnlock = new ObservableLockUnlockClient(client);
}

/// <summary>
Expand Down Expand Up @@ -473,58 +479,6 @@ public IObservable<Issue> Update(long repositoryId, int number, IssueUpdate issu
return _client.Update(repositoryId, number, issueUpdate).ToObservable();
}

/// <summary>
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#lock-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>
/// <param name="lockReason">The reason for locking the issue</param>
public IObservable<Unit> Lock(string owner, string name, int number, LockReason? lockReason = null)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));

return _client.Lock(owner, name, number, lockReason).ToObservable();
}

/// <summary>
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#lock-an-issue</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The issue number</param>
/// <param name="lockReason">The reason for locking the issue</param>
public IObservable<Unit> Lock(long repositoryId, int number, LockReason? lockReason = null)
{
return _client.Lock(repositoryId, number, lockReason).ToObservable();
}

/// <summary>
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#unlock-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>
public IObservable<Unit> Unlock(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));

return _client.Unlock(owner, name, number).ToObservable();
}

/// <summary>
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#unlock-an-issue</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The issue number</param>
public IObservable<Unit> Unlock(long repositoryId, int number)
{
return _client.Unlock(repositoryId, number).ToObservable();
}

}
}
75 changes: 75 additions & 0 deletions Octokit.Reactive/Clients/ObservableLockUnlockClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;

namespace Octokit.Reactive
{
/// <summary>
/// Client to manage locking/unlocking a conversation for an Issue or a Pull request
/// </summary>
public class ObservableLockUnlockClient : IObservableLockUnlockClient
{
readonly ILockUnlockClient _client;

public ObservableLockUnlockClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));

_client = client.Issue.LockUnlock;
}

/// <summary>
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#lock-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>
/// <param name="lockReason">The reason for locking the issue</param>
public IObservable<Unit> Lock(string owner, string name, int number, LockReason? lockReason = null)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));

return _client.Lock(owner, name, number, lockReason).ToObservable();
}

/// <summary>
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#lock-an-issue</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The issue number</param>
/// <param name="lockReason">The reason for locking the issue</param>
public IObservable<Unit> Lock(long repositoryId, int number, LockReason? lockReason = null)
{
return _client.Lock(repositoryId, number, lockReason).ToObservable();
}

/// <summary>
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#unlock-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>
public IObservable<Unit> Unlock(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));

return _client.Unlock(owner, name, number).ToObservable();
}

/// <summary>
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.
/// </summary>
/// <remarks>https://developer.github.com/v3/issues/#unlock-an-issue</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The issue number</param>
public IObservable<Unit> Unlock(long repositoryId, int number)
{
return _client.Unlock(repositoryId, number).ToObservable();
}
}
}
6 changes: 6 additions & 0 deletions Octokit.Reactive/Clients/ObservablePullRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class ObservablePullRequestsClient : IObservablePullRequestsClient
/// </summary>
public IObservablePullRequestReviewRequestsClient ReviewRequest { get; private set; }

/// <summary>
/// Client for locking/unlocking a conversation on a pull request
/// </summary>
public IObservableLockUnlockClient LockUnlock { get; private set; }

public ObservablePullRequestsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
Expand All @@ -39,6 +44,7 @@ public ObservablePullRequestsClient(IGitHubClient client)
Review = new ObservablePullRequestReviewsClient(client);
ReviewComment = new ObservablePullRequestReviewCommentsClient(client);
ReviewRequest = new ObservablePullRequestReviewRequestsClient(client);
LockUnlock = new ObservableLockUnlockClient(client);
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions Octokit.Tests.Integration/Clients/IssuesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ public async Task CanLockAndUnlockIssue()
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
Assert.False(issue.Locked);

await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
await _issuesClient.LockUnlock.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
Assert.NotNull(retrieved);
Assert.True(retrieved.Locked);

await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
await _issuesClient.LockUnlock.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
Assert.NotNull(retrieved);
Assert.False(retrieved.Locked);
Expand All @@ -259,7 +259,7 @@ public async Task CanAccessActiveLockReason()
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
Assert.False(issue.Locked);

await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number, LockReason.OffTopic);
await _issuesClient.LockUnlock.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number, LockReason.OffTopic);
var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
Assert.NotNull(retrieved);
Assert.True(retrieved.Locked);
Expand All @@ -273,12 +273,12 @@ public async Task CanLockAndUnlockIssueWithRepositoryId()
var issue = await _issuesClient.Create(_context.Repository.Id, newIssue);
Assert.False(issue.Locked);

await _issuesClient.Lock(_context.Repository.Id, issue.Number);
await _issuesClient.LockUnlock.Lock(_context.Repository.Id, issue.Number);
var retrieved = await _issuesClient.Get(_context.Repository.Id, issue.Number);
Assert.NotNull(retrieved);
Assert.True(retrieved.Locked);

await _issuesClient.Unlock(_context.Repository.Id, issue.Number);
await _issuesClient.LockUnlock.Unlock(_context.Repository.Id, issue.Number);
retrieved = await _issuesClient.Get(_context.Repository.Id, issue.Number);
Assert.NotNull(retrieved);
Assert.False(retrieved.Locked);
Expand Down
Loading

0 comments on commit 595e35d

Please sign in to comment.