mirror of
https://github.com/zen-browser/desktop.git
synced 2025-07-07 21:49:58 +02:00
Update check-rc-response.py
Signed-off-by: Cristian Cezar Moisés <ethicalhacker@riseup.net>
This commit is contained in:
parent
d993ab7b48
commit
3ab089c264
1 changed files with 52 additions and 54 deletions
|
@ -1,63 +1,61 @@
|
|||
import json
|
||||
import sys
|
||||
import os
|
||||
import requests
|
||||
from typing import Optional
|
||||
|
||||
RESPONSE = 'rc-response.json'
|
||||
METADATA = 'surfer.json'
|
||||
RESPONSE_FILENAME = 'rc-response.json'
|
||||
METADATA_FILENAME = 'surfer.json'
|
||||
|
||||
def get_current_version():
|
||||
with open(METADATA) as f:
|
||||
metadata = json.load(f)
|
||||
return metadata['version']['candidate']
|
||||
def get_current_version() -> Optional[str]:
|
||||
"""Retrieve the current version from the metadata file."""
|
||||
try:
|
||||
with open(METADATA_FILENAME) as f:
|
||||
metadata = json.load(f)
|
||||
return metadata['version']['candidate']
|
||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||
print(f"Error reading current version: {e}")
|
||||
return None
|
||||
|
||||
def get_rc_response():
|
||||
with open(RESPONSE) as f:
|
||||
data = json.load(f)
|
||||
for tag_dict in data['tags']:
|
||||
tag = tag_dict['tag']
|
||||
is_valid_tag = (tag.startswith('FIREFOX') and tag.endswith('_BUILD1')
|
||||
and not 'ESR' in tag and not 'b' in tag)
|
||||
if is_valid_tag:
|
||||
return tag.replace('FIREFOX_', '').replace('_BUILD1', '').replace('_', '.')
|
||||
return None
|
||||
def get_rc_response() -> Optional[str]:
|
||||
"""Get the release candidate response from the response file."""
|
||||
try:
|
||||
with open(RESPONSE_FILENAME) as f:
|
||||
data = json.load(f)
|
||||
for tag_dict in data['tags']:
|
||||
tag = tag_dict['tag']
|
||||
if (tag.startswith('FIREFOX') and tag.endswith('_BUILD1')
|
||||
and 'ESR' not in tag and 'b' not in tag):
|
||||
return tag.replace('FIREFOX_', '').replace('_BUILD1', '').replace('_', '.')
|
||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||
print(f"Error reading RC response: {e}")
|
||||
return None
|
||||
|
||||
def get_pings():
|
||||
pings = ""
|
||||
for ping in os.getenv('DISCORD_PING_IDS').split(','):
|
||||
pings += "<@%s> " % ping
|
||||
return pings
|
||||
def get_pings() -> str:
|
||||
"""Build a string of Discord user IDs for mentions."""
|
||||
ping_ids = os.getenv('DISCORD_PING_IDS', '')
|
||||
return ' '.join(f"<@{ping.strip()}>" for ping in ping_ids.split(',') if ping.strip())
|
||||
|
||||
def send_webhook(rc: str):
|
||||
text = "||%s|| New Firefox RC version is available: **%s**" % (get_pings(), rc)
|
||||
webhook_url = os.getenv('DISCORD_WEBHOOK_URL') #os.getenv('DISCORD_WEBHOOK_URL')
|
||||
message = {
|
||||
"content": text,
|
||||
"username": "Firefox RC Checker",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/189789277?v=4",
|
||||
}
|
||||
response = requests.post(webhook_url, json=message)
|
||||
if response.status_code == 204:
|
||||
print("Message sent successfully!")
|
||||
else:
|
||||
print(f"Failed to send message: {response.status_code}")
|
||||
def send_webhook(rc: str) -> None:
|
||||
"""Send a message to the Discord webhook."""
|
||||
text = f"||{get_pings()}|| New Firefox RC version is available: **{rc}**"
|
||||
webhook_url = os.getenv('DISCORD_WEBHOOK_URL')
|
||||
|
||||
if webhook_url:
|
||||
message = {
|
||||
"content": text,
|
||||
"username": "Firefox RC Checker",
|
||||
}
|
||||
try:
|
||||
response = requests.post(webhook_url, json=message)
|
||||
response.raise_for_status() # Raise an error for bad responses
|
||||
except requests.RequestException as e:
|
||||
print(f"Error sending webhook: {e}")
|
||||
else:
|
||||
print("Webhook URL not set.")
|
||||
|
||||
def main():
|
||||
current = get_current_version()
|
||||
if not current:
|
||||
print('Could not find current version')
|
||||
return 1
|
||||
rc = get_rc_response()
|
||||
if not rc:
|
||||
print('Could not find RC version')
|
||||
return 1
|
||||
if current != rc:
|
||||
print('Current version is %s, but RC version is %s' % (current, rc))
|
||||
# Here, we should update the current version in surfer.json
|
||||
send_webhook(rc)
|
||||
return 0
|
||||
print('Current version is %s, and RC version is %s' % (current, rc))
|
||||
return 1
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
if __name__ == "__main__":
|
||||
current_version = get_current_version()
|
||||
rc_response = get_rc_response()
|
||||
|
||||
if rc_response and rc_response != current_version:
|
||||
send_webhook(rc_response)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue