-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
WalkthroughThe 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 Changes
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 managementIf 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
📒 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 csprojLength 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
andSystem.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 issueAdd 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 monthsThe
Option<int>
for--months
is correctly implemented with a default value of1
.
21-26
: Correctly adding the option to the 'all' commandThe
option
is appropriately added to theall
command, and the handler is set to invokeDownloadAllBills
with themonths
parameter.
29-32
: Consistent implementation for the 'alectra' commandThe
option
is added to thealectra
command, and the handler correctly callsDownloadAlectraBills
with themonths
parameter.
33-37
: Proper addition of the option to the 'enbridge' commandThe
option
is included in theenbridge
command, and the handler is set to callDownloadEnbridgeBills
with themonths
parameter.
43-45
: 'install' command implemented correctlyThe
install
command is added, and its handler invokes_service.InstallPlaywright()
as expected.
48-51
: Commands are organized under the 'bills' command appropriatelyAll subcommands (
all
,alectra
,enbridge
,install
,configure
) are correctly added under thebills
command.
60-62
: Efficient use of expression-bodied member for 'DownloadAllBills'The method
DownloadAllBills
efficiently delegates toDownloadBills
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 implementedThe method appropriately calls
DownloadBills
with the correct parameters for Enbridge bills.
69-75
: 🛠️ Refactor suggestionConsider adding a general exception handler for robustness
Currently,
DownloadBills
catchesUnconfiguredException
andUnauthorizedException
. 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 issueAdd 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(); |
There was a problem hiding this comment.
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();
}
Task DownloadAllBills(int months); | ||
Task DownloadAlectraBills(int months); | ||
Task DownloadEnbridgeBills(int months); |
There was a problem hiding this comment.
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 methodsDownloadAllBills
,DownloadAlectraBills
, andDownloadEnbridgeBills
Guppi.Core/Interfaces/Services/IBillService.cs
: Add XML documentation to specify valid ranges for themonths
parameter
🔗 Analysis chain
Consider adding parameter validation.
The months
parameter should be validated to ensure it's within acceptable ranges. Consider:
- Adding a custom attribute or documentation to specify valid ranges
- 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
public class WorkbookProvider | ||
{ | ||
readonly string _filename; | ||
readonly IXLWorkbook _workbook; | ||
readonly IXLWorksheet _worksheet; | ||
int row = 0; |
There was a problem hiding this comment.
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.
public void Save() | ||
{ | ||
_workbook.SaveAs(_filename); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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(); | |
} | |
} |
public void AddRow(IEnumerable<string> values) | ||
{ | ||
row++; | ||
int col = 1; | ||
foreach (string value in values) { | ||
_worksheet.Cell(row, col++).Value = value; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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" ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Program.Main([ "install" ]); | |
Program.Main(new[] { "install" }); |
{ | ||
await dialog.AcceptAsync(); | ||
billingPage.Dialog -= billingPage_Dialog_EventHandler; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
await DownloadEnbridgeBillsForAccount(page, months, "201 VICTORIA AVE N UNIT 1"); | ||
await DownloadEnbridgeBillsForAccount(page, months, "201 VICTORIA AVE N UNIT 2"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
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.
await DownloadAlectraBillsForAccount(page, months, "8501783878"); | ||
await DownloadAlectraBillsForAccount(page, months, "7030931444"); | ||
await DownloadAlectraBillsForAccount(page, months, "9676981145"); | ||
await DownloadAlectraBillsForAccount(page, months, "7076520332"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
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.
Fixes #200
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Documentation