Skip to content
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
20 changes: 18 additions & 2 deletions src/Microsoft.DotNet.Git.IssueManager/src/Clients/GitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -38,7 +40,10 @@ public static async Task<int> CreateNewIssueAsync(
string repositoryUrl,
string issueTitle,
string issueDescription,
string personalAccessToken)
string personalAccessToken,
int? milestone = null,
IEnumerable<string> labels = null,
IEnumerable<string> assignees = null)
{
(string owner, string repoName) = ParseRepoUri(repositoryUrl);

Expand All @@ -48,9 +53,20 @@ public static async Task<int> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T>(this Collection<T> collection, IEnumerable<T> items)
{
foreach (T item in items)
{
collection.Add(item);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,7 +43,10 @@ public static async Task<int> CreateNewIssueAsync(
string repositoryUrl,
string issueTitle,
string issueDescription,
string gitHubPersonalAccessToken)
string gitHubPersonalAccessToken,
int? milestone = null,
IEnumerable<string> labels = null,
IEnumerable<string> assignees = null)
{
if (Uri.TryCreate(repositoryUrl, UriKind.Absolute, out Uri parsedUri))
{
Expand All @@ -53,7 +57,14 @@ public static async Task<int> 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.");
Expand Down
11 changes: 9 additions & 2 deletions src/Microsoft.DotNet.Git.IssueManager/src/IssueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,13 +54,19 @@ public async Task<string> GetCommitAuthorAsync(string repositoryUrl, string comm
public async Task<int> CreateNewIssueAsync(
string repositoryUrl,
string issueTitle,
string issueDescription)
string issueDescription,
int? milestone = null,
IEnumerable<string> labels = null,
IEnumerable<string> assignees = null)
{
return await RepositoryHelper.CreateNewIssueAsync(
repositoryUrl,
issueTitle,
issueDescription,
GitHubPersonalAccessToken);
GitHubPersonalAccessToken,
milestone,
labels,
assignees);
}
}
}