Skip to content

Commit 536e5c3

Browse files
authored
feat: adds active lock reason to issue (#2525)
1 parent a7d5e33 commit 536e5c3

8 files changed

Lines changed: 72 additions & 15 deletions

File tree

Octokit.Reactive/Clients/IObservableIssuesClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,17 @@ public interface IObservableIssuesClient
324324
/// <param name="owner">The owner of the repository</param>
325325
/// <param name="name">The name of the repository</param>
326326
/// <param name="number">The issue number</param>
327-
IObservable<Unit> Lock(string owner, string name, int number);
327+
/// <param name="lockReason">The reason for locking the issue</param>
328+
IObservable<Unit> Lock(string owner, string name, int number, LockReason? lockReason = null);
328329

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

337339
/// <summary>
338340
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.

Octokit.Reactive/Clients/ObservableIssuesClient.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,13 @@ public IObservable<Issue> Update(long repositoryId, int number, IssueUpdate issu
480480
/// <param name="owner">The owner of the repository</param>
481481
/// <param name="name">The name of the repository</param>
482482
/// <param name="number">The issue number</param>
483-
public IObservable<Unit> Lock(string owner, string name, int number)
483+
/// <param name="lockReason">The reason for locking the issue</param>
484+
public IObservable<Unit> Lock(string owner, string name, int number, LockReason? lockReason = null)
484485
{
485486
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
486487
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
487488

488-
return _client.Lock(owner, name, number).ToObservable();
489+
return _client.Lock(owner, name, number, lockReason).ToObservable();
489490
}
490491

491492
/// <summary>
@@ -494,9 +495,10 @@ public IObservable<Unit> Lock(string owner, string name, int number)
494495
/// <remarks>https://developer.github.com/v3/issues/#lock-an-issue</remarks>
495496
/// <param name="repositoryId">The Id of the repository</param>
496497
/// <param name="number">The issue number</param>
497-
public IObservable<Unit> Lock(long repositoryId, int number)
498+
/// <param name="lockReason">The reason for locking the issue</param>
499+
public IObservable<Unit> Lock(long repositoryId, int number, LockReason? lockReason = null)
498500
{
499-
return _client.Lock(repositoryId, number).ToObservable();
501+
return _client.Lock(repositoryId, number, lockReason).ToObservable();
500502
}
501503

502504
/// <summary>

Octokit.Tests.Integration/Clients/IssuesClientTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,20 @@ public async Task CanLockAndUnlockIssue()
252252
Assert.False(retrieved.Locked);
253253
}
254254

255+
[IntegrationTest]
256+
public async Task CanAccessActiveLockReason()
257+
{
258+
var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" };
259+
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
260+
Assert.False(issue.Locked);
261+
262+
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number, LockReason.OffTopic);
263+
var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
264+
Assert.NotNull(retrieved);
265+
Assert.True(retrieved.Locked);
266+
Assert.Equal(retrieved.ActiveLockReason, LockReason.OffTopic);
267+
}
268+
255269
[IntegrationTest]
256270
public async Task CanLockAndUnlockIssueWithRepositoryId()
257271
{

Octokit.Tests/Models/IssueTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ public void CanBeDeserialized()
120120
""events_url"": ""https://api.github.com/users/octocat/events{/privacy}"",
121121
""received_events_url"": ""https://api.github.com/users/octocat/received_events"",
122122
""type"": ""User"",
123-
""site_admin"": false
124-
}
123+
""site_admin"": false,
124+
},
125+
""active_lock_reason"": null
125126
}";
126127
var serializer = new SimpleJsonSerializer();
127128

@@ -130,6 +131,7 @@ public void CanBeDeserialized()
130131
Assert.Equal(1347, issue.Number);
131132
Assert.Equal("octocat", issue.User.Login);
132133
Assert.Equal("bug", issue.Labels.First().Name);
134+
Assert.Null(issue.ActiveLockReason);
133135
}
134136

135137
public class TheToUpdateMethod

Octokit/Clients/IIssuesClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,17 @@ public interface IIssuesClient
321321
/// <param name="owner">The owner of the repository</param>
322322
/// <param name="name">The name of the repository</param>
323323
/// <param name="number">The issue number</param>
324-
Task Lock(string owner, string name, int number);
324+
/// <param name="lockReason">The reason for locking the issue</param>
325+
Task Lock(string owner, string name, int number, LockReason? lockReason = null);
325326

326327
/// <summary>
327328
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
328329
/// </summary>
329330
/// <remarks>https://developer.github.com/v3/issues/#lock-an-issue</remarks>
330331
/// <param name="repositoryId">The Id of the repository</param>
331332
/// <param name="number">The issue number</param>
332-
Task Lock(long repositoryId, int number);
333+
/// <param name="lockReason">The reason for locking the issue</param>
334+
Task Lock(long repositoryId, int number, LockReason? lockReason = null);
333335

334336
/// <summary>
335337
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.

Octokit/Clients/IssuesClient.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,14 @@ public Task<Issue> Update(long repositoryId, int number, IssueUpdate issueUpdate
500500
/// <param name="owner">The owner of the repository</param>
501501
/// <param name="name">The name of the repository</param>
502502
/// <param name="number">The issue number</param>
503+
/// <param name="lockReason">The reason for locking the issue</param>
503504
[ManualRoute("PUT", "/repos/{owner}/{repo}/issues/{issue_number}/lock")]
504-
public Task Lock(string owner, string name, int number)
505+
public Task Lock(string owner, string name, int number, LockReason? lockReason = null)
505506
{
506507
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
507508
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
508509

509-
return ApiConnection.Put<Issue>(ApiUrls.IssueLock(owner, name, number), new object());
510+
return ApiConnection.Put<Issue>(ApiUrls.IssueLock(owner, name, number), lockReason.HasValue ? new { LockReason = lockReason } : new object());
510511
}
511512

512513
/// <summary>
@@ -515,10 +516,11 @@ public Task Lock(string owner, string name, int number)
515516
/// <remarks>https://developer.github.com/v3/issues/#lock-an-issue</remarks>
516517
/// <param name="repositoryId">The Id of the repository</param>
517518
/// <param name="number">The issue number</param>
519+
/// <param name="lockReason">The reason for locking the issue</param>
518520
[ManualRoute("PUT", "/repositories/{id}/issues/{number}/lock")]
519-
public Task Lock(long repositoryId, int number)
521+
public Task Lock(long repositoryId, int number, LockReason? lockReason = null)
520522
{
521-
return ApiConnection.Put<Issue>(ApiUrls.IssueLock(repositoryId, number), new object());
523+
return ApiConnection.Put<Issue>(ApiUrls.IssueLock(repositoryId, number), lockReason.HasValue ? new { LockReaons = lockReason } : new object());
522524
}
523525

524526
/// <summary>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Octokit.Internal;
2+
3+
namespace Octokit
4+
{
5+
/// <summary>
6+
/// The possible reasons that an issue or pull request was locked.
7+
/// </summary>
8+
public enum LockReason
9+
{
10+
// The issue or pull request was locked because the conversation was off-topic.
11+
[Parameter(Value = "off-topic")]
12+
OffTopic,
13+
14+
// The issue or pull request was locked because the conversation was resolved.
15+
[Parameter(Value = "resolved")]
16+
Resolved,
17+
18+
// The issue or pull request was locked because the conversation was spam.
19+
[Parameter(Value = "spam")]
20+
Spam,
21+
22+
// The issue or pull request was locked because the conversation was too heated.
23+
[Parameter(Value = "too heated")]
24+
TooHeated
25+
}
26+
}

Octokit/Models/Response/Issue.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
using System.Globalization;
55
using System.Linq;
66

7+
78
namespace Octokit
89
{
910
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1011
public class Issue
1112
{
1213
public Issue() { }
1314

14-
public Issue(string url, string htmlUrl, string commentsUrl, string eventsUrl, int number, ItemState state, string title, string body, User closedBy, User user, IReadOnlyList<Label> labels, User assignee, IReadOnlyList<User> assignees, Milestone milestone, int comments, PullRequest pullRequest, DateTimeOffset? closedAt, DateTimeOffset createdAt, DateTimeOffset? updatedAt, int id, string nodeId, bool locked, Repository repository, ReactionSummary reactions)
15+
public Issue(string url, string htmlUrl, string commentsUrl, string eventsUrl, int number, ItemState state, string title, string body, User closedBy, User user, IReadOnlyList<Label> labels, User assignee, IReadOnlyList<User> assignees, Milestone milestone, int comments, PullRequest pullRequest, DateTimeOffset? closedAt, DateTimeOffset createdAt, DateTimeOffset? updatedAt, int id, string nodeId, bool locked, Repository repository, ReactionSummary reactions, LockReason? activeLockReason)
1516
{
1617
Id = id;
1718
NodeId = nodeId;
@@ -37,6 +38,7 @@ public Issue(string url, string htmlUrl, string commentsUrl, string eventsUrl, i
3738
Locked = locked;
3839
Repository = repository;
3940
Reactions = reactions;
41+
ActiveLockReason = activeLockReason;
4042
}
4143

4244
/// <summary>
@@ -156,6 +158,11 @@ public Issue(string url, string htmlUrl, string commentsUrl, string eventsUrl, i
156158
/// </summary>
157159
public ReactionSummary Reactions { get; protected set; }
158160

161+
/// <summary>
162+
/// Reason that the conversation was locked.
163+
/// </summary>
164+
public StringEnum<LockReason>? ActiveLockReason { get; protected set; }
165+
159166
internal string DebuggerDisplay
160167
{
161168
get

0 commit comments

Comments
 (0)