Allow using git tags for branch names

Now supports branch names, commit shas, and git tags. Shas must still be the full length 40-character value. Tags are a fall back on branch names. If a tag has the same name as a branch, the branch will be retrieved and not the tag
This commit is contained in:
andrew committed 2023-06-11 06:49:38 -04:00
1 parent 61b54991e8
commit a9c532f873
4 files changed
+19 -16

No files matched your search

+1 -1
View File
@@ -52,7 +52,7 @@ urlpatterns = [
django.urls.path(r'test/<int:id>/', OpenBench.views.test),
django.urls.path(r'viewTest/<int:id>/', OpenBench.views.test),
django.urls.path(r'test/<int:id>/<str:action>', OpenBench.views.test),
django.urls.path(r'newTest/', OpenBench.views.newTest),
django.urls.path(r'newTest/', OpenBench.views.create_test),
# Links for viewing and managing Networks
django.urls.path(r'networks/', OpenBench.views.networks),
+15 -9
View File
@@ -216,10 +216,9 @@ def determine_bench(request, field, message):
def collect_github_info(request, errors, field):
# Get branch name, whether it is a commit SHA, and the API path for it
# Get branch name / commit sha / tag, and the API path for it
branch = request.POST['{0}_branch'.format(field)]
bysha = bool(re.search('[0-9a-fA-F]{40}', branch))
url = 'commits' if bysha else 'branches'
# All API requests will share this common path. Some engines are private.
base = request.POST['%s_repo' % (field)].replace('github.com', 'api.github.com/repos')
@@ -257,14 +256,21 @@ def collect_github_info(request, errors, field):
## [D] If the engine is private, we will carry onto Step 3.
try: # Fetch data from the Github API
path = 'commits' if bysha else 'branches'
url = path_join(base, path, branch)
data = requests.get(url, headers=headers).json()
data = data if bysha else data['commit']
except: # Unable to connect for whatever reason
path = 'Commit Sha' if bysha else 'Branch'
errors.append('{0} {1} could not be found'.format(path, branch))
# Lookup branch or commit sha, but will fail for tags
url = path_join(base, 'commits' if bysha else 'branches', branch)
data = requests.get(url, headers=headers).json()
# Check to see if the branch name was actually a tag name
if not bysha and 'commit' not in data:
url = path_join(base, 'commits', branch)
data = requests.get(url, headers=headers).json()
# Actual branches have to go one layer deeper
elif not bysha: data = data['commit']
except: # Unable to find for whatever reason
errors.append('%s could not be found' % (branch))
return (None, None)
# Extract the bench from the web form, or from the commit message
+3 -6
View File
@@ -394,7 +394,7 @@ def test(request, id, action=None):
LogEvent.objects.create(author=request.user.username, summary=action, log_file='', test_id=test.id)
return django.http.HttpResponseRedirect('/index/')
def newTest(request):
def create_test(request):
if not request.user.is_authenticated:
return redirect(request, '/login/', error='Only enabled users can create tests')
@@ -404,14 +404,11 @@ def newTest(request):
if request.method == 'GET':
data = { 'networks' : list(Network.objects.all().values()) }
return render(request, 'newTest.html', data)
return render(request, 'create_test.html', data)
test, errors = OpenBench.utils.create_new_test(request)
if errors != [] and errors != None:
errors = ["[{0}]: {1}".format(i, e) for i, e in enumerate(errors)]
longest = max([len(e) for e in errors])
errors = ["{0}{1}".format(e, ' ' * (longest-len(e))) for e in errors]
return render(request, 'newTest.html', {'error_message': '\n'.join(errors)})
return redirect(request, '/newTest/', error='\n'.join(errors))
username = request.user.username
profile = Profile.objects.get(user=request.user)
File renamed without changes.