From 6a3a4402b64b767b7d072f31144d3a5ba6bba671 Mon Sep 17 00:00:00 2001 From: Sachin Bisht Date: Wed, 8 May 2024 10:58:49 +0530 Subject: [PATCH] Fixed code standared violation fixes --- .github/ISSUE_TEMPLATE/bug_report.md | 36 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 27 +++++++++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 37 +++++++++++++++++++++++ .github/workflows/pre-commit.yml | 15 +++++++++ .pre-commit-config.yaml | 17 +++++++++-- SLACKAPP.md | 32 ++++++++++---------- app/services/budget_service.py | 6 ++-- app/services/slack_service.py | 4 +-- requirements-dev.txt | 6 ++-- requirements.txt | 2 +- 10 files changed, 155 insertions(+), 27 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..1f8cf88 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,36 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[BUG] " +labels: bug +assignees: Sachinbisht27 + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Set webhook payload '...' +2. Trigger webhook '....' +3. See the error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Environment (please complete the following information):** + - Webhook Payload ``` here``` + - Environment - Production/Staging/other + +**Additional context** +Add any other context about the problem here. + +**Acceptance Criteria** +Add acceptance criteria here. + +**Documentation** +Add whatever documentation will be required here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..796cafd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,27 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[FEATURE] " +labels: enhancement +assignees: Sachinbisht27 + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. + + +**Acceptance Criteria** +Add acceptance criteria here. + +**Documentation** +Add whatever documentation will be required here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..3069ad3 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,37 @@ + + + +#[ISSUE_ID] + + + +### Please complete the following steps and check these boxes before filing your PR: + + +### Types of changes + +- [ ] Bug fix (a change which fixes an issue) +- [ ] New feature (a change which adds functionality) + + +### Short description of what this resolves: + + + + +### Checklist: + + +- [ ] I have performed a self-review of my own code. +- [ ] The code follows the style guidelines of this project. +- [ ] The code changes are passing the CI checks +- [ ] I have documented my code wherever required. +- [ ] The changes requires a change to the documentation. +- [ ] I have updated the documentation based on the my changes. +- [ ] I have added tests to cover my changes (if not applicable, please state why) +- [ ] All new and existing tests are passing. diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..ae667b2 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,15 @@ +name: pre-commit + +on: + pull_request: + push: + branches: + - develop + - main +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8b33f4f..892115c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -8,7 +8,20 @@ repos: - id: check-yaml - id: check-merge-conflict - id: check-added-large-files + - id: debug-statements + - id: requirements-txt-fixer - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 24.4.2 hooks: - id: black + args: [--line-length=88] +- repo: https://github.com/PyCQA/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + exclude: __init__.py + args: [--max-line-length=170] +- repo: https://github.com/PyCQA/docformatter + rev: v1.7.5 + hooks: + - id: docformatter diff --git a/SLACKAPP.md b/SLACKAPP.md index c36faf8..06b77ef 100644 --- a/SLACKAPP.md +++ b/SLACKAPP.md @@ -4,52 +4,52 @@ 1. Go to the channel on which you want to install the app 2. Go to the view all members icon on the top right of the channel - + ![image](https://github.com/Sachinbisht27/gcp-budget-alerts-service/assets/96137915/13cc0d92-076e-4fd5-b985-fb5102efac79) - + 3. Click on **add app** option 4. Click on **View app directory** 5. Click on the **build** option at the top right of the menu 6. Create an app from scratch 7. Provide a name to the app and assign it to a workspace 8. Go to OAuth and Permission menu - + ![image (9)](https://github.com/Sachinbisht27/gcp-budget-alerts-service/assets/96137915/252b96f9-ce02-4c74-bcdc-0527b01c3742) - + 9. Under the scope section, give the app permission to write messages - + ![image (10)](https://github.com/Sachinbisht27/gcp-budget-alerts-service/assets/96137915/6183d4aa-4577-4fe8-af35-5c8baf28d93c) - + 10. Install the app to the workspace - + ![image (11)](https://github.com/Sachinbisht27/gcp-budget-alerts-service/assets/96137915/4b75f0a7-0c34-4abe-b31d-120ed99d8679) - + 11. Give permission to the app - + ![image (12)](https://github.com/Sachinbisht27/gcp-budget-alerts-service/assets/96137915/1ef99851-9258-4c87-88f3-22dd7971d665) - + 12. Once the app is installed copy the OAuth Token as it will be used for authentication. - + ![image (14)](https://github.com/Sachinbisht27/gcp-budget-alerts-service/assets/96137915/355d7d13-9cef-4d6b-9a6d-894c96685e95) - + 13. Go to the channel where you want to add app. 14. Click on the `channel name` . 15. Click on the integrations tab here. - + ![Untitled](https://github.com/Sachinbisht27/gcp-budget-alerts-service/assets/96137915/cc301091-2403-4541-ad55-305224bc7f7c) - + 16. Then click on the `Add apps`. - + ![Untitled (2)](https://github.com/Sachinbisht27/gcp-budget-alerts-service/assets/96137915/1cf34c76-a38a-4f85-86c7-dd4ef0241246) - + 17. Then recognize the newly created app and add to the channel. ![Untitled (3)](https://github.com/Sachinbisht27/gcp-budget-alerts-service/assets/96137915/17cf0b6f-d8bb-4033-81f4-8bc64e543a8e) diff --git a/app/services/budget_service.py b/app/services/budget_service.py index b22ace3..28d5f80 100644 --- a/app/services/budget_service.py +++ b/app/services/budget_service.py @@ -32,8 +32,8 @@ def handle(self, alert_attrs, alert_data): # Check if the alert is for the previous month if year_month_of_budget_interval != current_year_month: - ## The pub/sub is sending us alerts for the previous month on the first day of the new month. - ## To handle this condition, we compare the Month-Year of the budget alert interval with the current Month-Year. + # The pub/sub is sending us alerts for the previous month on the first day of the new month. + # To handle this condition, we compare the Month-Year of the budget alert interval with the current Month-Year. return billing_id = alert_attrs.get("billingAccountId") @@ -47,7 +47,7 @@ def handle(self, alert_attrs, alert_data): notify = notification_helper.notify(slack_block) - if notify == True: + if notify: self.insert_new_threshold(cost, budget, budget_name, threshold) def is_new_threshold_greater(self, threshold): diff --git a/app/services/slack_service.py b/app/services/slack_service.py index 64fdde5..493e1b5 100644 --- a/app/services/slack_service.py +++ b/app/services/slack_service.py @@ -20,8 +20,8 @@ def send_alert(self, slack_block): channel=self.channel_name, blocks=slack_block["blocks"], ) - logger.info(f"Alert Sent") + logger.info("Alert Sent") return True except Exception as e: - logger.error(f"Exception occurred:{e}") + logger.error(f"Exception occurred:{e}. Response: {response}") return False diff --git a/requirements-dev.txt b/requirements-dev.txt index 0fa6829..a7ba2bd 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,6 @@ -pre-commit==2.20.0 -python-dotenv==0.20.0 -slackclient==2.9.4 functions-framework==3.2.0 google-cloud-logging==3.5.0 google_cloud_bigquery==3.11.4 +pre-commit==2.20.0 +python-dotenv==0.20.0 +slackclient==2.9.4 diff --git a/requirements.txt b/requirements.txt index edc0ae0..fc8bf2a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -slackclient==2.9.4 functions-framework==3.2.0 google-cloud-logging==3.5.0 google_cloud_bigquery==3.11.4 +slackclient==2.9.4 Werkzeug==2.3.7