From 11b2e025412606d5c6ce1e3af99d431070583231 Mon Sep 17 00:00:00 2001 From: Matt Thalman Date: Fri, 21 May 2021 12:56:30 -0500 Subject: [PATCH 1/2] Allow for additional GitHub issue state to be set --- .../src/Clients/GitHubClient.cs | 20 +++++++++++++++++-- .../src/Helpers/CollectionExtensions.cs | 19 ++++++++++++++++++ .../src/Helpers/RepositoryHelper.cs | 9 +++++++-- .../src/IssueManager.cs | 11 ++++++++-- 4 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 src/Microsoft.DotNet.Git.IssueManager/src/Helpers/CollectionExtensions.cs diff --git a/src/Microsoft.DotNet.Git.IssueManager/src/Clients/GitHubClient.cs b/src/Microsoft.DotNet.Git.IssueManager/src/Clients/GitHubClient.cs index a51e587d759..f9b8f747591 100644 --- a/src/Microsoft.DotNet.Git.IssueManager/src/Clients/GitHubClient.cs +++ b/src/Microsoft.DotNet.Git.IssueManager/src/Clients/GitHubClient.cs @@ -3,9 +3,11 @@ using Octokit; using System; +using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Microsoft.DotNet.Git.IssueManager.Helpers; namespace Microsoft.DotNet.Git.IssueManager.Clients { @@ -38,7 +40,10 @@ public static async Task CreateNewIssueAsync( string repositoryUrl, string issueTitle, string issueDescription, - string personalAccessToken) + string personalAccessToken, + int? milestone = null, + IEnumerable labels = null, + IEnumerable assignees = null) { (string owner, string repoName) = ParseRepoUri(repositoryUrl); @@ -48,9 +53,20 @@ public static async Task CreateNewIssueAsync( NewIssue issueToBeCreated = new NewIssue(issueTitle) { - Body = issueDescription + Body = issueDescription, + Milestone = milestone }; + if (labels is not null) + { + issueToBeCreated.Labels.AddRange(labels); + } + + if (assignees is not null) + { + issueToBeCreated.Assignees.AddRange(assignees); + } + Issue createdIssue = await client.Issue.Create(owner, repoName, issueToBeCreated); return createdIssue.Number; diff --git a/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/CollectionExtensions.cs b/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/CollectionExtensions.cs new file mode 100644 index 00000000000..dfe6aa27d6e --- /dev/null +++ b/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/CollectionExtensions.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace Microsoft.DotNet.Git.IssueManager.Helpers +{ + internal static class CollectionExtensions + { + public static void AddRange(this Collection collection, IEnumerable items) + { + foreach (T item in items) + { + collection.Add(item); + } + } + } +} diff --git a/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/RepositoryHelper.cs b/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/RepositoryHelper.cs index 9d9741efd83..c2e31e0777b 100644 --- a/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/RepositoryHelper.cs +++ b/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/RepositoryHelper.cs @@ -3,6 +3,7 @@ using Microsoft.DotNet.Git.IssueManager.Clients; using System; +using System.Collections.Generic; using System.Threading.Tasks; namespace Microsoft.DotNet.Git.IssueManager.Helpers @@ -42,7 +43,10 @@ public static async Task CreateNewIssueAsync( string repositoryUrl, string issueTitle, string issueDescription, - string gitHubPersonalAccessToken) + string gitHubPersonalAccessToken, + int? milestone = null, + IEnumerable labels = null, + IEnumerable assignees = null) { if (Uri.TryCreate(repositoryUrl, UriKind.Absolute, out Uri parsedUri)) { @@ -53,7 +57,8 @@ public static async Task CreateNewIssueAsync( throw new ArgumentException("A GitHub personal access token is needed for this operation."); } - return await GitHubClient.CreateNewIssueAsync(repositoryUrl, issueTitle, issueDescription, gitHubPersonalAccessToken); + return await GitHubClient.CreateNewIssueAsync( + repositoryUrl, issueTitle, issueDescription, gitHubPersonalAccessToken, milestone, labels, assignees); } throw new NotImplementedException("Creating issues is not currently supported for an Azure DevOps repo."); diff --git a/src/Microsoft.DotNet.Git.IssueManager/src/IssueManager.cs b/src/Microsoft.DotNet.Git.IssueManager/src/IssueManager.cs index 510eab1797e..3eeac623e76 100644 --- a/src/Microsoft.DotNet.Git.IssueManager/src/IssueManager.cs +++ b/src/Microsoft.DotNet.Git.IssueManager/src/IssueManager.cs @@ -3,6 +3,7 @@ using Microsoft.DotNet.Git.IssueManager.Helpers; using System; +using System.Collections.Generic; using System.Threading.Tasks; namespace Microsoft.DotNet.Git.IssueManager @@ -53,13 +54,19 @@ public async Task GetCommitAuthorAsync(string repositoryUrl, string comm public async Task CreateNewIssueAsync( string repositoryUrl, string issueTitle, - string issueDescription) + string issueDescription, + int? milestone = null, + IEnumerable labels = null, + IEnumerable assignees = null) { return await RepositoryHelper.CreateNewIssueAsync( repositoryUrl, issueTitle, issueDescription, - GitHubPersonalAccessToken); + GitHubPersonalAccessToken, + milestone, + labels, + assignees); } } } From b6ec63cb1c676396b099fb1130125cfb5048c0a5 Mon Sep 17 00:00:00 2001 From: Matt Thalman Date: Mon, 24 May 2021 15:46:11 -0500 Subject: [PATCH 2/2] Add line breaks for args --- .../src/Helpers/RepositoryHelper.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/RepositoryHelper.cs b/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/RepositoryHelper.cs index c2e31e0777b..d487396d3a8 100644 --- a/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/RepositoryHelper.cs +++ b/src/Microsoft.DotNet.Git.IssueManager/src/Helpers/RepositoryHelper.cs @@ -58,7 +58,13 @@ public static async Task CreateNewIssueAsync( } return await GitHubClient.CreateNewIssueAsync( - repositoryUrl, issueTitle, issueDescription, gitHubPersonalAccessToken, milestone, labels, assignees); + repositoryUrl, + issueTitle, + issueDescription, + gitHubPersonalAccessToken, + milestone, + labels, + assignees); } throw new NotImplementedException("Creating issues is not currently supported for an Azure DevOps repo.");