Skip to content

Commit

Permalink
Do not create issue when unable to determine if issue already exists (#…
Browse files Browse the repository at this point in the history
…37)

* Do not create issue when unable to determine if issue already exists.

* Update logic per peer feedback.

* Added is error true.
  • Loading branch information
IEvangelist authored Apr 5, 2021
1 parent bd8a982 commit ffb441f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 16 deletions.
13 changes: 7 additions & 6 deletions src/DotNet.GitHub/GitHubGraphQLClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ... on Issue {
}";

readonly Uri _graphQLUri = new("https://api.github.com/graphql");
readonly static JsonSerializerOptions _options = new()
readonly static JsonSerializerOptions s_options = new()
{
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) },
PropertyNameCaseInsensitive = true
Expand All @@ -45,7 +45,7 @@ ... on Issue {
public GitHubGraphQLClient(HttpClient httpClient, ILogger<GitHubGraphQLClient> logger) =>
(_httpClient, _logger) = (httpClient, logger);

public async Task<ExistingIssue?> GetIssueAsync(
public async Task<(bool IsError, ExistingIssue? Issue)> GetIssueAsync(
string owner, string name, string token, string title)
{
try
Expand All @@ -68,20 +68,21 @@ public GitHubGraphQLClient(HttpClient httpClient, ILogger<GitHubGraphQLClient> l
request.Headers.Add("Accepts", MediaTypeNames.Application.Json);

using var response = await _httpClient.PostAsync(_graphQLUri, request);
response.EnsureSuccessStatusCode();

var json = await response.Content.ReadAsStringAsync();
var result = json.FromJson<GraphQLResult<ExistingIssue>>(_options);
var result = json.FromJson<GraphQLResult<ExistingIssue>>(s_options);

return result?.Data?.Search?.Nodes
return (false, result?.Data?.Search?.Nodes
?.Where(i => i.State == ItemState.Open)
?.OrderByDescending(i => i.CreatedAt.GetValueOrDefault())
?.FirstOrDefault();
?.FirstOrDefault());
}
catch (Exception ex)
{
_logger.LogWarning(ex, ex.Message);

return default;
return (true, default);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/DotNet.GitHub/GitHubLabelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Octokit;
using Octokit.Extensions;

namespace DotNet.GitHub
{
Expand Down
10 changes: 5 additions & 5 deletions src/DotNet.GitHub/ModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public static string ToMarkdownBody(
var tfms = psr.TargetFrameworkMonikerSupports;
document.AppendTable(
new MarkdownTableHeader(
new MarkdownTableHeaderCell("TFM in project"),
new MarkdownTableHeaderCell("Target version"),
new MarkdownTableHeaderCell("End of life"),
new MarkdownTableHeaderCell("Release notes"),
new MarkdownTableHeaderCell("Nearest LTS TFM version")),
new("TFM in project"),
new("Target version"),
new("End of life"),
new("Release notes"),
new("Nearest LTS TFM version")),
tfms.Where(_ => _.IsUnsupported)
.Select(tfm =>
{
Expand Down
10 changes: 7 additions & 3 deletions src/DotNet.VersionSweeper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ static async Task CreateAndEnqueueAsync(
IJobService job,
string title, Options options, Func<Options, string> getBody)
{
var existingIssue =
var (isError, existingIssue) =
await client.GetIssueAsync(
options.Owner, options.Name, options.Token, title);
if (existingIssue?.State == ItemState.Open)
if (isError)
{
job.Info($"Re-discovered but ignoring, latent non-LTS version in {existingIssue}.");
job.Debug($"Error checking for existing issue, best not to create an issue as it may be a duplicate.");
}
else if (existingIssue is { State: ItemState.Open })
{
job.Info($"Re-discovered but ignoring, latent issue: {existingIssue}.");
}
else
{
Expand Down
12 changes: 12 additions & 0 deletions test/DotNet.GitHubActionsTests/JobServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ public void WriteSaveStateCommandTest<T>(

public static IEnumerable<object[]> WriteSetOutputInput = new[]
{
new object[]
{
new Dictionary<string, string>
{
["name"] = "summary"
},
"Everything worked as expected",
new[]
{
$"::{Commands.SetOutput} name=summary::Everything worked as expected"
}
},
new object[]
{
null,
Expand Down
2 changes: 1 addition & 1 deletion test/DotNet.ReleasesTests/DotNet.ReleasesTests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
Expand Down
2 changes: 2 additions & 0 deletions test/DotNet.ReleasesTests/LabeledVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class LabeledVersionTests
new object[] { "5.0.2", new LabeledVersion(new Version(5, 0, 2)) },
new object[] { "3.1.405", new LabeledVersion(new Version(3, 1, 405)) },
new object[] { "2.2.207", new LabeledVersion(new Version(2, 2, 207)) },
new object[] { "8.1.0.314-preview1", new LabeledVersion(new Version(8, 1, 0, 314), "preview1") },
new object[] { "7.7.84.34-beta", new LabeledVersion(new Version(7, 7, 84, 34), "beta") },
new object[] { "3.5.0-sp1", new LabeledVersion(new Version(3, 5, 0), "sp1") },
new object[] { "pickles", new LabeledVersion(null) }
};
Expand Down

0 comments on commit ffb441f

Please sign in to comment.