Skip to content

Refactor duplicated OAuth2 config and JSON serialization patterns#7

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/refactor-duplicated-code
Draft

Refactor duplicated OAuth2 config and JSON serialization patterns#7
Copilot wants to merge 4 commits intomainfrom
copilot/refactor-duplicated-code

Conversation

Copy link

Copilot AI commented Feb 16, 2026

Problem

Identical TryGetSetting patterns repeated across 4 OAuth2 client implementations. Duplicate JsonSerializerOptions initialization in 6+ files.

Changes

OAuth2 Configuration Utilities

Consolidated duplicated setting retrieval into OAuth2SettingsHelper:

// Before (repeated 4 times across GitHub, GitLab, Bitbucket clients)
if (settings.TryGetSetting(
    Constants.EnvironmentVariables.DevOAuthClientId,
    Constants.GitConfiguration.Credential.SectionName, 
    Constants.GitConfiguration.Credential.DevOAuthClientId,
    out string clientId))
{
    return clientId;
}
return Constants.OAuthClientId;

// After
return settings.GetOAuthConfigValue(
    Constants.EnvironmentVariables.DevOAuthClientId,
    Constants.GitConfiguration.Credential.SectionName,
    Constants.GitConfiguration.Credential.DevOAuthClientId,
    Constants.OAuthClientId);

Methods provided:

  • GetOAuthConfigValue() - optional config with fallback
  • GetRequiredOAuthConfigValue() - required config, throws if missing
  • GetOAuthConfigUri() - URI config with validation

Files refactored:

  • GitHub/GitHubOAuth2Client.cs
  • GitLab/GitLabOAuth2Client.cs
  • Atlassian.Bitbucket/Cloud/BitbucketOAuth2Client.cs
  • Atlassian.Bitbucket/DataCenter/BitbucketOAuth2Client.cs

JSON Serialization Options

Created shared JsonHelper with reusable configurations:

// Before (repeated in 6+ files)
JsonSerializer.Deserialize<T>(json, new JsonSerializerOptions
{
    PropertyNameCaseInsensitive = true
});

// After
JsonSerializer.Deserialize<T>(json, JsonHelper.CaseInsensitiveOptions);

Shared instances:

  • JsonHelper.CaseInsensitiveOptions
  • JsonHelper.CaseInsensitiveIgnoreNullOptions

Files refactored:

  • REST API implementations: BitbucketRestApi.cs (Cloud/DataCenter), OAuth2Client.cs
  • Test files: BitbucketTokenEndpointResponseJsonTest.cs, UserInfoTest.cs, TokenEndpointResponseJsonTest.cs

Impact

~160 lines of duplication eliminated across 12 files. Thread-safety documented for shared instances.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.29/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.29/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll (dns block)
  • www.apple.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.1/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.24.1/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.24.1/x64/codeql/xml/tools/xml-extractor.jar --fileList=/home/REDACTED/work/git-credential-manager/.codeql-scratch/dbs/csharp/working/files-to-index4456684017528651772.list --sourceArchiveDir=/home/REDACTED/work/git-credential-manager/.codeql-scratch/dbs/csharp/src --outputDir=/home/REDACTED/work/git-credential-manager/.codeql-scratch/dbs/csharp/trap/csharp -manager/git-credential-manager//low:false dll xQ465H/tmp7f58dcgit (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 16, 2026 04:15
Co-authored-by: mdellison90-stack <230609064+mdellison90-stack@users.noreply.github.com>
Co-authored-by: mdellison90-stack <230609064+mdellison90-stack@users.noreply.github.com>
Co-authored-by: mdellison90-stack <230609064+mdellison90-stack@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Refactor duplicated OAuth2 config and JSON serialization patterns Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants