Add parameter to set a limit on the age of changes looked back at

This commit is contained in:
Ian H Pittwood 2020-02-27 17:50:58 -06:00
parent 32d3914cdd
commit 5919e03842
3 changed files with 10 additions and 3 deletions

View File

@ -47,6 +47,11 @@ def main():
)
parser.add_argument('-g', '--gerrit-url', action='store', required=True, type=str,
default=os.getenv('GERRIT_URL', default=None), help='Target Gerrit URL.')
parser.add_argument('-a', '--change-age', action='store', required=False, type=str,
default=None,
help='Specifies how far in the past to search for changes in Gerrit. '
'See https://gerrit-review.googlesource.com/Documentation/user-search.html#age for more '
'details.')
parser.add_argument('-u', '--github-user', action='store', required=False, type=str,
default=os.getenv('GITHUB_USER', default=None),
help='Username to use for GitHub Issues integration. Defaults to GITHUB_USER in '

View File

@ -21,9 +21,9 @@ LOG = logging.getLogger(__name__)
def update(gerrit_url: str, gerrit_project_name: str, github_project_name: str, github_user: str, github_password: str,
github_token: str):
github_token: str, change_age: str = None):
repo = github_issues.get_repo(github_project_name, github_user, github_password, github_token)
change_list = gerrit.get_changes(gerrit_url, gerrit_project_name)
change_list = gerrit.get_changes(gerrit_url, gerrit_project_name, change_age=change_age)
for change in change_list['data']:
if 'commitMessage' in change:
process_change(change, repo, gerrit_url)

View File

@ -14,8 +14,10 @@ import json
from fabric import Connection
def get_changes(gerrit_url: str, project_name: str, port: int = 29418) -> dict:
def get_changes(gerrit_url: str, project_name: str, port: int = 29418, change_age: str = None) -> dict:
cmd = f'gerrit query --format=JSON status:open project:{project_name}'
if change_age:
cmd += f' -- -age:{change_age}'
result = Connection(gerrit_url, port=port).run(cmd)
processed_stdout = '{"data":[%s]}' % ','.join(list(filter(None, result.stdout.split('\n'))))
data = json.loads(processed_stdout)