8000 Release - 3/18/24 by EricJohnson327 · Pull Request #370 · microsoft/devhomegithubextension · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false
#Formatting - wrapping options

#leave code block on separate lines
csharp_preserve_single_line_blocks = false
csharp_preserve_single_line_blocks = true

#Style - Code block preferences

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion build/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parameters:
- release

variables:
MSIXVersion: '0.1100'
MSIXVersion: '0.1200'
solution: '**/GitHubExtension.sln'
appxPackageDir: 'AppxPackages'
testOutputArtifactDir: 'TestResults'
Expand Down
2 changes: 1 addition & 1 deletion build/scripts/CreateBuildInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Param(
)

$Major = "0"
$Minor = "11"
$Minor = "12"
$Patch = "99" # default to 99 for local builds

$versionSplit = $Version.Split(".");
Expand Down
3 changes: 0 additions & 3 deletions codeAnalysis/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
// a specific target and scoped to a namespace, type, member, etc.
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009:ClosingParenthesisMustBeSpacedCorrectly", Justification = "All current violations are due to Tuple shorthand and so valid.")]
[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1011:ClosingSquareBracketsMustBeSpacedCorrectly", Justification = "Optional arrays need to be supported. Ex []?")]

[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "We follow the C# Core Coding Style which avoids using `this` unless absolutely necessary.")]

[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:UsingDirectivesMustBePlacedWithinNamespace", Justification = "We follow the C# Core Coding Style which puts using statements outside the namespace.")]
Expand Down
40 changes: 0 additions & 40 deletions src/GitHubExtension/Client/Exceptions.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/GitHubExtension/Client/GithubClientProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class GitHubClientProvider
{
private readonly GitHubClient publicRepoClient;

private static readonly object InstanceLock = new ();
private static readonly object InstanceLock = new();

private static GitHubClientProvider? _instance;

Expand Down
16 changes: 16 additions & 0 deletions src/GitHubExtension/Client/InvalidApiException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace GitHubExtension.Client;

public class InvalidApiException : Exception
{
public InvalidApiException()
{
}

public InvalidApiException(string message)
: base(message)
{
}
}
16 changes: 16 additions & 0 deletions src/GitHubExtension/Client/InvalidGitHubUrlException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace GitHubExtension.Client;

public class InvalidGitHubUrlException : Exception
{
public InvalidGitHubUrlException()
{
}

public InvalidGitHubUrlException(string message)
: base(message)
{
}
}
16 changes: 16 additions & 0 deletions src/GitHubExtension/Client/InvalidUrlException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace GitHubExtension.Client;

public class InvalidUrlException : Exception
{
public InvalidUrlException()
{
}

public InvalidUrlException(string message)
: base(message)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@

namespace GitHubExtension;

public class RepositoryNotFoundException : ApplicationException
{
public RepositoryNotFoundException()
{
}

public RepositoryNotFoundException(string message)
: base(message)
{
}
}

public class DataStoreInaccessibleException : ApplicationException
{
public DataStoreInaccessibleException()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.Windows.DevHome.SDK;

namespace GitHubExtension;

public class DataStoreOperationParameters
{
// parameters for updating the data store.
Expand Down
104 changes: 82 additions & 22 deletions src/GitHubExtension/DataManager/GitHubDataManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using GitHubExtension.Client;
Expand All @@ -18,6 +18,7 @@ public partial class GitHubDataManager : IGitHubDataManager, IDisposable
private static readonly TimeSpan SearchRetentionTime = TimeSpan.FromDays(7);
private static readonly TimeSpan PullRequestStaleTime = TimeSpan.FromDays(1);
private static readonly TimeSpan ReviewStaleTime = TimeSpan.FromDays(7);
private static readonly TimeSpan ReleaseRetentionTime = TimeSpan.FromDays(7);

// It is possible different widgets have queries which touch the same pull requests.
// We want to keep this window large enough that we don't delete data being used by
Expand Down Expand Up @@ -179,6 +180,28 @@ public async Task UpdatePullRequestsForLoggedInDeveloperIdsAsync()
SendDeveloperUpdateEvent(this);
}

public asyn F430 c Task UpdateReleasesForRepositoryAsync(string owner, string name, RequestOptions? options = null)
{
ValidateDataStore();
var parameters = new DataStoreOperationParameters
{
Owner = owner,
RepositoryName = name,
RequestOptions = options,
OperationName = "UpdateReleasesForRepositoryAsync",
};

await UpdateDataForRepositoryAsync(
parameters,
async (parameters, devId) =>
{
var repository = await UpdateRepositoryAsync(parameters.Owner!, parameters.RepositoryName!, devId.GitHubClient);
await UpdateReleasesAsync(repository, devId.GitHubClient, parameters.RequestOptions);
});

SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), new string[] { "Releases" });
}

public IEnumerable<Repository> GetRepositories()
{
ValidateDataStore();
Expand Down Expand Up @@ -269,29 +292,30 @@ private async Task UpdateDataForRepositoryAsync(DataStoreOperationParameters par
found = true;
break;
}
catch (Exception ex)
catch (Exception ex) when (ex is Octokit.ApiException)
{
if (ex is Octokit.ForbiddenException)
{
// This can happen most commonly with SAML-enabled organizations.
Log.Logger()?.ReportDebug(Name, $"DeveloperId {devId.LoginId} was forbidden access to {parameters.Owner}/{parameters.RepositoryName}");
continue;
}

if (ex is Octokit.NotFoundException)
{
// A private repository can come back as "not found" by the GitHub API when an unauthorized account cannot even view it.
Log.Logger()?.ReportDebug(Name, $"DeveloperId {devId.LoginId} did not find {parameters.Owner}/{parameters.RepositoryName}");
continue;
}

if (ex is Octokit.RateLimitExceededException)
switch (ex)
{
Log.Logger()?.ReportError(Name, $"DeveloperId {devId.LoginId} rate limit exceeded.", ex);
throw;
case Octokit.NotFoundException:
// A private repository will come back as "not found" by the GitHub API when an unauthorized account cannot even view it.
Log.Logger()?.ReportDebug(Name, $"DeveloperId {devId.LoginId} did not find {parameters.Owner}/{parameters.RepositoryName}");
continue;

case Octokit.RateLimitExceededException:
Log.Logger()?.ReportDebug(Name, $"DeveloperId {devId.LoginId} rate limit exceeded.");
throw;

case Octokit.ForbiddenException:
// This can happen most commonly with SAML-enabled organizations.
// The user may have access but the org blocked the application.
Log.Logger()?.ReportDebug(Name, $"DeveloperId {devId.LoginId} was forbidden access to {parameters.Owner}/{parameters.RepositoryName}");
throw;

default:
// If it's some other error like abuse detection, abort and do not continue.
Log.Logger()?.ReportDebug(Name, $"Unhandled Octokit API error for {devId.LoginId} and {parameters.Owner} / {parameters.RepositoryName}");
throw;
}

throw;
}
}

Expand Down Expand Up @@ -703,6 +727,41 @@ private async Task UpdateIssuesAsync(Repository repository, Octokit.GitHubClient
Issue.DeleteLastObservedBefore(DataStore, repository.Id, DateTime.UtcNow - LastObservedDeleteSpan);
}

// Internal method to update releases. Assumes Repository has already been populated and created.
// DataStore transaction is assumed to be wrapped around this in the public method.
private async Task UpdateReleasesAsync(Repository repository, Octokit.GitHubClient? client = null, RequestOptions? options = null)
{
options ??= RequestOptions.RequestOptionsDefault();

// Limit the number of fetched releases.
options.ApiOptions.PageCount = 1;
options.ApiOptions.PageSize = 10;

client ??= await GitHubClientProvider.Instance.GetClientForLoggedInDeveloper(true);
Log.Logger()?.ReportInfo(Name, $"Updating releases for: {repository.FullName}");

var releasesResult = await client.Repository.Release.GetAll(repository.InternalId, options.ApiOptions);
if (releasesResult == null)
{
Log.Logger()?.ReportDebug($"No releases found.");
return;
}

Log.Logger()?.ReportDebug(Name, $"Results contain {releasesResult.Count} releases.");
foreach (var release in releasesResult)
{
if (release.Draft)
{
continue;
}

_ = Release.GetOrCreateByOctokitRelease(DataStore, release, repository);
}

// Remove releases from this repository that were not observed recently.
Release.DeleteLastObservedBefore(DataStore, repository.Id, DateTime.UtcNow - LastObservedDeleteSpan);
}

// Removes unused data from the datastore.
private void PruneObsoleteData()
{
Expand All @@ -714,6 +773,7 @@ private void PruneObsoleteData()
Search.DeleteBefore(DataStore, DateTime.Now - SearchRetentionTime);
SearchIssue.DeleteUnreferenced(DataStore);
Review.DeleteUnreferenced(DataStore);
Release.DeleteBefore(DataStore, DateTime.Now - ReleaseRetentionTime);
}

// Sets a last-updated in the MetaData.
Expand Down Expand Up @@ -763,7 +823,7 @@ private void ValidateDataStore()

// Making the default options a singleton to avoid repeatedly calling the storage APIs and
// creating a new GitHubDataStoreSchema when not necessary.
private static readonly Lazy<DataStoreOptions> LazyDataStoreOptions = new (DefaultOptionsInit);
private static readonly Lazy<DataStoreOptions> LazyDataStoreOptions = new(DefaultOptionsInit);

private static DataStoreOptions DefaultOptions => LazyDataStoreOptions.Value;

Expand Down
4 changes: 3 additions & 1 deletion src/GitHubExtension/DataManager/IGitHubDataManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using GitHubExtension.DataModel;
Expand All @@ -25,6 +25,8 @@ public interface IGitHubDataManager : IDisposable

Task UpdatePullRequestsForLoggedInDeveloperIdsAsync();

Task UpdateReleasesForRepositoryAsync(string owner, string name, RequestOptions? options = null);

IEnumerable<Repository> GetRepositories();

IEnumerable<User> GetDeveloperUsers();
Expand Down
16 changes: 16 additions & 0 deletions src/GitHubExtension/DataManager/RepositoryNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace GitHubExtension.DataManager;

public class RepositoryNotFoundException : ApplicationException
{
public RepositoryNotFoundException()
{
}

public RepositoryNotFoundException(string message)
: base(message)
{
}
}
Loading
0