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

Implements PullRequest.MergeableState field #1764

Merged
merged 2 commits into from
Feb 18, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Octokit.Tests.Conventions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static CustomTypeInfo GetCustomTypeInfo(this Type type)
public static bool IsModel(this Type type)
{
var typeInfo = type.GetTypeInfo();
return !typeInfo.IsInterface && !typeInfo.IsEnum && typeInfo.Assembly == typeof(AuthorizationUpdate).GetTypeInfo().Assembly;
return !typeInfo.IsGenericType && !typeInfo.IsInterface && !typeInfo.IsEnum && typeInfo.Assembly == typeof(AuthorizationUpdate).GetTypeInfo().Assembly;
}

public static bool IsClientInterface(this Type type)
Expand Down
3 changes: 2 additions & 1 deletion Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ public async Task CannotBeMergedDueMismatchConflict()
Assert.True(ex.Message.StartsWith("Head branch was modified"));
}

[IntegrationTest(Skip = "this PR is actually mergeable - rewrite the test")]
[IntegrationTest]
public async Task CannotBeMergedDueNotInMergeableState()
{
await CreateTheWorld();
Expand All @@ -749,6 +749,7 @@ public async Task CannotBeMergedDueNotInMergeableState()
var updatedPullRequest = await _fixture.Get(Helper.UserName, _context.RepositoryName, pullRequest.Number);

Assert.False(updatedPullRequest.Mergeable);
Assert.Equal(updatedPullRequest.MergeableState, MergeableState.Dirty);

var merge = new MergePullRequest { Sha = pullRequest.Head.Sha };
var ex = await Assert.ThrowsAsync<PullRequestNotMergeableException>(() => _fixture.Merge(Helper.UserName, _context.RepositoryName, pullRequest.Number, merge));
Expand Down
57 changes: 56 additions & 1 deletion Octokit/Models/Response/PullRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using Octokit.Internal;

namespace Octokit
{
Expand All @@ -15,7 +16,7 @@ public PullRequest(int number)
Number = number;
}

public PullRequest(long id, string url, string htmlUrl, string diffUrl, string patchUrl, string issueUrl, string statusesUrl, int number, ItemState state, string title, string body, DateTimeOffset createdAt, DateTimeOffset updatedAt, DateTimeOffset? closedAt, DateTimeOffset? mergedAt, GitReference head, GitReference @base, User user, User assignee, IReadOnlyList<User> assignees, bool? mergeable, User mergedBy, string mergeCommitSha, int comments, int commits, int additions, int deletions, int changedFiles, Milestone milestone, bool locked, IReadOnlyList<User> requestedReviewers)
public PullRequest(long id, string url, string htmlUrl, string diffUrl, string patchUrl, string issueUrl, string statusesUrl, int number, ItemState state, string title, string body, DateTimeOffset createdAt, DateTimeOffset updatedAt, DateTimeOffset? closedAt, DateTimeOffset? mergedAt, GitReference head, GitReference @base, User user, User assignee, IReadOnlyList<User> assignees, bool? mergeable, MergeableState? mergeableState, User mergedBy, string mergeCommitSha, int comments, int commits, int additions, int deletions, int changedFiles, Milestone milestone, bool locked, IReadOnlyList<User> requestedReviewers)
{
Id = id;
Url = url;
Expand All @@ -38,6 +39,7 @@ public PullRequest(long id, string url, string htmlUrl, string diffUrl, string p
Assignee = assignee;
Assignees = assignees;
Mergeable = mergeable;
MergeableState = mergeableState;
MergedBy = mergedBy;
MergeCommitSha = mergeCommitSha;
Comments = comments;
Expand Down Expand Up @@ -168,6 +170,11 @@ public bool Merged
/// </summary>
public bool? Mergeable { get; protected set; }

/// <summary>
/// Provides extra information regarding the mergeability of the pull request.
/// </summary>
public StringEnum<MergeableState>? MergeableState { get; protected set; }

/// <summary>
/// The user who merged the pull request.
/// </summary>
Expand Down Expand Up @@ -222,4 +229,52 @@ internal string DebuggerDisplay
get { return string.Format(CultureInfo.InvariantCulture, "Number: {0} State: {1}", Number, State); }
}
}

/// <summary>
/// Provides extra information regarding the mergeability of a pull request
/// </summary>
public enum MergeableState
{
/// <summary>
/// Merge conflict. Merging is blocked.
/// </summary>
[Parameter(Value = "dirty")]
Dirty,

/// <summary>
/// Mergeability was not checked yet. Merging is blocked.
/// </summary>
[Parameter(Value = "unknown")]
Unknown,

/// <summary>
/// Failing/missing required status check. Merging is blocked.
/// </summary>
[Parameter(Value = "blocked")]
Blocked,

/// <summary>
/// Head branch is behind the base branch. Only if required status checks is enabled but loose policy is not. Merging is blocked.
/// </summary>
[Parameter(Value = "behind")]
Behind,

/// <summary>
/// Failing/pending commit status that is not part of the required status checks. Merging is still allowed.
/// </summary>
[Parameter(Value = "unstable")]
Unstable,

/// <summary>
/// GitHub Enterprise only, if a repo has custom pre-receive hooks. Merging is allowed.
/// </summary>
[Parameter(Value = "has_hooks")]
HasHooks,

/// <summary>
/// No conflicts, everything good. Merging is allowed.
/// </summary>
[Parameter(Value = "clean")]
Clean
}
}