Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download Enbridge bills #201

Merged
merged 5 commits into from
Oct 28, 2024
Merged

Download Enbridge bills #201

merged 5 commits into from
Oct 28, 2024

Conversation

rprouse
Copy link
Owner

@rprouse rprouse commented Oct 27, 2024

Fixes #200

  • Download Enbridge Bills
  • Fixes based on testing
  • Limit to downloading a specified number of months
  • Install playwright
  • Format the date

Summary by CodeRabbit

Release Notes

  • New Features

    • Updated version to 6.3.1.
    • Introduced a new "Bills" skill for downloading bills from Alectra and Enbridge for the past year.
    • Added command to install Playwright for the bills skill.
    • Enhanced command functionality to allow users to specify the number of months for bill downloads.
  • Bug Fixes

    • Improved error handling and command registration for bill downloads.
  • Documentation

    • Updated README with instructions for the new "Bills" skill and installation command.

Copy link

coderabbitai bot commented Oct 27, 2024

Walkthrough

The changes in this pull request encompass various updates across multiple files related to the Guppi command line utility. Key modifications include incrementing the version number in the project file, altering command line arguments in the launch settings, and enhancing the BillsSkill class to accept parameters for downloading bills. New methods and a class for managing Excel workbooks have been introduced, alongside updates to service interfaces. Additionally, the README file has been updated to include instructions for a new "Bills" skill.

Changes

File Path Change Summary
Guppi.Console/Guppi.Console.csproj Version updated from 6.3.0 to 6.3.1.
Guppi.Console/Properties/launchSettings.json Updated commandLineArgs from "bills alectra" to "bills all".
Guppi.Console/Skills/BillsSkill.cs Added parameterized methods for downloading bills, introduced DownloadBills method, and added install command.
Guppi.Core/Interfaces/Services/IBillService.cs Updated DownloadAlectraBills method to accept months parameter; added DownloadAllBills and DownloadEnbridgeBills.
Guppi.Core/Providers/WorkbookProvider.cs Added WorkbookProvider class for managing Excel workbooks, including methods for adding rows and saving.
Guppi.Core/Services/BillService.cs Introduced new methods for downloading bills with months parameter and improved error handling.
README.md Added new skill "Bills" with instructions for downloading bills and installing Playwright.

Poem

🐇 In the land of code where rabbits play,
New skills emerge to brighten the day.
With bills to fetch and workbooks to write,
Our utility shines, a true delight!
So hop along, dear friends, don't delay,
Embrace the changes, come what may! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 17

🧹 Outside diff range and nitpick comments (4)
Guppi.Core/Interfaces/Services/IBillService.cs (1)

7-9: Add XML documentation for public interface members.

Consider adding XML documentation to describe the purpose of each method, the valid ranges for the months parameter, and any exceptions that might be thrown.

Example:

+    /// <summary>
+    /// Downloads bills for all configured services.
+    /// </summary>
+    /// <param name="months">Number of months of history to download. Must be positive.</param>
+    /// <returns>A task representing the asynchronous download operation.</returns>
+    /// <exception cref="ArgumentOutOfRangeException">Thrown when months is less than or equal to 0.</exception>
     Task DownloadAllBills(int months);
README.md (2)

30-31: Fix grammatical errors.

Please apply these corrections:

  • "last years worth" should be "last year's worth"
  • "hard coded" should be "hard-coded"
-Downloads the last years worth of bills from Alectra and Enbridge. The account numbers for each utility
-are hard coded at the moment.
+Downloads the last year's worth of bills from Alectra and Enbridge. The account numbers for each utility
+are hard-coded at the moment.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~30-~30: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: ...solution ### Bills Downloads the last years worth of bills from Alectra and Enbridg...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)


[uncategorized] ~31-~31: This word is normally spelled with a hyphen.
Context: ...he account numbers for each utility are hard coded at the moment. You will need to instal...

(HARD_CODE_COMPOUND)


28-38: Add error handling and troubleshooting section.

Consider adding a troubleshooting section that covers:

  • Common installation issues with Playwright
  • What to do if bill download fails
  • How to verify correct account configuration

Would you like me to help draft this section?

🧰 Tools
🪛 LanguageTool

[uncategorized] ~30-~30: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: ...solution ### Bills Downloads the last years worth of bills from Alectra and Enbridg...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)


[uncategorized] ~31-~31: This word is normally spelled with a hyphen.
Context: ...he account numbers for each utility are hard coded at the moment. You will need to instal...

(HARD_CODE_COMPOUND)

Guppi.Core/Services/BillService.cs (1)

90-93: Offer assistance with configuration management

If you need help refactoring the code to externalize the account numbers and identifiers into configuration files, I'd be happy to assist with implementing this change.

Do you want me to help with refactoring the code to load account information from the configuration?

Also applies to: 120-122

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3e09fd0 and 0fb09ae.

📒 Files selected for processing (7)
  • Guppi.Console/Guppi.Console.csproj (1 hunks)
  • Guppi.Console/Properties/launchSettings.json (1 hunks)
  • Guppi.Console/Skills/BillsSkill.cs (2 hunks)
  • Guppi.Core/Interfaces/Services/IBillService.cs (1 hunks)
  • Guppi.Core/Providers/WorkbookProvider.cs (1 hunks)
  • Guppi.Core/Services/BillService.cs (5 hunks)
  • README.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Guppi.Console/Properties/launchSettings.json
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~30-~30: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: ...solution ### Bills Downloads the last years worth of bills from Alectra and Enbridg...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)


[uncategorized] ~31-~31: This word is normally spelled with a hyphen.
Context: ...he account numbers for each utility are hard coded at the moment. You will need to instal...

(HARD_CODE_COMPOUND)

🔇 Additional comments (14)
Guppi.Core/Providers/WorkbookProvider.cs (1)

1-4: Verify ClosedXML package reference.

Let's ensure the ClosedXML package is properly referenced in the project file.

✅ Verification successful

ClosedXML package reference is properly configured

The package is correctly referenced in the project file with version 0.104.1.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if ClosedXML is referenced in the project file
rg -l "PackageReference.*ClosedXML" --type csproj

Length of output: 82


Script:

#!/bin/bash
# Find all project files and check for ClosedXML reference
fd '\.csproj$' | xargs cat | grep -i "ClosedXML"

Length of output: 111

Guppi.Console/Guppi.Console.csproj (1)

Line range hint 44-45: Consider stability implications of beta dependencies.

The project depends on beta versions of System.CommandLine packages:

  • System.CommandLine (2.0.0-beta4.22272.1)
  • System.CommandLine.NamingConventionBinder (2.0.0-beta4.22272.1)

While these are stable beta releases, be aware that breaking changes could occur in future updates.

Let's check for any known issues or breaking changes:

✅ Verification successful

Beta dependencies are extensively used but stable in implementation

The System.CommandLine packages are indeed used extensively throughout the codebase:

  • Core application bootstrapping in Application.cs
  • 17+ skill modules consistently using the command-line parsing features
  • Consistent usage pattern across files using both System.CommandLine and System.CommandLine.NamingConventionBinder

The widespread and uniform usage pattern suggests the implementation is stable and well-established in the codebase. While the beta status of these packages warrants attention during updates, the current implementation appears robust and standardized across the application.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for System.CommandLine usage that might be affected by beta status
# Expected: Understanding of command-line parsing implementation

# Look for command-line argument parsing
ast-grep --pattern 'class $_ : Command'

Length of output: 41


Script:

#!/bin/bash
# Let's try different approaches to find System.CommandLine usage

# Search for System.CommandLine imports and usages
rg -l "System.CommandLine" --type csharp

# Search for Command class usage with namespace
rg "using System.CommandLine" -A 5 --type csharp

# Look for command-line related classes
rg "class.*Command" --type csharp

# Check specific package versions in csproj files
find . -name "*.csproj" -exec grep -l "System.CommandLine" {} \;

Length of output: 10208

README.md (1)

30-31: ⚠️ Potential issue

Add configuration instructions for account numbers.

Since the account numbers are currently hard-coded, please add instructions for users on where and how to configure their utility account numbers. This is especially important for security and reusability.

Let's verify if there's a configuration file or environment variables being used:

🧰 Tools
🪛 LanguageTool

[uncategorized] ~30-~30: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: ...solution ### Bills Downloads the last years worth of bills from Alectra and Enbridg...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)


[uncategorized] ~31-~31: This word is normally spelled with a hyphen.
Context: ...he account numbers for each utility are hard coded at the moment. You will need to instal...

(HARD_CODE_COMPOUND)

Guppi.Console/Skills/BillsSkill.cs (10)

19-20: Good use of option for specifying the number of months

The Option<int> for --months is correctly implemented with a default value of 1.


21-26: Correctly adding the option to the 'all' command

The option is appropriately added to the all command, and the handler is set to invoke DownloadAllBills with the months parameter.


29-32: Consistent implementation for the 'alectra' command

The option is added to the alectra command, and the handler correctly calls DownloadAlectraBills with the months parameter.


33-37: Proper addition of the option to the 'enbridge' command

The option is included in the enbridge command, and the handler is set to call DownloadEnbridgeBills with the months parameter.


43-45: 'install' command implemented correctly

The install command is added, and its handler invokes _service.InstallPlaywright() as expected.


48-51: Commands are organized under the 'bills' command appropriately

All subcommands (all, alectra, enbridge, install, configure) are correctly added under the bills command.


60-62: Efficient use of expression-bodied member for 'DownloadAllBills'

The method DownloadAllBills efficiently delegates to DownloadBills with the appropriate parameters.


63-65: 'DownloadAlectraBills' method correctly delegates to 'DownloadBills'

The method correctly passes the title, months, and downloader function to DownloadBills.


66-68: 'DownloadEnbridgeBills' method correctly implemented

The method appropriately calls DownloadBills with the correct parameters for Enbridge bills.


69-75: 🛠️ Refactor suggestion

Consider adding a general exception handler for robustness

Currently, DownloadBills catches UnconfiguredException and UnauthorizedException. Adding a general exception handler will improve error handling by catching unexpected exceptions and preventing the application from crashing.

Apply this diff to add a general exception handler:

     catch (UnconfiguredException ue)
     {
         AnsiConsole.MarkupLine($"[yellow][[:yellow_circle: {ue.Message}]][/]");
     }
     catch (UnauthorizedException ue)
     {
         AnsiConsole.MarkupLine($"[red][[:cross_mark: {ue.Message}]][/]");
+    }
+    catch (Exception ex)
+    {
+        AnsiConsole.MarkupLine($"[red][[:cross_mark: An unexpected error occurred: {ex.Message}]][/]");
+    }

Likely invalid or redundant comment.

Guppi.Core/Services/BillService.cs (1)

189-189: ⚠️ Potential issue

Add missing space in loop condition

There is a missing space between months and && in the loop condition, which can cause a compilation error.

Apply this diff to fix the issue:

-for (int i = 0; i < months&&  i < dateCells.Count && i < billLinks.Count; i++)
+for (int i = 0; i < months && i < dateCells.Count && i < billLinks.Count; i++)

Likely invalid or redundant comment.

Task DownloadAllBills(int months);
Task DownloadAlectraBills(int months);
Task DownloadEnbridgeBills(int months);
void InstallPlaywright();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider separating infrastructure concerns.

InstallPlaywright() appears to be an infrastructure concern that violates the Interface Segregation Principle. Consider moving it to a separate interface like IPlaywrightInstaller to maintain better separation of concerns.

Example refactor:

public interface IPlaywrightInstaller
{
    void InstallPlaywright();
}

public interface IBillService
{
    Task DownloadAllBills(int months);
    Task DownloadAlectraBills(int months);
    Task DownloadEnbridgeBills(int months);
    void Configure();
}

Comment on lines +7 to +9
Task DownloadAllBills(int months);
Task DownloadAlectraBills(int months);
Task DownloadEnbridgeBills(int months);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Parameter validation needed for months parameter

Looking at the implementation in BillService.cs, there is no validation for the months parameter in any of the download methods. This could lead to potential issues with:

  • Negative values
  • Unreasonably large values that could overload the system
  • Zero values that would result in no downloads

Suggested locations that need validation:

  • Guppi.Core/Services/BillService.cs: Add validation in the public methods DownloadAllBills, DownloadAlectraBills, and DownloadEnbridgeBills
  • Guppi.Core/Interfaces/Services/IBillService.cs: Add XML documentation to specify valid ranges for the months parameter
🔗 Analysis chain

Consider adding parameter validation.

The months parameter should be validated to ensure it's within acceptable ranges. Consider:

  1. Adding a custom attribute or documentation to specify valid ranges
  2. Implementing validation in the service implementation

Let's check if there's any validation in the implementation:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the service implementation to verify parameter validation
ast-grep --pattern 'class $_ : IBillService {
  $$$
  async Task DownloadAllBills(int months) {
    $$$
  }
  $$$
}'

Length of output: 118


Script:

#!/bin/bash
# Let's try a broader search for implementations of IBillService
rg "class.*IBillService" -A 5

# Also search for any implementation of these specific methods
rg "DownloadAllBills|DownloadAlectraBills|DownloadEnbridgeBills" -A 3

Length of output: 7619

Comment on lines +7 to +12
public class WorkbookProvider
{
readonly string _filename;
readonly IXLWorkbook _workbook;
readonly IXLWorksheet _worksheet;
int row = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider implementing an interface for better testability.

The WorkbookProvider class would benefit from having an interface definition (e.g., IWorkbookProvider). This would make it easier to mock in unit tests and follow the dependency inversion principle.

+public interface IWorkbookProvider
+{
+    void AddRow(IEnumerable<string> values);
+    void Save();
+}

-public class WorkbookProvider
+public class WorkbookProvider : IWorkbookProvider

Committable suggestion was skipped due to low confidence.

Comment on lines +44 to +47
public void Save()
{
_workbook.SaveAs(_filename);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling, documentation, and implement IDisposable.

The class should implement IDisposable to properly clean up ClosedXML resources. The Save method needs error handling and documentation.

Apply these improvements:

-public class WorkbookProvider : IWorkbookProvider
+public class WorkbookProvider : IWorkbookProvider, IDisposable
 {
     // ... existing code ...

+    /// <summary>
+    /// Saves the workbook to the specified filename
+    /// </summary>
+    /// <exception cref="IOException">Thrown when the file cannot be saved</exception>
     public void Save()
     {
-        _workbook.SaveAs(_filename);
+        try
+        {
+            _workbook.SaveAs(_filename);
+        }
+        catch (Exception ex)
+        {
+            throw new IOException($"Failed to save workbook to {_filename}", ex);
+        }
     }
+
+    public void Dispose()
+    {
+        _workbook?.Dispose();
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void Save()
{
_workbook.SaveAs(_filename);
}
public class WorkbookProvider : IWorkbookProvider, IDisposable
{
/// <summary>
/// Saves the workbook to the specified filename
/// </summary>
/// <exception cref="IOException">Thrown when the file cannot be saved</exception>
public void Save()
{
try
{
_workbook.SaveAs(_filename);
}
catch (Exception ex)
{
throw new IOException($"Failed to save workbook to {_filename}", ex);
}
}
public void Dispose()
{
_workbook?.Dispose();
}
}

Comment on lines +35 to +42
public void AddRow(IEnumerable<string> values)
{
row++;
int col = 1;
foreach (string value in values) {
_worksheet.Cell(row, col++).Value = value;
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add validation and documentation to AddRow method.

The method needs parameter validation and XML documentation. It should also ensure the number of values matches the number of columns.

Apply these improvements:

+/// <summary>
+/// Adds a new row of values to the worksheet
+/// </summary>
+/// <param name="values">The values to add to the row</param>
+/// <exception cref="ArgumentNullException">Thrown when values is null</exception>
+/// <exception cref="ArgumentException">Thrown when number of values doesn't match the number of columns</exception>
 public void AddRow(IEnumerable<string> values)
 {
+    ArgumentNullException.ThrowIfNull(values);
+    
+    var valuesList = values.ToList();
+    var columnCount = _worksheet.Row(1).CellsUsed().Count();
+    
+    if (valuesList.Count != columnCount)
+        throw new ArgumentException($"Number of values ({valuesList.Count}) must match number of columns ({columnCount})", nameof(values));
+
     row++;
     int col = 1;
-    foreach (string value in values) {
+    foreach (string value in valuesList) {
         _worksheet.Cell(row, col++).Value = value;
     }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void AddRow(IEnumerable<string> values)
{
row++;
int col = 1;
foreach (string value in values) {
_worksheet.Cell(row, col++).Value = value;
}
}
/// <summary>
/// Adds a new row of values to the worksheet
/// </summary>
/// <param name="values">The values to add to the row</param>
/// <exception cref="ArgumentNullException">Thrown when values is null</exception>
/// <exception cref="ArgumentException">Thrown when number of values doesn't match the number of columns</exception>
public void AddRow(IEnumerable<string> values)
{
ArgumentNullException.ThrowIfNull(values);
var valuesList = values.ToList();
var columnCount = _worksheet.Row(1).CellsUsed().Count();
if (valuesList.Count != columnCount)
throw new ArgumentException($"Number of values ({valuesList.Count}) must match number of columns ({columnCount})", nameof(values));
row++;
int col = 1;
foreach (string value in valuesList) {
_worksheet.Cell(row, col++).Value = value;
}
}

int _row = 2;
IXLWorksheet _worksheet;
readonly static string DOWNLOAD_PATH = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", "bills");
readonly static string[] HEADERS = ["Account", "Date", "Amount"];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix array initialization syntax in HEADERS

In C#, arrays should be initialized using curly braces {} instead of square brackets []. Replace the square brackets with curly braces to correctly initialize the HEADERS array.

Apply this diff to fix the issue:

-readonly static string[] HEADERS = ["Account", "Date", "Amount"];
+readonly static string[] HEADERS = { "Account", "Date", "Amount" };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
readonly static string[] HEADERS = ["Account", "Date", "Amount"];
readonly static string[] HEADERS = { "Account", "Date", "Amount" };


private bool Configured => _configuration.Configured;
public void InstallPlaywright()
{
Program.Main([ "install" ]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Correct array syntax in Program.Main call

When calling Program.Main, the argument should be a string array initialized with curly braces {}. Replace the square brackets [] with curly braces {} and use new[] to create the array.

Apply this diff to fix the issue:

-Program.Main([ "install" ]);
+Program.Main(new[] { "install" });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Program.Main([ "install" ]);
Program.Main(new[] { "install" });

Comment on lines +223 to +226
{
await dialog.AcceptAsync();
billingPage.Dialog -= billingPage_Dialog_EventHandler;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid using async void methods

Using async void methods can cause unobserved exceptions and make error handling difficult. It's recommended to use async Task instead.

Apply this diff to fix the issue:

-async void billingPage_Dialog_EventHandler(object sender, IDialog dialog)
+async Task billingPage_Dialog_EventHandler(object sender, IDialog dialog)

Ensure you adjust the event subscription accordingly:

-billingPage.Dialog += billingPage_Dialog_EventHandler;
+billingPage.Dialog += async (sender, dialog) => await billingPage_Dialog_EventHandler(sender, dialog);

Committable suggestion was skipped due to low confidence.

Comment on lines +120 to +122
await DownloadEnbridgeBillsForAccount(page, months, "201 VICTORIA AVE N UNIT 1");
await DownloadEnbridgeBillsForAccount(page, months, "201 VICTORIA AVE N UNIT 2");

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Avoid hardcoding account identifiers

Similarly, hardcoding account identifiers for Enbridge bills can lead to maintenance issues. Consider externalizing these identifiers to a configuration file or passing them as parameters.

Modify the method to accept a list of account addresses from the configuration:

-private async Task DownloadEnbridgeBillsInternal(int months)
+private async Task DownloadEnbridgeBillsInternal(int months, IEnumerable<string> accounts)
 {
     // Existing code...
 
-    await DownloadEnbridgeBillsForAccount(page, months, "201 VICTORIA AVE N UNIT 1");
-    await DownloadEnbridgeBillsForAccount(page, months, "201 VICTORIA AVE N UNIT 2");
+    foreach (var account in accounts)
+    {
+        await DownloadEnbridgeBillsForAccount(page, months, account);
+    }
 
     // Existing code...
 }

And pass the accounts from the configuration when calling the method.

Committable suggestion was skipped due to low confidence.

Comment on lines +90 to +93
await DownloadAlectraBillsForAccount(page, months, "8501783878");
await DownloadAlectraBillsForAccount(page, months, "7030931444");
await DownloadAlectraBillsForAccount(page, months, "9676981145");
await DownloadAlectraBillsForAccount(page, months, "7076520332");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Avoid hardcoding account numbers

Hardcoding account numbers directly in the code can lead to maintenance issues and potential security concerns. Consider externalizing these account numbers to a configuration file or passing them as parameters.

You can modify the method to accept a list of accounts from the configuration:

-private async Task DownloadAlectraBillsInternal(int months)
+private async Task DownloadAlectraBillsInternal(int months, IEnumerable<string> accounts)
 {
     // Existing code...
 
-    await DownloadAlectraBillsForAccount(page, months, "8501783878");
-    await DownloadAlectraBillsForAccount(page, months, "7030931444");
-    await DownloadAlectraBillsForAccount(page, months, "9676981145");
-    await DownloadAlectraBillsForAccount(page, months, "7076520332");
+    foreach (var account in accounts)
+    {
+        await DownloadAlectraBillsForAccount(page, months, account);
+    }
 
     // Existing code...
 }

And pass the accounts from the configuration when calling the method.

Committable suggestion was skipped due to low confidence.

@rprouse rprouse merged commit d67b840 into main Oct 28, 2024
2 checks passed
@rprouse rprouse deleted the issue/200 branch October 28, 2024 13:13
@coderabbitai coderabbitai bot mentioned this pull request Nov 29, 2024
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.

Download Enbridge bills
1 participant