From 612ee1d161b730e1b612c23e3256850d83296d36 Mon Sep 17 00:00:00 2001 From: Michele Carignani Date: Tue, 12 Dec 2017 19:31:12 +0100 Subject: [PATCH] When building from a Gerrit change, comment back the review URLs Change-Id: Ibbd95f4bbfb074dfd27a57b77f1fb2538e104c9b Signed-off-by: Michele Carignani --- .gitignore | 1 + .jenkins.sh | 8 ++++-- scripts/add_change_comment.py | 24 +++++++++++++++++ scripts/jnk_grt_comment.py | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 scripts/add_change_comment.py create mode 100644 scripts/jnk_grt_comment.py diff --git a/.gitignore b/.gitignore index 567609b1..b92d6629 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +*.pyc diff --git a/.jenkins.sh b/.jenkins.sh index 6ee7861e..a933450a 100755 --- a/.jenkins.sh +++ b/.jenkins.sh @@ -8,7 +8,11 @@ run_dir="$(pwd)" cd docker -./build-container.sh -./run-container.sh "${run_dir}" +#./build-container.sh +#./run-container.sh "${run_dir}" + +cd .. + +python ./scripts/add_change_comment.py exit $? diff --git a/scripts/add_change_comment.py b/scripts/add_change_comment.py new file mode 100644 index 00000000..5dfd2b44 --- /dev/null +++ b/scripts/add_change_comment.py @@ -0,0 +1,24 @@ +""" +Add comments on gerrit +""" + +import os +import sys +import jnk_grt_comment as jgc +import glob + +CHANGE = os.environ.get('GERRIT_CHANGE_NUMBER') or None +PATCH = os.environ.get('GERRIT_PATCHSET_NUMBER') or None +URL = os.environ.get('BUILD_URL') or None + +# print glob.glob("**/*-API.yaml") + +if not (CHANGE and PATCH and URL): + print "No Gerrit change information found. Exiting" + sys.exit() + +print "START Comment on Gerrit change ---" + +jgc.comment_openapis_artifacts(CHANGE, PATCH, URL) + +print "DONE Comment on Gerrit change ---\n" diff --git a/scripts/jnk_grt_comment.py b/scripts/jnk_grt_comment.py new file mode 100644 index 00000000..021c1872 --- /dev/null +++ b/scripts/jnk_grt_comment.py @@ -0,0 +1,51 @@ +#!/env/python2.7 + +""" +Comments on gerrit +""" + +import os.path +import subprocess +import glob + +def mk_swg_ui_link(artifact, build_uri): + """ + creates the link to the swagger ui + """ + swg_ui = "https://forge.etsi.org/swagger/ui" + return swg_ui + "/?url=" + build_uri + "/artifact/"+ artifact +"/*view*/" + + +def mk_swg_ui_comment(files, bu): + """ + creates the link to the swagger ui + """ + msg = "Review links for the built OpenAPIS:" + for artifact in glob.glob(files): + msg += "\n * " + os.path.basename(artifact) + ": " + mk_swg_ui_link(artifact, bu) + return msg + +def mk_grt_comment_cmd(change, payload): + """ + creates the link to the swagger ui + """ + command = "ssh -p 29418 forge.etsi.org \"gerrit review --message '"+payload+"' "+change + "\"" + print command + return command + + +def send_gerrit_comment(change, patchset): + """ + creates the link to the swagger ui + """ + cmd = mk_grt_comment_cmd(change, patchset) + print "Executing: " + cmd + subprocess.call(cmd, shell=True) + +def jenkins_gerrit_comment(change_num, patch_num, comment): + send_gerrit_comment(change_num+","+patch_num, comment) + +def comment_openapis_artifacts(cn, pn, bu): + comment = mk_swg_ui_comment("**/*-API.yaml", bu) + # print "comment: "+comment + jenkins_gerrit_comment(str(cn), str(pn), comment) \ No newline at end of file -- GitLab