mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[ADD] forwardport: some typing to conftest
It's not amazing, because cross-typing between the different conftests and utility modules doesn't really work smoothly. So not entirely convinced it's great. While at it, inline a few `x.json()` local aliases when the jsons are used in exclusive locations e.g. usually an assertion message on one side and a result / process on the other.
This commit is contained in:
parent
f4889ec8cf
commit
0e71f85802
30
conftest.py
30
conftest.py
@ -1,4 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Configuration:
|
Configuration:
|
||||||
|
|
||||||
@ -614,7 +617,7 @@ class Repo:
|
|||||||
assert res['object']['type'] == 'commit'
|
assert res['object']['type'] == 'commit'
|
||||||
return res['object']['sha']
|
return res['object']['sha']
|
||||||
|
|
||||||
def commit(self, ref):
|
def commit(self, ref: str) -> Commit:
|
||||||
if not re.match(r'[0-9a-f]{40}', ref):
|
if not re.match(r'[0-9a-f]{40}', ref):
|
||||||
if not ref.startswith(('heads/', 'refs/heads/')):
|
if not ref.startswith(('heads/', 'refs/heads/')):
|
||||||
ref = 'refs/heads/' + ref
|
ref = 'refs/heads/' + ref
|
||||||
@ -625,12 +628,11 @@ class Repo:
|
|||||||
ref = 'refs/' + ref
|
ref = 'refs/' + ref
|
||||||
|
|
||||||
r = self._session.get('https://api.github.com/repos/{}/commits/{}'.format(self.name, ref))
|
r = self._session.get('https://api.github.com/repos/{}/commits/{}'.format(self.name, ref))
|
||||||
response = r.json()
|
assert 200 <= r.status_code < 300, r.json()
|
||||||
assert 200 <= r.status_code < 300, response
|
|
||||||
|
|
||||||
return self._commit_from_gh(response)
|
return self._commit_from_gh(r.json())
|
||||||
|
|
||||||
def _commit_from_gh(self, gh_commit):
|
def _commit_from_gh(self, gh_commit: dict) -> Commit:
|
||||||
c = gh_commit['commit']
|
c = gh_commit['commit']
|
||||||
return Commit(
|
return Commit(
|
||||||
id=gh_commit['sha'],
|
id=gh_commit['sha'],
|
||||||
@ -788,7 +790,16 @@ class Repo:
|
|||||||
)).raise_for_status()
|
)).raise_for_status()
|
||||||
return PR(self, number)
|
return PR(self, number)
|
||||||
|
|
||||||
def make_pr(self, *, title=None, body=None, target, head, draft=False, token=None):
|
def make_pr(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
title: Optional[str] = None,
|
||||||
|
body: Optional[str] = None,
|
||||||
|
target: str,
|
||||||
|
head: str,
|
||||||
|
draft: bool = False,
|
||||||
|
token: Optional[str] = None
|
||||||
|
) -> PR:
|
||||||
assert self.hook
|
assert self.hook
|
||||||
self.hook = 2
|
self.hook = 2
|
||||||
|
|
||||||
@ -821,10 +832,9 @@ class Repo:
|
|||||||
},
|
},
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
pr = r.json()
|
assert 200 <= r.status_code < 300, r.json()
|
||||||
assert 200 <= r.status_code < 300, pr
|
|
||||||
|
|
||||||
return PR(self, pr['number'])
|
return PR(self, r.json()['number'])
|
||||||
|
|
||||||
def post_status(self, ref, status, context='default', **kw):
|
def post_status(self, ref, status, context='default', **kw):
|
||||||
assert self.hook
|
assert self.hook
|
||||||
|
Loading…
Reference in New Issue
Block a user