osclib/origin: provide origin_revision_state().
This commit is contained in:
parent
860fcd0a60
commit
f6b9a9dd87
@ -480,3 +480,31 @@ def policy_input_evaluate_reviews_not_allowed(policy, inputs):
|
||||
reviews_not_allowed.append(review_remaining)
|
||||
|
||||
return reviews_not_allowed
|
||||
|
||||
def origin_revision_state(apiurl, target_project, package, origin_info=None, limit=10):
|
||||
if not origin_info:
|
||||
origin_info = origin_find(apiurl, target_project, package)
|
||||
|
||||
revisions = []
|
||||
|
||||
# Allow for origin project to contain revisions not present in target by
|
||||
# considering double the limit of revisions. The goal is to know how many
|
||||
# revisions behind the package in target project is and if it deviated from
|
||||
# origin, not that it ended up with every revision found in origin project.
|
||||
origin_project = origin_info.project.rstrip('~')
|
||||
origin_hashes = list(package_source_hash_history(apiurl, origin_project, package, limit * 2, True))
|
||||
target_hashes = list(package_source_hash_history(apiurl, target_project, package, limit))
|
||||
for source_hash in origin_hashes:
|
||||
if source_hash not in target_hashes:
|
||||
revisions.append(-1)
|
||||
else:
|
||||
break
|
||||
|
||||
for source_hash in target_hashes:
|
||||
if len(revisions) == limit:
|
||||
break
|
||||
|
||||
revisions.append(int(source_hash in origin_hashes))
|
||||
|
||||
# To simplify usage which is left-right (oldest-newest) place oldest first.
|
||||
return list(reversed(revisions))
|
||||
|
Loading…
x
Reference in New Issue
Block a user