From 00b56ad3ce8bfb485c7999a2c133217e7b791341 Mon Sep 17 00:00:00 2001 From: Felipe G Date: Wed, 14 Aug 2024 10:57:34 -0700 Subject: [PATCH 1/7] Simplifying Issues and Pull Requests Widgets customization (#424) * Removing check url and adding first version of dropdown * Fixing save bug and adding loop to get repos from RepositoryProvider * Adding changes on issues template * Removing known repos code * Cleaning up code --------- Co-authored-by: Felipe da Conceicao Guimaraes --- .../Widgets/GitHubRepositoryWidget.cs | 110 +++++++----------- .../GitHubIssuesConfigurationTemplate.json | 11 +- .../GitHubPullsConfigurationTemplate.json | 11 +- 3 files changed, 48 insertions(+), 84 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs index 067b36a..582ac2d 100644 --- a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs @@ -5,7 +5,6 @@ using System.Text.Json.Nodes; using GitHubExtension.Client; using GitHubExtension.DataManager; -using GitHubExtension.Helpers; using GitHubExtension.Widgets.Enums; using Microsoft.Windows.Widgets.Providers; @@ -15,6 +14,8 @@ public abstract class GitHubRepositoryWidget : GitHubWidget { protected string RepositoryUrl { get; set; } = string.Empty; + private string? _message; + public GitHubRepositoryWidget() : base() { @@ -66,14 +67,14 @@ public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) switch (verb) { - case WidgetAction.CheckUrl: - HandleCheckUrl(actionInvokedArgs); - break; - case WidgetAction.Save: - UpdateTitle(JsonNode.Parse(actionInvokedArgs.Data)); - base.OnActionInvoked(actionInvokedArgs); - CorrectUrl(); + if (HandleCheckUrl(actionInvokedArgs)) + { + UpdateTitle(JsonNode.Parse(actionInvokedArgs.Data)); + base.OnActionInvoked(actionInvokedArgs); + CorrectUrl(); + } + break; default: @@ -144,7 +145,14 @@ private void UpdateTitle(JsonNode? dataObj) GetTitleFromDataObject(dataObj); if (string.IsNullOrEmpty(WidgetTitle)) { - WidgetTitle = GetRepositoryFromUrl(RepositoryUrl).FullName; + try + { + WidgetTitle = GetRepositoryFromUrl(RepositoryUrl).FullName; + } + catch + { + WidgetTitle = string.Empty; + } } } @@ -207,7 +215,7 @@ public override void OnCustomizationRequested(WidgetCustomizationRequestedArgs c base.OnCustomizationRequested(customizationRequestedArgs); } - private void HandleCheckUrl(WidgetActionInvokedArgs args) + private bool HandleCheckUrl(WidgetActionInvokedArgs args) { // Set loading page while we fetch data from GitHub. Page = WidgetPageState.Loading; @@ -223,7 +231,19 @@ private void HandleCheckUrl(WidgetActionInvokedArgs args) RepositoryUrl = dataObject["url"]?.GetValue() ?? string.Empty; UpdateTitle(dataObject); - ConfigurationData = data; + var isGoodToSave = true; + + try + { + GetRepositoryFromUrl(RepositoryUrl); + ConfigurationData = data; + _message = null; + } + catch (Exception ex) + { + _message = ex.Message; + isGoodToSave = false; + } var updateRequestOptions = new WidgetUpdateRequestOptions(Id) { @@ -233,71 +253,29 @@ private void HandleCheckUrl(WidgetActionInvokedArgs args) }; WidgetManager.GetDefault().UpdateWidget(updateRequestOptions); + + // Already shown error message while updating above, + // can reset it to null here. + _message = null; + return isGoodToSave; } + + UpdateWidget(); + + return false; } public string GetConfiguration(string dataUrl) { var configurationData = new JsonObject { - { "submitIcon", IconLoader.GetIconAsBase64("arrow.png") }, { "widgetTitle", WidgetTitle }, + { "url", dataUrl }, + { "savedRepositoryUrl", SavedConfigurationData }, + { "errorMessage", _message }, }; - if (dataUrl == string.Empty) - { - configurationData.Add("hasConfiguration", false); - var repositoryData = new JsonObject - { - { "url", string.Empty }, - }; - - configurationData.Add("configuration", repositoryData); - configurationData.Add("savedRepositoryUrl", SavedConfigurationData); - configurationData.Add("saveEnabled", false); - - return configurationData.ToString(); - } - else - { - try - { - var repository = GetRepositoryFromUrl(dataUrl); - var repositoryData = new JsonObject - { - { "name", repository.FullName }, - { "label", repository.Name }, - { "owner", repository.Owner.Login }, - { "milestone", string.Empty }, - { "project", repository.Description }, - { "url", RepositoryUrl }, - { "query", GetUnescapedIssueQuery() }, - }; - - configurationData.Add("hasConfiguration", true); - configurationData.Add("configuration", repositoryData); - configurationData.Add("savedRepositoryUrl", SavedConfigurationData); - configurationData.Add("saveEnabled", true); - } - catch (Exception ex) - { - Log.Error(ex, $"Failed getting configuration information for input url: {dataUrl}"); - configurationData.Add("hasConfiguration", false); - - var repositoryData = new JsonObject - { - { "url", RepositoryUrl }, - }; - - configurationData.Add("errorMessage", ex.Message); - configurationData.Add("configuration", repositoryData); - configurationData.Add("saveEnabled", false); - - return configurationData.ToString(); - } - - return configurationData.ToJsonString(); - } + return configurationData.ToJsonString(); } public override string GetData(WidgetPageState page) diff --git a/src/GitHubExtension/Widgets/Templates/GitHubIssuesConfigurationTemplate.json b/src/GitHubExtension/Widgets/Templates/GitHubIssuesConfigurationTemplate.json index 0333c9a..3359318 100644 --- a/src/GitHubExtension/Widgets/Templates/GitHubIssuesConfigurationTemplate.json +++ b/src/GitHubExtension/Widgets/Templates/GitHubIssuesConfigurationTemplate.json @@ -7,16 +7,10 @@ "type": "Input.Text", "id": "url", "label": "%Widget_Template_Label/Url%", - "inlineAction": { - "type": "Action.Execute", - "tooltip": "%Widget_Template_Tooltip/Submit%", - "verb": "CheckUrl", - "iconUrl": "data:image/png;base64,${submitIcon}" - }, "spacing": "Medium", "style": "Url", "placeholder": "%Widget_Template_Input/UrlPlaceholder%", - "value": "${$root.configuration.url}" + "value": "${url}" }, { "type": "Input.Text", @@ -115,8 +109,7 @@ "type": "Action.Execute", "title": "%Widget_Template_Button/Save%", "verb": "Save", - "tooltip": "%Widget_Template_Tooltip/Save%", - "isEnabled": "${$root.saveEnabled}" + "tooltip": "%Widget_Template_Tooltip/Save%" }, { "type": "Action.Execute", diff --git a/src/GitHubExtension/Widgets/Templates/GitHubPullsConfigurationTemplate.json b/src/GitHubExtension/Widgets/Templates/GitHubPullsConfigurationTemplate.json index 881d356..15cbd87 100644 --- a/src/GitHubExtension/Widgets/Templates/GitHubPullsConfigurationTemplate.json +++ b/src/GitHubExtension/Widgets/Templates/GitHubPullsConfigurationTemplate.json @@ -7,16 +7,10 @@ "type": "Input.Text", "id": "url", "label": "%Widget_Template_Label/Url%", - "inlineAction": { - "type": "Action.Execute", - "tooltip": "%Widget_Template_Tooltip/Submit%", - "verb": "CheckUrl", - "iconUrl": "data:image/png;base64,${submitIcon}" - }, "spacing": "Medium", "style": "Url", "placeholder": "%Widget_Template_Input/UrlPlaceholder%", - "value": "${$root.configuration.url}" + "value": "${url}" }, { "type": "Input.Text", @@ -100,8 +94,7 @@ "type": "Action.Execute", "title": "%Widget_Template_Button/Save%", "verb": "Save", - "tooltip": "%Widget_Template_Tooltip/Save%", - "isEnabled": "${saveEnabled}" + "tooltip": "%Widget_Template_Tooltip/Save%" }, { "type": "Action.Execute", From 0fbabbef70e6fc88321e5e6cf965ffaa03019281 Mon Sep 17 00:00:00 2001 From: Vineeth Thomas Alex Date: Fri, 16 Aug 2024 14:09:06 -0500 Subject: [PATCH 2/7] Add JsonSerializerIsReflectionEnabledByDefault to props file (#431) Co-authored-by: Vineeth Thomas Alex --- Directory.Build.props | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Directory.Build.props b/Directory.Build.props index c6c3307..3a872c8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -55,4 +55,8 @@ + + + true + \ No newline at end of file From 00d2e88c5806a7a39e7232d3a9240ec54b9c7238 Mon Sep 17 00:00:00 2001 From: Felipe G Date: Wed, 28 Aug 2024 12:02:29 -0700 Subject: [PATCH 3/7] Making default titles not be saved in data (#439) Co-authored-by: Felipe da Conceicao Guimaraes --- .../Widgets/GitHubIssuesWidget.cs | 2 +- src/GitHubExtension/Widgets/GitHubPullsWidget.cs | 2 +- .../Widgets/GitHubReleasesWidget.cs | 2 +- .../Widgets/GitHubRepositoryWidget.cs | 16 +++++----------- src/GitHubExtension/Widgets/GitHubUserWidget.cs | 16 +++++++++++----- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs index 7d895e6..355012e 100644 --- a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs @@ -152,7 +152,7 @@ public override void LoadContentData() issuesData.Add("issues", issuesArray); issuesData.Add("selected_repo", repository?.FullName ?? string.Empty); - issuesData.Add("widgetTitle", WidgetTitle); + issuesData.Add("widgetTitle", GetActualTitle()); issuesData.Add("is_loading_data", DataState == WidgetDataState.Unknown); issuesData.Add("issues_icon_data", _issuesIconData); diff --git a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs index fad9d23..54691b8 100644 --- a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs @@ -123,7 +123,7 @@ public override void LoadContentData() pullsData.Add("pulls", pullsArray); pullsData.Add("selected_repo", repository?.FullName ?? string.Empty); - pullsData.Add("widgetTitle", WidgetTitle); + pullsData.Add("widgetTitle", GetActualTitle()); pullsData.Add("is_loading_data", DataState == WidgetDataState.Unknown); pullsData.Add("pulls_icon_data", _pullsIconData); diff --git a/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs b/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs index 5b3d708..5358c8d 100644 --- a/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs @@ -121,7 +121,7 @@ public override void LoadContentData() releasesData.Add("releases", releasesArray); releasesData.Add("selected_repo", repository?.FullName ?? string.Empty); - releasesData.Add("widgetTitle", WidgetTitle); + releasesData.Add("widgetTitle", GetActualTitle()); releasesData.Add("is_loading_data", DataState == WidgetDataState.Unknown); releasesData.Add("releases_icon_data", _releasesIconData); diff --git a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs index 582ac2d..2311b42 100644 --- a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs @@ -143,17 +143,11 @@ private void UpdateTitle(JsonNode? dataObj) } GetTitleFromDataObject(dataObj); - if (string.IsNullOrEmpty(WidgetTitle)) - { - try - { - WidgetTitle = GetRepositoryFromUrl(RepositoryUrl).FullName; - } - catch - { - WidgetTitle = string.Empty; - } - } + } + + protected string GetActualTitle() + { + return string.IsNullOrEmpty(WidgetTitle) ? GetRepositoryFromUrl(RepositoryUrl).FullName : WidgetTitle; } protected override void ResetWidgetInfoFromState() diff --git a/src/GitHubExtension/Widgets/GitHubUserWidget.cs b/src/GitHubExtension/Widgets/GitHubUserWidget.cs index ee8ee1b..b83901c 100644 --- a/src/GitHubExtension/Widgets/GitHubUserWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubUserWidget.cs @@ -57,11 +57,17 @@ public override void OnWidgetContextChanged(WidgetContextChangedArgs contextChan protected void UpdateTitle(JsonNode dataObj) { - GetTitleFromDataObject(dataObj); - if (string.IsNullOrEmpty(WidgetTitle)) + if (dataObj == null) { - WidgetTitle = UserName; + return; } + + GetTitleFromDataObject(dataObj); + } + + protected string GetActualTitle() + { + return string.IsNullOrEmpty(WidgetTitle) ? UserName : WidgetTitle; } protected override void ResetWidgetInfoFromState() @@ -249,7 +255,7 @@ public override void LoadContentData() { "openCount", 0 }, { "items", new JsonArray() }, { "userName", UserName }, - { "widgetTitle", WidgetTitle }, + { "widgetTitle", GetActualTitle() }, { "titleIconUrl", GetTitleIconData() }, { "is_loading_data", true }, }; @@ -302,7 +308,7 @@ public void LoadContentData(IEnumerable items) issuesData.Add("items", issuesArray); issuesData.Add("userName", UserName); issuesData.Add("titleIconUrl", GetTitleIconData()); - issuesData.Add("widgetTitle", WidgetTitle); + issuesData.Add("widgetTitle", GetActualTitle()); LastUpdated = DateTime.Now; ContentData = issuesData.ToJsonString(); From 0fb5d2348c60b75f25b311392775b548b8450593 Mon Sep 17 00:00:00 2001 From: Felipe G Date: Wed, 28 Aug 2024 14:57:05 -0700 Subject: [PATCH 4/7] Review requested widget now is customizable (#440) * Injecting in reiew code version * Injecting in template version * Reverted change in UserWidget class * Better quality of code, no more hacks --------- Co-authored-by: Felipe da Conceicao Guimaraes --- .../Widgets/GitHubReviewWidget.cs | 53 ++----------------- .../Widgets/GitHubUserWidget.cs | 6 ++- .../Package-Can.appxmanifest | 2 +- .../Package-Dev.appxmanifest | 2 +- .../Package.appxmanifest | 2 +- 5 files changed, 11 insertions(+), 54 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs index 7a5c00a..c0420ac 100644 --- a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs @@ -1,70 +1,25 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using System.Text.Json.Nodes; -using GitHubExtension.DataManager; using GitHubExtension.Helpers; -using Microsoft.Windows.Widgets.Providers; using Octokit; namespace GitHubExtension.Widgets; internal sealed class GitHubReviewWidget : GitHubUserWidget { - public GitHubReviewWidget() - : base() - { - // This widget does not allow customization, so this value will not change. - ShowCategory = SearchCategory.PullRequests; - } - - public override void RequestContentData() - { - var request = new SearchIssuesRequest($"review-requested:{UserName}"); - - RequestContentData(request); - } + protected override string DefaultShowCategory => "PullRequests"; protected override string GetTitleIconData() { return IconLoader.GetIconAsBase64("pulls.png"); } - // This widget does not have "ShowCategory" as a variable. - // So we override this method to not care about this data. - protected override void ResetWidgetInfoFromState() - { - base.ResetWidgetInfoFromState(); - ShowCategory = SearchCategory.PullRequests; - } - - // Overriding this method because this widget only cares about the account. - public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) + public override void RequestContentData() { - if (actionInvokedArgs.Verb == "Submit") - { - var data = actionInvokedArgs.Data; - var dataObject = JsonNode.Parse(data); - - if (dataObject == null) - { - return; - } - - DeveloperLoginId = dataObject["account"]?.GetValue() ?? string.Empty; - UpdateTitle(dataObject); - - ConfigurationData = data; + var request = new SearchIssuesRequest($"review-requested:{UserName}"); - // If we got here during the customization flow, we need to LoadContentData again - // so we can show the loading page rather than stale data. - LoadContentData(); - UpdateActivityState(); - } - else - { - base.OnActionInvoked(actionInvokedArgs); - } + RequestContentData(request); } public override string GetTemplatePath(WidgetPageState page) diff --git a/src/GitHubExtension/Widgets/GitHubUserWidget.cs b/src/GitHubExtension/Widgets/GitHubUserWidget.cs index b83901c..27e98de 100644 --- a/src/GitHubExtension/Widgets/GitHubUserWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubUserWidget.cs @@ -19,6 +19,8 @@ internal abstract class GitHubUserWidget : GitHubWidget protected SearchCategory ShowCategory { get; set; } = SearchCategory.Unknown; + protected virtual string DefaultShowCategory => string.Empty; + private string _userName = string.Empty; protected string UserName @@ -121,7 +123,7 @@ protected override void ResetWidgetInfoFromState() try { dataObject ??= JsonNode.Parse(ConfigurationData); - ShowCategory = EnumHelper.StringToSearchCategory(dataObject!["showCategory"]?.GetValue() ?? string.Empty); + ShowCategory = EnumHelper.StringToSearchCategory(dataObject!["showCategory"]?.GetValue() ?? DefaultShowCategory); DeveloperLoginId = dataObject!["account"]?.GetValue() ?? string.Empty; UpdateTitle(dataObject); } @@ -153,7 +155,7 @@ public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) return; } - ShowCategory = EnumHelper.StringToSearchCategory(dataObject["showCategory"]?.GetValue() ?? string.Empty); + ShowCategory = EnumHelper.StringToSearchCategory(dataObject["showCategory"]?.GetValue() ?? DefaultShowCategory); DeveloperLoginId = dataObject["account"]?.GetValue() ?? string.Empty; UpdateTitle(dataObject); diff --git a/src/GitHubExtensionServer/Package-Can.appxmanifest b/src/GitHubExtensionServer/Package-Can.appxmanifest index 6fb37d8..8f0db6d 100644 --- a/src/GitHubExtensionServer/Package-Can.appxmanifest +++ b/src/GitHubExtensionServer/Package-Can.appxmanifest @@ -212,7 +212,7 @@ - + diff --git a/src/GitHubExtensionServer/Package-Dev.appxmanifest b/src/GitHubExtensionServer/Package-Dev.appxmanifest index 92db75b..861e773 100644 --- a/src/GitHubExtensionServer/Package-Dev.appxmanifest +++ b/src/GitHubExtensionServer/Package-Dev.appxmanifest @@ -212,7 +212,7 @@ - + diff --git a/src/GitHubExtensionServer/Package.appxmanifest b/src/GitHubExtensionServer/Package.appxmanifest index 6895de1..785a937 100644 --- a/src/GitHubExtensionServer/Package.appxmanifest +++ b/src/GitHubExtensionServer/Package.appxmanifest @@ -212,7 +212,7 @@ - + From 9e343dc7567092e2082f37fb8e24aafed5e2b7a0 Mon Sep 17 00:00:00 2001 From: Eric Johnson Date: Wed, 4 Sep 2024 16:31:30 -0700 Subject: [PATCH 5/7] Update pipeline for compliance (#438) --- build/azure-pipelines.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/build/azure-pipelines.yml b/build/azure-pipelines.yml index 953f00d..258e006 100644 --- a/build/azure-pipelines.yml +++ b/build/azure-pipelines.yml @@ -38,6 +38,12 @@ extends: sdl: roslyn: enabled: true + binskim: + break: false + scanOutputDirectoryOnly: true + policheck: + break: false + severity: Note arrow: serviceConnection: DevHome Build VM Generation baseline: @@ -145,6 +151,16 @@ extends: filePath: 'build/scripts/Build.ps1' arguments: -Platform "${{ platform }}" -Configuration "${{ configuration }}" -Version $(MSIXVersion) -BuildStep "msix" -AzureBuildingBranch "$(BuildingBranch)" -IsAzurePipelineBuild -ClientId $(GitHubClientId) -ClientSecret $(GitHubClientSecret) + - task: PowerShell@2 + displayName: Copy Binaries for Artifact Publishing + inputs: + targetType: inline + script: >- + New-Item -Path '$(Build.ArtifactStagingDirectory)\rawBinaries' -ItemType Directory + + Get-ChildItem -Path "$(Build.SourcesDirectory)\buildoutput\*" -Include *.dll,*.exe,*.pdb -Recurse | Copy-Item -Destination "$(Build.ArtifactStagingDirectory)\rawBinaries" -verbose + pwsh: true + - template: ./build/templates/EsrpSigning-Steps.yml@self parameters: displayName: Submit *.msix to ESRP for code signing @@ -267,6 +283,10 @@ extends: targetPath: $(appxPackageDir)\${{ configuration }} sbomPackageName: devhomegithubextension.msixpackage sbomPackageVersion: $(MSIXVersion) + - output: pipelineArtifact + displayName: 'Publish Binaries' + artifactName: binaries_${{ platform }}_${{ configuration }} + targetPath: $(Build.ArtifactStagingDirectory)\rawBinaries - stage: Build_MsixBundle dependsOn: Build_Msix From b6ca3c443c9aba36623c8e6da1c37d851d1c5e89 Mon Sep 17 00:00:00 2001 From: Eric Johnson Date: Tue, 10 Sep 2024 10:08:31 -0700 Subject: [PATCH 6/7] Update to version 0.18 (#446) --- build/azure-pipelines.yml | 2 +- build/scripts/CreateBuildInfo.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/azure-pipelines.yml b/build/azure-pipelines.yml index 258e006..debeb36 100644 --- a/build/azure-pipelines.yml +++ b/build/azure-pipelines.yml @@ -20,7 +20,7 @@ parameters: - release variables: - MSIXVersion: '0.1700' + MSIXVersion: '0.1800' solution: '**/GitHubExtension.sln' appxPackageDir: 'AppxPackages' testOutputArtifactDir: 'TestResults' diff --git a/build/scripts/CreateBuildInfo.ps1 b/build/scripts/CreateBuildInfo.ps1 index ac0fa3a..2b0b363 100644 --- a/build/scripts/CreateBuildInfo.ps1 +++ b/build/scripts/CreateBuildInfo.ps1 @@ -5,7 +5,7 @@ Param( ) $Major = "0" -$Minor = "17" +$Minor = "18" $Patch = "99" # default to 99 for local builds $versionSplit = $Version.Split("."); From 86649390843cd7e921b9621bbc72a02e3e0db417 Mon Sep 17 00:00:00 2001 From: David Bennett Date: Wed, 11 Sep 2024 10:02:21 -0700 Subject: [PATCH 7/7] Add HttpRequestException expected exception handling (#443) --- .../DataManager/GitHubDataManager.cs | 16 ++++++++++++++++ .../DataManager/GitHubDataManagerUpdate.cs | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/src/GitHubExtension/DataManager/GitHubDataManager.cs b/src/GitHubExtension/DataManager/GitHubDataManager.cs index 170e42a..edf2229 100644 --- a/src/GitHubExtension/DataManager/GitHubDataManager.cs +++ b/src/GitHubExtension/DataManager/GitHubDataManager.cs @@ -251,6 +251,16 @@ private async Task UpdateDataStoreAsync(DataStoreOperationParameters parameters, PruneObsoleteData(); SetLastUpdatedInMetaData(); } + catch (HttpRequestException httpEx) + { + // HttpRequestExceptions can happen when internet connection is + // down or various other network issues. + _log.Warning($"Http Request Exception: {httpEx.Message}"); + tx.Rollback(); + + // Rethrow so clients can catch/display appropriate UX. + throw; + } catch (Exception ex) { _log.Error(ex, $"Failed Updating DataStore for: {parameters}"); @@ -331,6 +341,12 @@ private async Task UpdateDataForRepositoryAsync(DataStoreOperationParameters par PruneObsoleteData(); SetLastUpdatedInMetaData(); } + catch (HttpRequestException) + { + // Higher layer will catch and log this. Suppress logging an error for this to keep log clean. + tx.Rollback(); + throw; + } catch (Exception ex) { // This is for catching any other unexpected error as well as any we throw. diff --git a/src/GitHubExtension/DataManager/GitHubDataManagerUpdate.cs b/src/GitHubExtension/DataManager/GitHubDataManagerUpdate.cs index c3944fe..491299b 100644 --- a/src/GitHubExtension/DataManager/GitHubDataManagerUpdate.cs +++ b/src/GitHubExtension/DataManager/GitHubDataManagerUpdate.cs @@ -25,6 +25,15 @@ public static async Task Update() { await UpdateDeveloperPullRequests(); } + catch (HttpRequestException httpEx) + { + // HttpRequestExceptions can happen when internet connection is + // down or various other network issues unrelated to this update. + // This is not an error in the extension or anything we can + // address. Log a warning so it is understood why the update did + // not occur, but otherwise keep the log clean. + _log.Warning($"Http Request Exception: {httpEx.Message}"); + } catch (Exception ex) { _log.Error(ex, "Update failed unexpectedly.");