Skip to content

refactor: extract GetWithLoggingAsync to eliminate HTTP timing/logging duplication in GitHubService#173

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-http-logging-pattern
Draft

refactor: extract GetWithLoggingAsync to eliminate HTTP timing/logging duplication in GitHubService#173
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-http-logging-pattern

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

The HTTP GET timing and response logging pattern was duplicated verbatim across three methods in GitHubService (GetCurrentUserAsync, GetPendingReviewsAsync, GetLatestReleaseAsync), meaning any change to log format or timing logic required three edits.

Changes

  • New helper GetWithLoggingAsync(string url) — consolidates the repeated pattern into a single private method:
private async Task<HttpResponseMessage> GetWithLoggingAsync(string url)
{
    Logger.LogInfo($"HTTP GET {url}");
    var startTime = DateTime.UtcNow;
    var response = await _httpClient.GetAsync(url);
    var elapsed = (DateTime.UtcNow - startTime).TotalMilliseconds;
    Logger.LogInfo($"HTTP Response: {(int)response.StatusCode} {response.StatusCode} | {elapsed:F0}ms | {url}");
    return response;
}
  • Replaced all 3 call sites with await GetWithLoggingAsync(url), removing the inline pre-request log lines where they existed.

Logging output is unchanged across all three methods.

Original prompt

This section details on the original issue you should resolve

<issue_title>Duplicate Code: HTTP Timing/Logging Pattern in GitHubService</issue_title>
<issue_description>Analysis of commit 0888461 (refactor: extract JsonFileStore helper to eliminate JSON persistence duplication)

Assignee: @copilot

Summary

The HTTP request timing and response logging pattern is duplicated 3 times in src/GitHubService.cs across the three async methods that make HTTP calls. Each instance measures elapsed time and logs the response status/timing in an identical (or near-identical) 4-line block.

Duplication Details

Pattern: HTTP GET timing + response logging

  • Severity: Medium

  • Occurrences: 3 instances

  • Locations:

    • src/GitHubService.cs (lines 60–64) — GetCurrentUserAsync
    • src/GitHubService.cs (lines 126–130) — GetPendingReviewsAsync
    • src/GitHubService.cs (lines 271–275) — GetLatestReleaseAsync
  • Code Sample:

    var startTime = DateTime.UtcNow;
    var response = await _httpClient.GetAsync(url);
    var elapsed = (DateTime.UtcNow - startTime).TotalMilliseconds;
    Logger.LogInfo($"HTTP Response: {(int)response.StatusCode} {response.StatusCode} | {elapsed:F0}ms | {url}");

Impact Analysis

  • Maintainability: Any change to the logging format or timing mechanism requires updating three places, risking inconsistency.
  • Bug Risk: If elapsed time calculation or log format changes, one instance may be missed, creating inconsistent log output.
  • Code Bloat: 12 lines of near-identical code across 3 methods in the same class.

Refactoring Recommendations

  1. Extract a private helper method in GitHubService
    • Add a method such as:
      private async Task(HttpResponseMessage) GetWithLoggingAsync(string url)
      {
          Logger.LogInfo($"HTTP GET {url}");
          var startTime = DateTime.UtcNow;
          var response = await _httpClient.GetAsync(url);
          var elapsed = (DateTime.UtcNow - startTime).TotalMilliseconds;
          Logger.LogInfo($"HTTP Response: {(int)response.StatusCode} {response.StatusCode} | {elapsed:F0}ms | {url}");
          return response;
      }
    • Replace all 3 call sites with await GetWithLoggingAsync(url).
    • Estimated effort: ~30 minutes
    • Benefits: Single point of change for log format, easier to extend (e.g., add retry logic, metrics)

Implementation Checklist

  • Review duplication findings
  • Extract GetWithLoggingAsync helper into GitHubService
  • Replace the 3 duplicated call sites
  • Verify logging output is unchanged
  • Confirm no functionality broken

Analysis Metadata

  • Analyzed Files: 22 .cs files (all non-test .cs files in the repository)
  • Detection Method: Manual grep-based pattern search (Serena LSP unavailable)
  • Commit: 0888461
  • Analysis Date: 2026-03-22T20:55:58Z

Generated by Duplicate Code Detector ·

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/duplicate-code-detector.md@852cb06ad52958b402ed982b69957ffc57ca0619

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…/logging duplication

Co-authored-by: sunzhuoshi <592211+sunzhuoshi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/sunzhuoshi/agent-supervisor/sessions/12b9d979-cafe-4426-a922-15f2148a5db1
Copilot AI changed the title [WIP] Refactor duplicate HTTP timing and logging in GitHubService refactor: extract GetWithLoggingAsync to eliminate HTTP timing/logging duplication in GitHubService Mar 25, 2026
Copilot AI requested a review from sunzhuoshi March 25, 2026 10:59
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.

Duplicate Code: HTTP Timing/Logging Pattern in GitHubService

2 participants