in webhooks-with-cloud-run/MicroServices/GitHub/github.py [0:0]
def index():
# Subscribes to Pub/Sub Topic
# and sends a message to Slack Channel
envelope = request.get_json()
# Check if valid JSON
if not envelope:
raise Exception("Expecting JSON payload")
# Check if valid pub/sub message
if "message" not in envelope:
raise Exception("Not a valid Pub/Sub Message")
msg = envelope["message"]
data = json.loads(base64.b64decode(msg["data"]).decode("utf-8").strip())
if data["action"] == "opened":
# Post response to Github
create_issue_comment(data["issue"]["url"])
sys.stdout.flush()
return ("", 204)