|
| 1 | +using DotnetDocsTools.GitHubCommunications; |
| 2 | +using DotnetDocsTools.GraphQLQueries; |
| 3 | + |
| 4 | +namespace Dotnet.DocsTools.GraphQLQueries |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// Retrieve the count of open issues based on labels |
| 8 | + /// </summary> |
| 9 | + /// <remarks> |
| 10 | + /// This query returns the number of matching open issues. You can specify |
| 11 | + /// either issues with certain labels, or issues without certain labels, |
| 12 | + /// or a mix. |
| 13 | + /// </remarks> |
| 14 | + public class LabeledIssueCounts |
| 15 | + { |
| 16 | + private const string AreaIssuesCount = |
| 17 | +@"query ($search_value: String!) { |
| 18 | + search(query: $search_value, type: ISSUE) { |
| 19 | + issueCount |
| 20 | + } |
| 21 | +} |
| 22 | +"; |
| 23 | + private readonly IGitHubClient client; |
| 24 | + private readonly string search_value; |
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// Constructor |
| 28 | + /// </summary> |
| 29 | + /// <param name="client">The GitHub client.</param> |
| 30 | + /// <param name="owner">The owner of the repository</param> |
| 31 | + /// <param name="repository">The repository name</param> |
| 32 | + /// <param name="labelFilter">The GraphQL string for filtering</param> |
| 33 | + public LabeledIssueCounts(IGitHubClient client, string owner, string repository, string labelFilter) |
| 34 | + { |
| 35 | + this.client = client ?? throw new ArgumentNullException(paramName: nameof(client), message: "Cannot be null"); |
| 36 | + if (string.IsNullOrWhiteSpace(owner)) |
| 37 | + throw new ArgumentException(message: "Must not be whitespace", paramName: nameof(owner)); |
| 38 | + if (string.IsNullOrWhiteSpace(repository)) |
| 39 | + throw new ArgumentException(message: "Must not be whitespace", paramName: nameof(repository)); |
| 40 | + search_value = $"repo:{owner}/{repository} is:issue is:open " + labelFilter; |
| 41 | + //Console.WriteLine(search_value); |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Perform the query for the issue count |
| 46 | + /// </summary> |
| 47 | + /// <returns>The number of open issues matching this query.</returns> |
| 48 | + public async Task<int> PerformQueryAsync() |
| 49 | + { |
| 50 | + var queryText = new GraphQLPacket |
| 51 | + { |
| 52 | + query = AreaIssuesCount |
| 53 | + }; |
| 54 | + queryText.variables["search_value"] = search_value; |
| 55 | + |
| 56 | + var results = await client.PostGraphQLRequestAsync(queryText); |
| 57 | + return results.Descendent("search", "issueCount").GetInt32(); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments