diff --git a/OpenBench/static/style.css b/OpenBench/static/style.css index 1141a76..3ff65db 100644 --- a/OpenBench/static/style.css +++ b/OpenBench/static/style.css @@ -333,6 +333,10 @@ td pre { color: red; } +#content .warning-message { + color: yellow; +} + #content .status-message { color: green; } diff --git a/OpenBench/utils.py b/OpenBench/utils.py index a9e7a7c..926039d 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -215,6 +215,30 @@ def getEngine(source, name, sha, bench): return Engine.objects.create(name=name, source=source, sha=sha, bench=bench) + +def branch_is_out_of_date(test): + + # Cannot compare across engines + if test.dev_engine != test.base_engine: + return False + + # Format the request to the Github endpoint + base = 'https://api.github.com/repos/' + base = test.dev_repo.replace('github.com', 'api.github.com/repos') + url = path_join(base, 'compare', '%s...%s' % (test.dev.sha, test.base.sha)) + + try: + # Out of date if ahead_by is non-zero + headers = read_git_credentials(test.dev_engine) + data = requests.get(url, headers=headers).json() + return data.get('ahead_by', 0) > 0 + + except: + # If something went wrong, just ignore it + import traceback + traceback.print_exc() + return False + def read_git_credentials(engine): fname = 'credentials.%s' % (engine.replace(' ', '').lower()) if os.path.exists(fname): diff --git a/OpenBench/views.py b/OpenBench/views.py index 4d454ed..8f7a8f8 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -46,7 +46,7 @@ from django.core.files.base import ContentFile class UnableToAuthenticate(Exception): pass -def render(request, template, content={}, always_allow=False, error=None, status=None): +def render(request, template, content={}, always_allow=False, error=None, warning=None, status=None): data = content.copy() data.update({ 'config' : OPENBENCH_CONFIG }) @@ -69,21 +69,27 @@ def render(request, template, content={}, always_allow=False, error=None, status if error: request.session['error_message'] = error + if warning: + request.session['warning_message'] = error + if status: request.session['status_message'] = status response = django.shortcuts.render(request, 'OpenBench/{0}'.format(template), data) - for key in ['status_message', 'error_message']: + for key in ['status_message', 'warning_message', 'error_message']: if key in request.session: del request.session[key] return response -def redirect(request, destination, error=None, status=None): +def redirect(request, destination, error=None, warning=None, status=None): if error: request.session['error_message'] = error + if warning: + request.session['warning_message'] = warning + if status: request.session['status_message'] = status @@ -481,6 +487,9 @@ def create_test(request): if errors != [] and errors != None: return redirect(request, '/newTest/', error='\n'.join(errors)) + if warning := OpenBench.utils.branch_is_out_of_date(test): + warning = 'Consider Rebasing: Dev (%s) appears behind Base (%s)' % (test.dev.name, test.base.name) + username = request.user.username profile = Profile.objects.get(user=request.user) LogEvent.objects.create(author=username, summary='CREATE', log_file='', test_id=test.id) @@ -501,7 +510,7 @@ def create_test(request): action = "APPROVE P={0} TP={1}".format(test.priority, test.throughput) LogEvent.objects.create(author=username, summary=action, log_file='', test_id=test.id) - return django.http.HttpResponseRedirect('/index/') + return redirect(request, '/index/', warning=warning) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # diff --git a/Templates/OpenBench/base.html b/Templates/OpenBench/base.html index f4dff8b..cbea106 100644 --- a/Templates/OpenBench/base.html +++ b/Templates/OpenBench/base.html @@ -117,6 +117,12 @@ {% endif %} + {% if request.session.warning_message %} +
+
{{request.session.warning_message}}
+
+ {% endif %} + {% if request.session.status_message %}
{{request.session.status_message}}