-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·34 lines (26 loc) · 1009 Bytes
/
main.py
File metadata and controls
executable file
·34 lines (26 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python3
import json
import os
import requests
def main():
""" The main method executed. """
# Input variables
input_message = os.environ.get('INPUT_MESSAGE')
input_gchat_webhook_url = os.environ.get('INPUT_GCHAT_WEBHOOK_URL')
# Post message to GoogleChat
post_request_data = {'text': input_message}
post_request_details = requests.post(
input_gchat_webhook_url,
json=post_request_data)
if post_request_details.ok:
print('::debug::Message posted successfully.')
else:
try:
json_response = post_request_details.json()
error_message = json_response['error']['message'] if 'error' in json_response and 'message' in json_response['error'] else ''
except json.decoder.JSONDecodeError:
error_message = ''
print('::debug::Fail to post message to GChat.')
print(f'::debug::Got [{post_request_details.status_code}]: {error_message}')
if __name__ == "__main__":
main()