Move some code around. Send the hash instead of the ref.
This commit is contained in:
parent
fc4c02a019
commit
33eed3cedb
|
|
@ -29,11 +29,23 @@ def main():
|
||||||
def job():
|
def job():
|
||||||
loop(repo, pattern, url, data_file)
|
loop(repo, pattern, url, data_file)
|
||||||
schedule.every(loop_time).minutes.do(job)
|
schedule.every(loop_time).minutes.do(job)
|
||||||
|
logging.debug('Doing initial run.')
|
||||||
|
schedule.run_all()
|
||||||
logging.debug('Starting loop.')
|
logging.debug('Starting loop.')
|
||||||
while True:
|
while True:
|
||||||
schedule.run_pending()
|
schedule.run_pending()
|
||||||
time.sleep(1)
|
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):
|
def git_ls(repo):
|
||||||
cmd = 'git ls-remote {repo}'.format(repo=repo)
|
cmd = 'git ls-remote {repo}'.format(repo=repo)
|
||||||
output = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE)
|
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)
|
last_hash = last_time.get(branch, None)
|
||||||
if my_hash != last_hash:
|
if my_hash != last_hash:
|
||||||
logging.debug('Branch {} has new hash.'.format(branch))
|
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:
|
if r.status_code != 200:
|
||||||
logging.warning("Something went wrong on request.")
|
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():
|
def get_config():
|
||||||
repo = os.environ.get('J7S_REPO', None)
|
repo = os.environ.get('J7S_REPO', None)
|
||||||
url = os.environ.get('J7S_URL', 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))
|
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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue