-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Trey <[email protected]>
- Loading branch information
Showing
16 changed files
with
531 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions
63
.github/management_bot/pulumi/reminder_handler/lambda_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import json | ||
import os, base64 | ||
import urllib.request | ||
from textwrap import dedent | ||
|
||
from github import Github, Issue, GithubIntegration, PullRequest | ||
from github import Auth | ||
|
||
import logging | ||
import helpers | ||
|
||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.DEBUG if os.environ.get("DEBUG") else logging.DEBUG) # todo go back to info | ||
logger = logging.getLogger(__name__) | ||
|
||
aws_session_token = os.environ.get("AWS_SESSION_TOKEN") | ||
|
||
REPOSITORY_NAME = "TreyWW/MyFinances" | ||
|
||
|
||
def lambda_handler(event: dict, lambda_context): | ||
print(f"EVENT_DETAILS: {event}") | ||
# https://docs.aws.amazon.com/systems-manager/latest/userguide/ps-integration-lambda-extensions.html | ||
stage = "production" | ||
req = urllib.request.Request( | ||
f"http://localhost:2773/systemsmanager/parameters/get?withDecryption=true&name=%2Fmyfinances%2Fgithub_bot%2F{stage}" | ||
) | ||
req.add_header("X-Aws-Parameters-Secrets-Token", aws_session_token) | ||
config = urllib.request.urlopen(req).read() | ||
|
||
ssm_result: json = json.loads(config) | ||
ssm_value: json = json.loads(ssm_result["Parameter"]["Value"]) | ||
|
||
PRIVATE_KEY = helpers.decode_private_key(ssm_value["private_key"]) | ||
APP_ID = ssm_value["app_id"] | ||
|
||
auth = Auth.AppAuth(APP_ID, PRIVATE_KEY) | ||
gi = GithubIntegration(auth=auth) | ||
g: Github = gi.get_installations()[0].get_github_for_installation() | ||
|
||
repository = g.get_repo(REPOSITORY_NAME) | ||
|
||
target: Issue.Issue | PullRequest.PullRequest | ||
message: str = event.get("message") | ||
|
||
if issue_id := event.get("issue_id"): | ||
target = repository.get_issue(issue_id) | ||
elif pr_id := event.get("pr_id"): | ||
target = repository.get_pull(pr_id) | ||
else: | ||
raise ValueError("No issue or pull request specified") | ||
|
||
target.create_comment( | ||
dedent( | ||
f""" | ||
:wave: @{event.get("user")}, {message if message else "you set a reminder for now!"} | ||
{helpers.del_reply_comment()} | ||
""" | ||
) | ||
) | ||
|
||
return {"statusCode": 200, "body": json.dumps({}), "headers": {"Content-Type": "application/json"}} |
Oops, something went wrong.