Skip to content

Commit

Permalink
Merge pull request #39 from joshuaferrara/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
joshuaferrara authored Oct 11, 2024
2 parents 5287884 + 6dd5ec7 commit 33bf266
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 39 deletions.
50 changes: 25 additions & 25 deletions .github/workflows/new-review.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Handle case files
on:
issues:
issues:
types: [opened, edited]
jobs:
new-case-file:
Expand All @@ -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 }}
```
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parser.log
venv/
31 changes: 22 additions & 9 deletions automation/issue.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -86,5 +98,6 @@ def findValue(key: str) -> str:
else:
raise Exception(f"Action {action} unsupported")


if __name__ == "__main__":
main()
40 changes: 39 additions & 1 deletion automation/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion parser.log

This file was deleted.

6 changes: 3 additions & 3 deletions site/reviews/2.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
GITHUB_EVENT_PATH=./automation/test.json python ./automation/issue.py

0 comments on commit 33bf266

Please sign in to comment.