From cdcb3e4fb01d50945abebf6c8ba5e161ca5a11bb Mon Sep 17 00:00:00 2001 From: James Pace Date: Wed, 3 Jan 2024 23:05:13 -0500 Subject: [PATCH] Minor modifications to make play nicer with the limbo trigger. --- j7s_branch_trigger/j7s_branch_trigger.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/j7s_branch_trigger/j7s_branch_trigger.py b/j7s_branch_trigger/j7s_branch_trigger.py index be6407e..9025a26 100644 --- a/j7s_branch_trigger/j7s_branch_trigger.py +++ b/j7s_branch_trigger/j7s_branch_trigger.py @@ -25,9 +25,9 @@ import logging def main(): logging.basicConfig(level=logging.DEBUG) logging.debug('Starting up....') - (repo, url, data_file, pattern, loop_time) = get_config() + (repo, url, data_file, pattern, loop_time, repo_name) = get_config() def job(): - loop(repo, pattern, url, data_file) + loop(repo, pattern, url, data_file, repo_name) schedule.every(loop_time).minutes.do(job) logging.debug('Doing initial run.') schedule.run_all() @@ -36,14 +36,14 @@ def main(): schedule.run_pending() time.sleep(1) -def loop(repo, pattern, request_url, data_file): +def loop(repo, pattern, request_url, data_file, repo_name): 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) + compare_branches(last_time, concerned_branches, request_url, repo_name) save_this_time(data_file, concerned_branches) def git_ls(repo): @@ -82,13 +82,13 @@ def save_this_time(file_name, this_time): with open(file_name, 'w') as f: json.dump(this_time, f) -def compare_branches(last_time, this_time, url): +def compare_branches(last_time, this_time, url, repo_name): for branch in this_time.keys(): my_hash = this_time[branch] 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={"hash": my_hash}) + r = requests.post(url, json={"sha": my_hash, "repo_name": repo_name}) if r.status_code == 200 or r.status_code == 202: logging.debug("Request ok!") else: @@ -99,8 +99,10 @@ def get_config(): url = os.environ.get('J7S_URL', None) if not url or not repo: raise Exception('Missing J7S_REPO OR J7S_URL.') + # the part right before .git in gitea clone url + repo_name = os.environ.get('J7S_REPO_NAME', "") data_file = os.environ.get('J7S_HISTORY_FILE', '/tmp/branch-history.json') pattern = os.environ.get('J7S_PATTERN', '^HEAD$') loop_time = float(os.environ.get('J7S_LOOPTIME', 1.0)) - return (repo, url, data_file, pattern, loop_time) + return (repo, url, data_file, pattern, loop_time, repo_name)