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

Create a Github Workflow to keep currencies in sync from API #129

Merged
merged 2 commits into from
Jul 14, 2024

Conversation

katosdev
Copy link
Contributor

@katosdev katosdev commented Jul 14, 2024

What type of PR is this?

  • feature

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

  • Discord issues.

Testing

Tested in a private repository and confirmed working.

Summary by CodeRabbit

  • New Features
    • Introduced an automated process to fetch and update currency data using a new Python script.
    • Implemented a GitHub Actions workflow to automatically update currency information on pushes to the main branch or manual dispatch.

Copy link
Contributor

coderabbitai bot commented Jul 14, 2024

Walkthrough

Walkthrough

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

File/Path Summary
.github/scripts/update_currencies.py Introduced functions to fetch, process, and save currency data to JSON.
.github/workflows/update-currencies.yml Added a GitHub Actions workflow to automate currency data updates.

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
Loading

Poem

When currencies dance in binary streams,
A Python script fulfills our dreams.
GitHub Actions, swift and keen,
Keeps our data evergreen.
Automated updates, a seamless flight,
In the code's embrace, day and night.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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.

Caution

Inline review comments failed to post

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 625730f and 967e574.

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."
fi

Length 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."
fi

Length of output: 96

.github/scripts/update_currencies.py (2)

26-30: Function save_currencies is well-implemented.

The function correctly handles file operations and saves the provided list of currencies to a specified JSON file.


31-37: Function main 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

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 967e574 and f0942f0.

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

@katosdev katosdev marked this pull request as ready for review July 14, 2024 15:04
@katosdev katosdev merged commit 2c34047 into main Jul 14, 2024
3 checks passed
@katosdev katosdev deleted the katos/currencies-auto-update branch July 14, 2024 15:05
truecharts-admin referenced this pull request in truecharts/public Jul 27, 2024
… 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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;katosdev](https://github.com/katosdev) in
[https://github.com/sysadminsmedia/homebox/pull/132](https://github.com/sysadminsmedia/homebox/pull/132)
- Update currencies by
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;Rshep3087](https://github.com/Rshep3087) in
[https://github.com/sysadminsmedia/homebox/pull/140](https://github.com/sysadminsmedia/homebox/pull/140)
- Update currencies by
[@&#8203;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
[@&#8203;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
[@&#8203;tankerkiller125](https://github.com/tankerkiller125) in
[https://github.com/sysadminsmedia/homebox/pull/148](https://github.com/sysadminsmedia/homebox/pull/148)

#### New Contributors

- [@&#8203;eltociear](https://github.com/eltociear) made their first
contribution in
[https://github.com/sysadminsmedia/homebox/pull/106](https://github.com/sysadminsmedia/homebox/pull/106)
- [@&#8203;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)
- [@&#8203;PatrickDaG](https://github.com/PatrickDaG) made their first
contribution in
[https://github.com/sysadminsmedia/homebox/pull/136](https://github.com/sysadminsmedia/homebox/pull/136)
- [@&#8203;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==-->
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