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..d487396d3a8 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,14 @@ 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); } } }