-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ namespace Guppi.Core.Interfaces.Services; | |
|
||
public interface IBillService | ||
{ | ||
Task DownloadAlectraBills(); | ||
Task DownloadAllBills(int months); | ||
Task DownloadAlectraBills(int months); | ||
Task DownloadEnbridgeBills(int months); | ||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Parameter validation needed for Looking at the implementation in
Suggested locations that need validation:
🔗 Analysis chainConsider adding parameter validation. The
Let's check if there's any validation in the implementation: 🏁 Scripts executedThe 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 |
||
void InstallPlaywright(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider separating infrastructure 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();
} |
||
void Configure(); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using System.Collections.Generic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using System.IO; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using ClosedXML.Excel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
namespace Guppi.Core.Providers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public class WorkbookProvider | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readonly string _filename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readonly IXLWorkbook _workbook; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readonly IXLWorksheet _worksheet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int row = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+7
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider implementing an interface for better testability. The +public interface IWorkbookProvider
+{
+ void AddRow(IEnumerable<string> values);
+ void Save();
+}
-public class WorkbookProvider
+public class WorkbookProvider : IWorkbookProvider
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Creates a new instance of the WorksheetProvider | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <param name="filename">The filename for the workbook</param> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <param name="sheet">The name of the worksheet</param> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <param name="delete">Deletes and recreates the workbook if it exists</param> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public WorkbookProvider(string filename, string sheet, IEnumerable<string> headers, bool delete = true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_filename = filename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (delete && File.Exists(_filename)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
File.Delete(_filename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_workbook = new XLWorkbook(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_worksheet = _workbook.Worksheets.Add("Bills"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
AddRow(headers); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+14
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiple improvements needed in constructor implementation.
Apply these improvements: /// <summary>
-/// Creates a new instance of the WorksheetProvider
+/// Creates a new instance of the WorkbookProvider for managing Excel workbooks
/// </summary>
/// <param name="filename">The filename for the workbook</param>
-/// <param name="sheet">The name of the worksheet</param>
+/// <param name="sheet">The name of the worksheet to create</param>
+/// <param name="headers">The column headers to add as the first row</param>
/// <param name="delete">Deletes and recreates the workbook if it exists</param>
+/// <exception cref="ArgumentNullException">Thrown when filename, sheet, or headers is null</exception>
+/// <exception cref="ArgumentException">Thrown when headers collection is empty</exception>
public WorkbookProvider(string filename, string sheet, IEnumerable<string> headers, bool delete = true)
{
+ ArgumentNullException.ThrowIfNull(filename);
+ ArgumentNullException.ThrowIfNull(sheet);
+ ArgumentNullException.ThrowIfNull(headers);
+
+ if (!headers.Any())
+ throw new ArgumentException("Headers collection cannot be empty", nameof(headers));
+
_filename = filename;
if (delete && File.Exists(_filename))
{
File.Delete(_filename);
}
_workbook = new XLWorkbook();
- _worksheet = _workbook.Worksheets.Add("Bills");
+ _worksheet = _workbook.Worksheets.Add(sheet);
AddRow(headers);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void AddRow(IEnumerable<string> values) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
row++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int col = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
foreach (string value in values) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_worksheet.Cell(row, col++).Value = value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+35
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void Save() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_workbook.SaveAs(_filename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+44
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
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
Version changes should be documented in a changelog
Please create a CHANGELOG.md file in the root directory to track version changes. The new version 6.3.1 should be documented with:
🔗 Analysis chain
Version bump looks appropriate.
The increment from 6.3.0 to 6.3.1 aligns with semantic versioning for a patch release containing new features and fixes.
Let's verify the changelog is updated:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 174