Commit de4722d7 authored by hardy's avatar hardy

workout a more readable and compact test results note

parent 67874060
...@@ -509,18 +509,52 @@ class Dashboard: ...@@ -509,18 +509,52 @@ class Dashboard:
s3.meta.client.copy(copy_source, 'oaitestdashboard', path+'/'+ 'test_styles.css') s3.meta.client.copy(copy_source, 'oaitestdashboard', path+'/'+ 'test_styles.css')
def PostGitNote(self,mr,jobname,buildurl,buildid,status): def PostGitNote(self,mr,commit, jobname,buildurl,buildid,status):
#current date and time to be posted with test reulst
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M")
gl = gitlab.Gitlab.from_config('OAI') gl = gitlab.Gitlab.from_config('OAI')
project_id = 223 project_id = 223
project = gl.projects.get(project_id) project = gl.projects.get(project_id)
#retrieve all the notes from the MR
editable_mr = project.mergerequests.get(int(mr)) editable_mr = project.mergerequests.get(int(mr))
mr_notes = editable_mr.notes.list() mr_notes = editable_mr.notes.list(all=True)
mr_note = editable_mr.notes.create({
'body': 'Completed Test : '+jobname+', status: <b>'+status+'</b>, '+\ #find key word in notes to find out if such a note has already been posted
'(<a href="'+buildurl+'">'+buildid+'</a>)<br>'+\ n=0
'<a href="https://oaitestdashboard.s3.eu-west-1.amazonaws.com/MR'+mr+'/index.html">Consolidated Test Results</a>' found=False
}) while found==False and n<len(mr_notes):
editable_mr.save() res=re.search('Consolidated Test Results',mr_notes[n].body)#this is the marker we are looking for in all notes
if res!=None:
found=True
n+=1
if found==False:
#create new note
mr_note = editable_mr.notes.create({
'body': '<a href="https://oaitestdashboard.s3.eu-west-1.amazonaws.com/MR'+mr+'/index.html">Consolidated Test Results</a><br>'+\
dt_string + ' ' + commit + ': '+jobname+', status is <b>'+status+'</b>, '+\
'(<a href="'+buildurl+'">'+buildid+'</a>)<br>'
})
editable_mr.save()
else:
#retrieve current note : due to post incr in the parsing loop, need to check note n-1
cur_body = mr_notes[n-1].body
append_body = dt_string + ' ' + commit + ': '+jobname+', status is <b>'+status+'</b>, '+\
'(<a href="'+buildurl+'">'+buildid+'</a>)<br>'
new_body = cur_body + append_body
#create a new note at the bottom
mr_note = editable_mr.notes.create({
'body': new_body
})
editable_mr.save()
#delete current note
mr_notes[n-1].delete()
editable_mr.save()
def main(): def main():
...@@ -535,13 +569,14 @@ def main(): ...@@ -535,13 +569,14 @@ def main():
buildurl=sys.argv[4] buildurl=sys.argv[4]
buildid=sys.argv[5] buildid=sys.argv[5]
status=sys.argv[6] status=sys.argv[6]
commit=sys.argv[7]
htmlDash=Dashboard() htmlDash=Dashboard()
if mr in htmlDash.mr_list: if mr in htmlDash.mr_list:
htmlDash.Build('singleMR',mr,'/tmp/MR'+mr+'_index.html') htmlDash.Build('singleMR',mr,'/tmp/MR'+mr+'_index.html')
htmlDash.CopyToS3('/tmp/MR'+mr+'_index.html','oaitestdashboard','MR'+mr+'/index.html') htmlDash.CopyToS3('/tmp/MR'+mr+'_index.html','oaitestdashboard','MR'+mr+'/index.html')
htmlDash.Build('Tests','0000','/tmp/Tests_index.html') htmlDash.Build('Tests','0000','/tmp/Tests_index.html')
htmlDash.CopyToS3('/tmp/Tests_index.html','oaitestdashboard','index.html') htmlDash.CopyToS3('/tmp/Tests_index.html','oaitestdashboard','index.html')
htmlDash.PostGitNote(mr,jobname,buildurl,buildid,status) htmlDash.PostGitNote(mr,commit,jobname,buildurl,buildid,status)
else: else:
print("Not a Merge Request => this build is for testing/debug purpose, no report to git") print("Not a Merge Request => this build is for testing/debug purpose, no report to git")
#test and MR status dash boards, cron based #test and MR status dash boards, cron based
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment