From 72402edafb17f70bedaf0d6530ba299323ca40cd Mon Sep 17 00:00:00 2001 From: Marc Wrobel Date: Sun, 10 Dec 2023 22:33:43 +0100 Subject: [PATCH] [jira] Refactor script (#232) Make the script more readable, mostly by: - using the Product classes, - a little bit of renaming and documentation. --- src/confluence.py | 4 ++-- src/jira.py | 24 ++++++++---------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/confluence.py b/src/confluence.py index 1509f2f2..5cb94344 100644 --- a/src/confluence.py +++ b/src/confluence.py @@ -13,8 +13,8 @@ r.html.render(sleep=1, scrolldown=3) for version_block in r.html.find('.versions-list'): version = version_block.find('a.product-versions', first=True).attrs['data-version'] - date_text = version_block.find('.release-date', first=True).text - product.declare_version(version, dates.parse_date(date_text)) + date = dates.parse_date(version_block.find('.release-date', first=True).text) + product.declare_version(version, date) product.write() print("::endgroup::") diff --git a/src/jira.py b/src/jira.py index bc87a8bf..b1652fe3 100644 --- a/src/jira.py +++ b/src/jira.py @@ -2,27 +2,19 @@ from requests_html import HTMLSession from common import dates from common import endoflife -"""Fetch Jira versions with their dates from the Atlassian Website. +"""Fetches Jira versions from www.atlassian.com. -This script is using requests-html (https://requests-html.kennethreitz.org/) -because the page needs JavaScript to render correctly. -""" +Note that requests_html is used because JavaScript is needed to render the page.""" -PRODUCT = 'jira' -URL = 'https://www.atlassian.com/software/jira/update' - -print(f"::group::{PRODUCT}") -session = HTMLSession() -r = session.get(URL) +product = endoflife.Product("jira") +print(f"::group::{product.name}") +r = HTMLSession().get("https://www.atlassian.com/software/jira/update") r.html.render(sleep=1, scrolldown=3) -versions = {} for version_block in r.html.find('.versions-list'): version = version_block.find('a.product-versions', first=True).attrs['data-version'] - date_text = version_block.find('.release-date', first=True).text - date = dates.parse_date(date_text).strftime('%Y-%m-%d') - print(f"{version}: {date}") - versions[version] = date + date = dates.parse_date(version_block.find('.release-date', first=True).text) + product.declare_version(version, date) -endoflife.write_releases(PRODUCT, versions) +product.write() print("::endgroup::")