Merge pull request #1374 from jberry-suse/request_age-followup

osclib/core: request_age() return delta and handle Request object.
This commit is contained in:
Jimmy Berry 2018-01-29 21:18:56 -06:00 committed by GitHub
commit a13cfbdfe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 8 deletions

View File

@ -109,7 +109,7 @@ def requests(args):
withfullhistory=True) withfullhistory=True)
for request in requests: for request in requests:
action = request.actions[0] action = request.actions[0]
age = request_age(request) age = request_age(request).days
if age < args.min_age: if age < args.min_age:
continue continue
@ -134,7 +134,7 @@ def reviews(args):
if action.type != 'submit': if action.type != 'submit':
continue continue
age = request_age(request) age = request_age(request).days
if age < args.min_age: if age < args.min_age:
continue continue

View File

@ -10,6 +10,7 @@ from osc.core import get_dependson
from osc.core import http_GET from osc.core import http_GET
from osc.core import makeurl from osc.core import makeurl
from osc.core import owner from osc.core import owner
from osc.core import Request
from osc.core import show_package_meta from osc.core import show_package_meta
from osc.core import show_project_meta from osc.core import show_project_meta
from osclib.memoize import memoize from osclib.memoize import memoize
@ -166,6 +167,9 @@ def devel_project_fallback(apiurl, target_project, target_package):
return project, package return project, package
def request_age(request): def request_age(request):
created = date_parse(request.find('history').get('when')) if isinstance(request, Request):
delta = datetime.utcnow() - created created = request.statehistory[0].when
return delta.total_seconds() else:
created = request.find('history').get('when')
created = date_parse(created)
return datetime.utcnow() - created

View File

@ -107,7 +107,7 @@ class RequestSplitter(object):
history = request.find('history') history = request.find('history')
if history is not None: if history is not None:
age = request_age(request) age = request_age(request).total_seconds()
request.set('aged', str(age >= self.request_age_threshold)) request.set('aged', str(age >= self.request_age_threshold))
request_type = request.find('./action').get('type') request_type = request.find('./action').get('type')

View File

@ -44,7 +44,7 @@ def check(apiurl, entity, entity_type='group', comment=False, bot=None,
requests = search(apiurl, queries, request=xpath)['request'] requests = search(apiurl, queries, request=xpath)['request']
for request in requests: for request in requests:
age = request_age(request) age = request_age(request).total_seconds()
request_debug(request, age, threshold) request_debug(request, age, threshold)
if age <= threshold: if age <= threshold:
@ -77,7 +77,7 @@ def check(apiurl, entity, entity_type='group', comment=False, bot=None,
elif comment: elif comment:
kwargs['request_id'] = request.get('id') kwargs['request_id'] = request.get('id')
age = request_age(request) age = request_age(request).total_seconds()
request_debug(request, age, threshold) request_debug(request, age, threshold)
comment_age = check_comment(apiurl, bot, **kwargs) comment_age = check_comment(apiurl, bot, **kwargs)
if comment_age: if comment_age: