-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Create a Github Workflow to keep currencies in sync from API #129
Conversation
WalkthroughWalkthroughGreetings. The recent update introduces a new Python script that fetches and processes currency data from an API, then saves it to a JSON file. Additionally, a GitHub Actions workflow has been designed to automate this process upon pushes to the main branch or manual dispatch, ensuring the currency data remains current and accurate. Changes
Sequence Diagram(s)sequenceDiagram
participant GitHub as GitHub Actions
participant Script as update_currencies.py
participant API as Currency API
participant Repo as GitHub Repository
GitHub->>Script: Trigger workflow
Script->>API: fetch_currencies()
API-->>Script: Return currency data
Script->>Script: Process currency data
Script->>Repo: Save to JSON file
GitHub->>Repo: Commit and push updated JSON file
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 as PR comments)
Additionally, you can add CodeRabbit Configration 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.
Caution
Inline review comments failed to post
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- .github/scripts/update_currencies.py (1 hunks)
- .github/workflows/update-currencies.yml (1 hunks)
Additional comments not posted (6)
.github/workflows/update-currencies.yml (4)
1-7
: Workflow name and triggers are appropriate.The workflow is correctly named "Update Currencies" and is triggered by pushes to the main branch and manual dispatches, which aligns with the intended functionality.
9-20
: Job setup and environment are appropriate.The job runs on
ubuntu-latest
and includes steps to set up Python, which is suitable for this workflow.
22-27
: Dependency installation and script execution are appropriate.The dependencies are installed using pip, and the script
update_currencies.py
is executed correctly.
29-37
: Commit and push steps are correctly configured.The workflow configures Git, commits the changes, and pushes them back to the repository. Ensure the file path
backend/internal/core/currencies/currencies.json
is correct.Verification successful
Sir, the directory structure exists. Now, let's verify the existence of the
currencies.json
file within this directory.
Sir, the commit and push steps are correctly configured. The file path
backend/internal/core/currencies/currencies.json
is accurate, and the necessary file exists.
- The directory structure
backend/internal/core/currencies
exists.- The file
currencies.json
exists within this directory.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence of the file path for currency JSON file. # Test: Check if the directory structure exists. Expect: Directory structure exists. if [ -d "backend/internal/core/currencies" ]; then echo "Directory structure exists." else echo "Directory structure does not exist." fiLength of output: 110
Script:
#!/bin/bash # Description: Verify the existence of the currencies.json file. # Test: Check if the currencies.json file exists. Expect: File exists. if [ -f "backend/internal/core/currencies/currencies.json" ]; then echo "File exists." else echo "File does not exist." fiLength of output: 96
.github/scripts/update_currencies.py (2)
26-30
: Functionsave_currencies
is well-implemented.The function correctly handles file operations and saves the provided list of currencies to a specified JSON file.
31-37
: Functionmain
is well-implemented.The function correctly orchestrates the fetching and saving of currency data.
Comments failed to post (1)
.github/scripts/update_currencies.py
5-24: Function
fetch_currencies
is well-implemented.The function correctly fetches data from the API, processes it, and returns a list of currencies. Consider adding error handling for potential issues with the API response.
+ try: + response = requests.get('https://restcountries.com/v3.1/all') + response.raise_for_status() + except requests.RequestException as e: + print(f"An error occurred: {e}") + return [] countries = response.json()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.def fetch_currencies(): try: response = requests.get('https://restcountries.com/v3.1/all') response.raise_for_status() except requests.RequestException as e: print(f"An error occurred: {e}") return [] countries = response.json() currencies_list = [] for country in countries: country_name = country.get('name', {}).get('common') country_currencies = country.get('currencies', {}) for currency_code, currency_info in country_currencies.items(): symbol = currency_info.get('symbol', '') # Directly use the symbol as it is currencies_list.append({ 'code': currency_code, 'local': country_name, 'symbol': symbol, 'name': currency_info.get('name') }) return currencies_list
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- .github/scripts/update_currencies.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- .github/scripts/update_currencies.py
… v0.13.0@90328a8 by renovate (#24463) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [ghcr.io/sysadminsmedia/homebox](https://github.com/sysadminsmedia/homebox) | minor | `0.12.1` -> `0.13.0` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>sysadminsmedia/homebox (ghcr.io/sysadminsmedia/homebox)</summary> ### [`v0.13.0`](https://github.com/sysadminsmedia/homebox/releases/tag/v0.13.0) [Compare Source](https://github.com/sysadminsmedia/homebox/compare/v0.12.1...v0.13.0) #### What's Changed - docs: update get-started.md by [@​eltociear](https://github.com/eltociear) in [https://github.com/sysadminsmedia/homebox/pull/106](https://github.com/sysadminsmedia/homebox/pull/106) - Update location pricing to include quantity in calculation by [@​katosdev](https://github.com/katosdev) in [https://github.com/sysadminsmedia/homebox/pull/123](https://github.com/sysadminsmedia/homebox/pull/123) - Create a Github Workflow to keep currencies in sync from API by [@​katosdev](https://github.com/katosdev) in [https://github.com/sysadminsmedia/homebox/pull/129](https://github.com/sysadminsmedia/homebox/pull/129) - Update update_currencies.py to fix error handling by [@​katosdev](https://github.com/katosdev) in [https://github.com/sysadminsmedia/homebox/pull/130](https://github.com/sysadminsmedia/homebox/pull/130) - Skip commit attempt if currencies already synced with API by [@​katosdev](https://github.com/katosdev) in [https://github.com/sysadminsmedia/homebox/pull/131](https://github.com/sysadminsmedia/homebox/pull/131) - Force rebase on Update-currencies action by [@​katosdev](https://github.com/katosdev) in [https://github.com/sysadminsmedia/homebox/pull/132](https://github.com/sysadminsmedia/homebox/pull/132) - Update currencies by [@​github-actions](https://github.com/github-actions) in [https://github.com/sysadminsmedia/homebox/pull/133](https://github.com/sysadminsmedia/homebox/pull/133) - Add nmprc to automatically hoist dependencies by [@​PatrickDaG](https://github.com/PatrickDaG) in [https://github.com/sysadminsmedia/homebox/pull/136](https://github.com/sysadminsmedia/homebox/pull/136) - Add URL column to CSV export for items by [@​Rshep3087](https://github.com/Rshep3087) in [https://github.com/sysadminsmedia/homebox/pull/141](https://github.com/sysadminsmedia/homebox/pull/141) - Enable Sorting on Search By Created and Updated At by [@​Rshep3087](https://github.com/Rshep3087) in [https://github.com/sysadminsmedia/homebox/pull/140](https://github.com/sysadminsmedia/homebox/pull/140) - Update currencies by [@​github-actions](https://github.com/github-actions) in [https://github.com/sysadminsmedia/homebox/pull/143](https://github.com/sysadminsmedia/homebox/pull/143) - Splitting dependencies into separate docker layers (better caching) by [@​tankerkiller125](https://github.com/tankerkiller125) in [https://github.com/sysadminsmedia/homebox/pull/142](https://github.com/sysadminsmedia/homebox/pull/142) - chore: update openapi documentation by [@​tankerkiller125](https://github.com/tankerkiller125) in [https://github.com/sysadminsmedia/homebox/pull/148](https://github.com/sysadminsmedia/homebox/pull/148) #### New Contributors - [@​eltociear](https://github.com/eltociear) made their first contribution in [https://github.com/sysadminsmedia/homebox/pull/106](https://github.com/sysadminsmedia/homebox/pull/106) - [@​github-actions](https://github.com/github-actions) made their first contribution in [https://github.com/sysadminsmedia/homebox/pull/133](https://github.com/sysadminsmedia/homebox/pull/133) - [@​PatrickDaG](https://github.com/PatrickDaG) made their first contribution in [https://github.com/sysadminsmedia/homebox/pull/136](https://github.com/sysadminsmedia/homebox/pull/136) - [@​Rshep3087](https://github.com/Rshep3087) made their first contribution in [https://github.com/sysadminsmedia/homebox/pull/141](https://github.com/sysadminsmedia/homebox/pull/141) **Full Changelog**: sysadminsmedia/homebox@v0.12.1...v0.13.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44LjMiLCJ1cGRhdGVkSW5WZXIiOiIzOC44LjMiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIiLCJsYWJlbHMiOlsiYXV0b21lcmdlIiwidXBkYXRlL2RvY2tlci9nZW5lcmFsL25vbi1tYWpvciJdfQ==-->
What type of PR is this?
What this PR does / why we need it:
This PR creates a new Github workflow to poll
https://restcountries.com/v3.1/all
on every new commit and check for currencies. This then formats it into a JSON array and commits it back to the repository to ensure that currencies are always kept up-to-date and relevant.Which issue(s) this PR fixes:
Fixes:
#1
#79
Testing
Tested in a private repository and confirmed working.
Summary by CodeRabbit