From 33eed3cedbe29b63f58c7fb2586225a8b9d17f74 Mon Sep 17 00:00:00 2001 From: James Pace Date: Wed, 15 Feb 2023 20:10:43 -0500 Subject: [PATCH] Move some code around. Send the hash instead of the ref. --- j7s_branch_trigger/j7s_branch_trigger.py | 25 ++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/j7s_branch_trigger/j7s_branch_trigger.py b/j7s_branch_trigger/j7s_branch_trigger.py index ca56786..728b1fd 100644 --- a/j7s_branch_trigger/j7s_branch_trigger.py +++ b/j7s_branch_trigger/j7s_branch_trigger.py @@ -29,11 +29,23 @@ def main(): def job(): loop(repo, pattern, url, data_file) schedule.every(loop_time).minutes.do(job) + logging.debug('Doing initial run.') + schedule.run_all() logging.debug('Starting loop.') while True: schedule.run_pending() time.sleep(1) +def loop(repo, pattern, request_url, data_file): + logging.debug('Looking at {} for {}.'.format(repo, pattern)) + all_branches = git_ls(repo) + logging.debug('All branches: {}'.format(all_branches)) + concerned_branches = find_concerned_branches(all_branches, pattern) + logging.debug('Concerned branches for {}: {}'.format(pattern, concerned_branches)) + last_time = load_last_time(data_file) + compare_branches(last_time, concerned_branches, request_url) + save_this_time(data_file, concerned_branches) + def git_ls(repo): cmd = 'git ls-remote {repo}'.format(repo=repo) output = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE) @@ -76,20 +88,10 @@ def compare_branches(last_time, this_time, url): last_hash = last_time.get(branch, None) if my_hash != last_hash: logging.debug('Branch {} has new hash.'.format(branch)) - r = requests.post(url, json={"branch": branch}) + r = requests.post(url, json={"hash": my_hash}) if r.status_code != 200: logging.warning("Something went wrong on request.") -def loop(repo, pattern, request_url, data_file): - logging.debug('Looking at {} for {}.'.format(repo, pattern)) - all_branches = git_ls(repo) - logging.debug('All branches: {}'.format(all_branches)) - concerned_branches = find_concerned_branches(all_branches, pattern) - logging.debug('Concerned branches for {}: {}'.format(pattern, concerned_branches)) - last_time = load_last_time(data_file) - compare_branches(last_time, concerned_branches, request_url) - save_this_time(data_file, concerned_branches) - def get_config(): repo = os.environ.get('J7S_REPO', None) url = os.environ.get('J7S_URL', None) @@ -100,4 +102,3 @@ def get_config(): loop_time = float(os.environ.get('J7S_LOOPTIME', 1.0)) return (repo, url, data_file, pattern, loop_time) -