anteater/runbot.py
Hubert Van De Walle 5b92d2a8a5 anteater v2
2025-05-07 11:01:35 +02:00

61 lines
1.8 KiB
Python

import re
from typing import Literal
import requests
from bs4 import BeautifulSoup
bundles = {
"17.0": "17-0-192736",
"18.0": "18-0-320432",
}
Repo = Literal[
"odoo", "enterprise", "design-themes", "upgrade", "documentation", "upgrade-util"
]
def _commits_from_batch(id: int) -> dict[Repo, str]:
url = f"https://runbot.odoo.com/runbot/batch/{id}"
res = requests.get(url)
assert res.status_code == 200
soup = BeautifulSoup(res.text, "html.parser")
commit_nodes = soup.select("a[title='View Commit on Github']")
commits = dict()
assert len(commit_nodes) > 0
gh_re = re.compile(r"https://github.com/odoo/([\w-]+)/commit/(\w+)")
for commit in commit_nodes:
match = gh_re.search(commit["href"])
repo = match.group(1)
commit = match.group(2)
commits[repo] = commit
assert "odoo" in commits
assert "enterprise" in commits
return commits
def _get_bundle_last_page(version: str) -> int:
bundle = bundles[version]
url = f"https://runbot.odoo.com/runbot/bundle/{bundle}/page/1000"
res = requests.get(url)
assert res.status_code == 200
soup = BeautifulSoup(res.text, "html.parser")
text = soup.select_one(".page-item.active").get_text(strip=True)
return int(text)
def _get_batches(bundle, page=1) -> list[int]:
limit = 5000
url = f"https://runbot.odoo.com/runbot/bundle/{bundle}?limit={limit}"
res = requests.get(url)
assert res.status_code == 200
soup = BeautifulSoup(res.text, "html.parser")
batch_nodes = soup.select("div.batch_row")
batch_url_re = re.compile(r"^/runbot/batch/(\d+)$")
ids = []
for node in batch_nodes:
link = node.select_one("a[title='View Batch']")["href"]
match = batch_url_re.search(link)
ids.append(match.group(1))
return ids