Skip to content

Commit

Permalink
Try adding PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Aug 15, 2024
1 parent 7c963fd commit 15c82ab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/review_pull_request.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pandas as pd
from policyengine_us_data.data_storage import STORAGE_FOLDER
from IPython.display import Markdown
from policyengine_us_data.utils.github import set_pr_auto_review_comment

def main():
df = pd.read_csv(STORAGE_FOLDER / "evaluation.csv")
Expand All @@ -11,11 +11,14 @@ def main():
diff = (most_recent_rows - second_most_recent_rows)
# Convert to df
diff = diff.reset_index()
diff = diff[diff.Variable == "household_net_income"]
table = diff.to_markdown(index=False)

review_text = f"""## National projection changes\n\n{table}"""

print(review_text)

set_pr_auto_review_comment(review_text)

if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion .github/upload_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from policyengine_us_data.data_storage import STORAGE_FOLDER

if __name__ == "__main__":
main()
upload(
"policyengine",
"policyengine-us-data",
Expand Down
21 changes: 21 additions & 0 deletions policyengine_us_data/utils/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,24 @@ def upload(
)

return response.json()

def set_pr_auto_review_comment(text: str):
# On a pull request, set a review comment with the given text.

pr_number = os.environ["GITHUB_PR_NUMBER"]

url = f"https://api.github.com/repos/{os.environ['GITHUB_REPOSITORY']}/pulls/{pr_number}/reviews"

response = requests.post(
url,
headers=auth_headers,
json={
"body": text,
"event": "COMMENT",
},
)

if response.status_code != 200:
raise ValueError(
f"Invalid response code {response.status_code} for url {url}. Received: {response.text}"
)

0 comments on commit 15c82ab

Please sign in to comment.