using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using Octokit.Internal; namespace Octokit { /// /// Searching Issues /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class SearchIssuesRequestExclusions { /// /// Exclusions for Issue Search /// public SearchIssuesRequestExclusions() { } /// /// Excludes issues created by a certain user. /// /// /// https://help.github.com/articles/searching-issues/#search-by-the-author-of-an-issue-or-pull-request /// public string Author { get; set; } /// /// Excludes issues that are assigned to a certain user. /// /// /// https://help.github.com/articles/searching-issues/#search-by-the-assignee-of-an-issue-or-pull-request /// public string Assignee { get; set; } /// /// Excludes issues that mention a certain user. /// /// /// https://help.github.com/articles/searching-issues/#search-by-a-mentioned-user-within-an-issue-or-pull-request /// public string Mentions { get; set; } /// /// Excludes issues that a certain user commented on. /// /// /// https://help.github.com/articles/searching-issues/#search-by-a-commenter-within-an-issue-or-pull-request /// public string Commenter { get; set; } /// /// Excludes issues that were either created by a certain user, assigned to that user, /// mention that user, or were commented on by that user. /// /// /// https://help.github.com/articles/searching-issues/#search-by-a-user-thats-involved-within-an-issue-or-pull-request /// public string Involves { get; set; } /// /// Excludes issues based on open/closed state. /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-whether-an-issue-or-pull-request-is-open /// public ItemState? State { get; set; } private IEnumerable _labels; /// /// Excludes issues based on the labels assigned. /// /// /// https://help.github.com/articles/searching-issues/#search-by-the-labels-on-an-issue /// public IEnumerable Labels { get { return _labels; } set { if (value != null && value.Any()) { _labels = value.Distinct().ToList(); } } } /// /// Excludes issues in repositories that match a certain language. /// /// /// https://help.github.com/articles/searching-issues/#search-by-the-main-language-of-a-repository /// public Language? Language { get; set; } /// /// Excludes pull requests based on the status of the commits. /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-commit-status /// public CommitState? Status { get; set; } /// /// Excludes pull requests based on the branch they came from. /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-branch-names /// public string Head { get; set; } /// /// Excludes pull requests based on the branch they are merging into. /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-branch-names /// public string Base { get; set; } [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] public IReadOnlyList MergedQualifiers() { var parameters = new List(); if (Author.IsNotBlank()) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "-author:{0}", Author)); } if (Assignee.IsNotBlank()) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "-assignee:{0}", Assignee)); } if (Mentions.IsNotBlank()) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "-mentions:{0}", Mentions)); } if (Commenter.IsNotBlank()) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "-commenter:{0}", Commenter)); } if (Involves.IsNotBlank()) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "-involves:{0}", Involves)); } if (State.HasValue) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "-state:{0}", State.Value.ToParameter())); } if (Labels != null) { parameters.AddRange(Labels.Select(label => string.Format(CultureInfo.InvariantCulture, "-label:{0}", label))); } if (Language != null) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "-language:{0}", Language.ToParameter())); } if (Status.HasValue) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "-status:{0}", Status.Value.ToParameter())); } if (Head.IsNotBlank()) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "-head:{0}", Head)); } if (Base.IsNotBlank()) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "-base:{0}", Base)); } return new ReadOnlyCollection(parameters); } internal string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "Exclusions: {0}", string.Join(" ", MergedQualifiers())); } } } }