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

Refactoring project structure #9

Merged
merged 1 commit into from
Nov 23, 2023
Merged

Conversation

madflojo
Copy link
Member

@madflojo madflojo commented Nov 23, 2023

This PR refactors a bit of the project structure to make things a bit easier to find and a bit more organized.

Summary by CodeRabbit

  • New Features

    • Implemented a new build process for better organization of output files.
    • Added a new testing framework for the lookup function with coverage reports.
    • Introduced a new function for fetching airport data from a remote source.
    • Created a function to download, parse, enrich, and load CSV data into an SQL database.
  • Documentation

    • Added comments to explain the purpose of new and existing functions.
  • Refactor

    • Updated the build commands to accommodate the new directory structure for function outputs.
  • Tests

    • Included a new tests target in the Makefile to facilitate running Go tests with additional flags.

Copy link
Contributor

coderabbitai bot commented Nov 23, 2023

Walkthrough

The project has undergone a build process overhaul, with a restructured output directory and the addition of a testing suite for the lookup function. New functionalities for fetching and loading data have been implemented, and the lookup handler has been updated with a new entry point function and descriptive comments.

Changes

File(s) Change Summary
Makefile Updated build target with new directory structure; added tests target for lookup function testing.
.../fetch/main.go Added function to fetch airport data from a remote CSV file.
.../init/main.go Added comment block explaining the function's purpose.
.../load/main.go Added function to download, parse, enrich, and load CSV data into SQL database.
.../handlers/lookup/Makefile Added tests target to run Go tests with verbose and race flags.
.../handlers/lookup/main.go Added Handler function to Function struct and descriptive comments.

🐇 In the code's woven thread, 🍂
Changes fall, new paths we tread.
Tests and builds, now finely wed,
A rabbit's work, ahead it sped. 🚀


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

Copy link

codecov bot commented Nov 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (346ce17) 92.92% compared to head (58e9632) 92.92%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main       #9   +/-   ##
=======================================
  Coverage   92.92%   92.92%           
=======================================
  Files           2        2           
  Lines          99       99           
=======================================
  Hits           92       92           
  Misses          5        5           
  Partials        2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@madflojo madflojo merged commit cc63a78 into tarmac-project:main Nov 23, 2023
5 checks passed
@madflojo madflojo deleted the refactor branch November 23, 2023 15:31
Copy link
Contributor

@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.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 060c473 and 58e9632.
Files ignored due to filter (6)
  • config/tarmac.json
  • functions/src/data/init/go.mod
  • functions/src/data/init/go.sum
  • functions/src/handlers/lookup/go.mod
  • functions/src/handlers/lookup/go.sum
  • functions/src/init/go.mod
Files selected for processing (6)
  • Makefile (1 hunks)
  • functions/src/data/fetch/main.go (1 hunks)
  • functions/src/data/init/main.go (1 hunks)
  • functions/src/data/load/main.go (1 hunks)
  • functions/src/handlers/lookup/Makefile (1 hunks)
  • functions/src/handlers/lookup/main.go (2 hunks)
Files skipped from review due to trivial changes (3)
  • functions/src/data/init/main.go
  • functions/src/handlers/lookup/Makefile
  • functions/src/handlers/lookup/main.go
Additional comments: 2
Makefile (1)
  • 1-25:
    The refactoring of the build target and the addition of the tests target are aligned with the summary of changes. The docker-compose target is unchanged as expected.
functions/src/data/load/main.go (1)
  • 1-7:
    The comment block at the top of the file is clear and informative.

Comment on lines 15 to +22
.PHONY: tests
tests:
## Run tests
mkdir -p coverage
go test -v -race -covermode=atomic -coverprofile=coverage/coverage.out ./...
go tool cover -html=coverage/coverage.out -o coverage/coverage.html
## Run tests for the lookup function
$(MAKE) -C functions/src/handlers/lookup tests
Copy link
Contributor

Choose a reason for hiding this comment

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

The mkdir command for the coverage directory should be checked to avoid unnecessary directory creation if it already exists.

-	mkdir -p coverage
+	[ -d coverage ] || mkdir -p coverage

Commitable 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.

Suggested change
.PHONY: tests
tests:
## Run tests
mkdir -p coverage
go test -v -race -covermode=atomic -coverprofile=coverage/coverage.out ./...
go tool cover -html=coverage/coverage.out -o coverage/coverage.html
## Run tests for the lookup function
$(MAKE) -C functions/src/handlers/lookup tests
.PHONY: tests
tests:
## Run tests
[ -d coverage ] || mkdir -p coverage
go test -v -race -covermode=atomic -coverprofile=coverage/coverage.out ./...
go tool cover -html=coverage/coverage.out -o coverage/coverage.html
## Run tests for the lookup function
$(MAKE) -C functions/src/handlers/lookup tests

Comment on lines +1 to +4
/*
This function fetches airport data from a remote CSV file via HTTP and returns it to the application. It is designed
for reuse throughout the application.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment block provides a good overview of the purpose of the fetch function. However, it should also mention the expected format of the data (CSV) and any assumptions made (e.g., the structure of the CSV file, if any).

Comment on lines +1 to 7
/*
This function fetches airport data from a remote CSV file via HTTP and returns it to the application. It is designed
for reuse throughout the application.
*/
package main

import (
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [15-15]

The Function struct is missing documentation. It's important to explain the purpose of each member, especially tarmac, which seems to be central to the operation of this function.


Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [24-24]

The error message "failed to get airports.csv" is repeated. It would be better to define this as a constant or to use a more descriptive message in each case to differentiate between the error of the HTTP GET request and the error of an unsatisfactory status code.


Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [31-31]

The check for rsp.StatusCode >= 299 is unconventional. Typically, the check is for rsp.StatusCode >= 400 to catch client and server errors. If the intention is to catch redirects as well, this should be explicitly documented.


Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [37-45]

Error handling is missing if the SDK initialization fails. The application should log the error and exit with a non-zero status code to indicate failure.

	if err != nil {
+		log.Fatalf("Failed to initialize Tarmac SDK: %v", err)
-		return
	}


This function is called multiple times throughout the application. It's called by an "init" function and also set
as a scheduled task by itself.
*/
package main

import (
Copy link
Contributor

Choose a reason for hiding this comment

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

Syntax error in the import block.

import (
+ )

Commitable 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.

Suggested change
import (
import (
)

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.

1 participant