diff --git a/.github/workflows/new-review.yml b/.github/workflows/new-review.yml index 014a122..ec52a0a 100644 --- a/.github/workflows/new-review.yml +++ b/.github/workflows/new-review.yml @@ -1,6 +1,6 @@ name: Handle case files on: - issues: + issues: types: [opened, edited] jobs: new-case-file: @@ -9,29 +9,29 @@ jobs: issues: write pull-requests: write steps: - - uses: actions/checkout@v2 - - name: Install requirements - run: python3 -m pip install -r automation/requirements.txt - - name: Run parser - id: run_parser - run: | - python3 automation/issue.py 2>&1 | tee parser.log - result_code=${PIPESTATUS[0]} - echo "::set-output name=parser-output::$(cat parser.log)" - exit $result_code - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 - with: - token: ${{ secrets.PR_TOKEN }} - title: "New coffee case #${{ github.event.issue.number }}" - branch: new-case-${{ github.event.issue.number }} - delete-branch: true - body: | - Author: @${{ github.event.issue.user.login }} - Closes #${{ github.event.issue.number }} + - uses: actions/checkout@v4 + - name: Install requirements + run: python3 -m pip install -r automation/requirements.txt + - name: Run parser + id: run_parser + run: | + python3 automation/issue.py 2>&1 | tee parser.log + result_code=${PIPESTATUS[0]} + echo "parser-output=$(cat parser.log)" >> $GITHUB_OUTPUT + exit $result_code + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.PR_TOKEN }} + title: "New coffee case #${{ github.event.issue.number }}" + branch: new-case-${{ github.event.issue.number }} + delete-branch: true + body: | + Author: @${{ github.event.issue.user.login }} + Closes #${{ github.event.issue.number }} - ${{join(steps.run_parser.outputs.*, '\n')}} + ${{join(steps.run_parser.outputs.*, '\n')}} - ``` - ${{ github.event.issue.body }} - ``` + ``` + ${{ github.event.issue.body }} + ``` diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..157a334 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +parser.log +venv/ \ No newline at end of file diff --git a/automation/issue.py b/automation/issue.py index 8ee863d..c22235f 100644 --- a/automation/issue.py +++ b/automation/issue.py @@ -1,18 +1,22 @@ #!/usr/bin/env python3 # Script to automation creation of pull requests based when # issues are created in the mocha.lawyer git repo. -import os import json +import os import re -import geocoder + import yaml +from geopy.geocoders import Nominatim + +geolocator = Nominatim(user_agent="mocha_lawyer") + def main(): # get path to github event file github_event_path = os.environ.get("GITHUB_EVENT_PATH") if github_event_path is None: raise Exception("Failed to get GITHUB_EVENT_PATH env var") - + # parse github event file github_data: dict = None with open(github_event_path, "r") as f: @@ -24,11 +28,13 @@ def main(): else: raise Exception("Failed to determine trigger type") + def handle_issue(github_event: dict): action = github_event.get("action") if action == "opened" or action == "edited": issue_data = github_event.get("issue") body = issue_data.get("body") + def findValue(key: str) -> str: val_search = re.search(f"(?:{key}:)\s*(.+)", body) if val_search: @@ -55,25 +61,31 @@ def findValue(key: str) -> str: dict_out[translation] = value # Perform geolocation - g = geocoder.osm(dict_out["address"]) - dict_out["latitude"] = g.lat - dict_out["longitude"] = g.lng + g = geolocator.geocode(dict_out["address"]) + lat = g.latitude + lng = g.longitude + dict_out["latitude"] = lat + dict_out["longitude"] = lng # Print out URL for automation to include in PR - print(f"[View Lat/Lng in OpenStreetMaps](https://www.openstreetmap.org/?mlat={g.lat}&mlon={g.lng}#map=19/{g.lat}/{g.lng})") + print( + f"[View Lat/Lng in OpenStreetMaps](https://www.openstreetmap.org/?mlat={lat}&mlon={lng}#map=19/{lat}/{lng})" + ) # Add any extra fields dict_out["author"] = issue_data.get("user", {}).get("login") # Convert some things - number_fields = [ "coffee-to-choco", "coffee-score", "chocolate-score", "price" ] + number_fields = ["coffee-to-choco", "coffee-score", "chocolate-score", "price"] for field in number_fields: dict_out[field] = float(dict_out[field]) # Write yaml file yaml_out = yaml.dump(dict_out, default_flow_style=False, explicit_start=True) issue_number = issue_data.get("number") - yaml_out_path = os.path.join(os.getcwd(), "site", "reviews", f"{issue_number}.yml") + yaml_out_path = os.path.join( + os.getcwd(), "site", "reviews", f"{issue_number}.yml" + ) if os.environ.get("DEBUG", None) == None: with open(yaml_out_path, "w") as f: f.write(yaml_out) @@ -86,5 +98,6 @@ def findValue(key: str) -> str: else: raise Exception(f"Action {action} unsupported") + if __name__ == "__main__": main() diff --git a/automation/requirements.txt b/automation/requirements.txt index 8483328..1f2b4e0 100644 --- a/automation/requirements.txt +++ b/automation/requirements.txt @@ -1 +1,39 @@ -geocoder==1.38.1 +affine==2.4.0 +async-timeout==4.0.3 +attrs==24.2.0 +casttube==0.2.1 +certifi==2023.11.17 +charset-normalizer==3.3.2 +click==8.1.7 +click-plugins==1.1.1 +cligj==0.7.2 +decorator==5.1.1 +future==1.0.0 +geographiclib==2.0 +geopy==2.4.1 +idna==3.6 +ifaddr==0.2.0 +importlib_metadata==8.4.0 +mercantile==1.2.1 +numpy==1.24.4 +protobuf==4.25.2 +psycopg2==2.9.9 +PyChromecast==13.0.8 +pyparsing==3.1.4 +PyYAML==6.0.2 +rasterio==1.3.11 +ratelim==0.1.6 +requests==2.31.0 +rio-mbtiles==1.6.0 +Shapely==1.7.1 +six==1.16.0 +snuggs==1.4.7 +spark-parser==1.8.9 +supermercado==0.2.0 +tgtg==0.14.0 +tqdm==4.66.5 +uncompyle6==3.9.0 +urllib3==2.1.0 +xdis==6.0.5 +zeroconf==0.131.0 +zipp==3.20.1 diff --git a/parser.log b/parser.log deleted file mode 100644 index a0f613c..0000000 --- a/parser.log +++ /dev/null @@ -1 +0,0 @@ -[View Lat/Lng in OpenStreetMaps](https://www.openstreetmap.org/?mlat=33.17469864434854&mlon=-117.36162378856099#map=19/33.17469864434854/-117.36162378856099) diff --git a/site/reviews/2.yml b/site/reviews/2.yml index 3f7be3f..8444fae 100644 --- a/site/reviews/2.yml +++ b/site/reviews/2.yml @@ -1,13 +1,13 @@ --- address: 90 Bedford Street New York NY +author: joshuaferrara chocolate-score: 4.0 coffee-score: 4.0 coffee-to-choco: 0.2 item: Mocha -latitude: 40.7323594 -longitude: -74.0052999 +latitude: 40.7322791 +longitude: -74.0052939 name: Central Perk notes: Waitress got the order wrong the 1st time price: 3.0 whip-cream: Smooth -author: joshuaferrara diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..9ed6549 --- /dev/null +++ b/test.sh @@ -0,0 +1,2 @@ +#!/bin/bash +GITHUB_EVENT_PATH=./automation/test.json python ./automation/issue.py \ No newline at end of file