Skip to content
Snippets Groups Projects
Commit bada623d authored by Viktor Vorobev's avatar Viktor Vorobev Committed by Ugo Albanese
Browse files

Merged in NRRPLT-8128-test-coverage-update-py3.8 (pull request #26)

[NRRPLT-8128] Test coverage update Python 3.8

* [NRRPLT-8127] make reports with function
* [NRRPLT-8127] setup manual coverage line
* [NRRPLT-0000] docstrings and pylint fix for ci directory download python script

Approved-by: Vahid Zolfaghari
Approved-by: Krzysztof Lebioda
parent dbfa1352
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
"""
CI script for checkout of a single directory from a specified repo ref HEAD
This script uses BitBucket API, so the repo is supposed to be in BitBucket cloud
"""
import os import os
import sys import sys
from urllib.parse import urlparse from urllib.parse import urlparse
...@@ -6,18 +11,26 @@ import urllib.request ...@@ -6,18 +11,26 @@ import urllib.request
try: try:
import json import json
except: except ImportError:
import simplejson as json import simplejson as json
def open_directory(API_PATH, username, repo, slug, path): def open_directory(api_path_, user_name_, repository_, slug_, path_):
directory_url = "%s/%s/%s/src/%s/%s" % (API_PATH, username, repo, slug, path) """
open_directory opens directory and recursevely downloads its content throug BitBucket API
:param api_path_: path to BitBucket API core (https://api.bitbucket.org/2.0/repositories)
:param user_name_: BitBucket username (hbpneurorobotics)
:param repository_: the desired repo to download (i.e. CLE)
:param slug_: the desired ref (branch/tag/hash)
:param path_: the path to the directory inside repository
"""
directory_url = "%s/%s/%s/src/%s/%s" % (api_path_, user_name_, repository_, slug_, path_)
print(directory_url) print(directory_url)
json_data_url_handle = urllib.request.urlopen(directory_url) json_data_url_handle = urllib.request.urlopen(directory_url)
if json_data_url_handle.code != 200: if json_data_url_handle.code != 200:
print("url %s not found" % directory_url) print("url %s not found" % directory_url)
exit() sys.exit()
json_directory = json.loads(json_data_url_handle.read()) json_directory = json.loads(json_data_url_handle.read())
page_exists = True page_exists = True
...@@ -26,35 +39,38 @@ def open_directory(API_PATH, username, repo, slug, path): ...@@ -26,35 +39,38 @@ def open_directory(API_PATH, username, repo, slug, path):
for item in json_directory["values"]: for item in json_directory["values"]:
print(json.dumps(item, indent=4)) print(json.dumps(item, indent=4))
if item["type"] == "commit_directory": if item["type"] == "commit_directory":
open_directory(API_PATH, username, repo, slug, item["path"]) open_directory(api_path_, user_name_, repository_, slug_, item["path"])
for file in json_directory["values"]: for file_ in json_directory["values"]:
if file["type"] == "commit_file" and file["mimetype"] == "text/xml": if file_["type"] == "commit_file" and file_["mimetype"] == "text/xml":
try: try:
os.makedirs(os.path.dirname(file["path"])) os.makedirs(os.path.dirname(file_["path"]))
except OSError: except OSError:
None pass
print("downloading %s" % file["path"]) print("downloading %s" % file_["path"])
print(file['links']['self']['href']) print(file_['links']['self']['href'])
urllib.request.urlretrieve(file['links']['self']['href'], file['path']) urllib.request.urlretrieve(file_['links']['self']['href'], file_['path'])
if "next" in json_directory: if "next" in json_directory:
json_data_url_handle = urllib.request.urlopen(json_directory['next']) json_data_url_handle = urllib.request.urlopen(json_directory['next'])
if json_data_url_handle.code != 200: if json_data_url_handle.code != 200:
print("url %s not found" % directory_url) print("url %s not found" % directory_url)
exit() sys.exit()
json_directory = json.loads(json_data_url_handle.read()) json_directory = json.loads(json_data_url_handle.read())
else: else:
page_exists = False page_exists = False
if ( if (
len(sys.argv) != 2 or len(sys.argv) != 2 or
sys.argv[1].find("https://bitbucket.org/") != 0 or sys.argv[1].find("https://bitbucket.org/") != 0 or
sys.argv[1].find("/src/") == -1 sys.argv[1].find("/src/") == -1
): ):
print("usage: python download_directory.py.py https://bitbucket.org/ws/repo/src/branch/demo/") print("usage: python download_directory.py.py https://bitbucket.org/ws/repo/src/branch/demo/")
exit() sys.exit()
API_PATH = "https://api.bitbucket.org/2.0/repositories" API_PATH = "https://api.bitbucket.org/2.0/repositories"
null, username, repo, null, slug, path = urlparse(sys.argv[1]).path.split("/", 5) _, username, repo, _, slug, path_section = urlparse(sys.argv[1]).path.split("/", 5)
print(username, repo, slug, path)
open_directory(API_PATH, username, repo, slug, path) print(username, repo, slug, path_section)
open_directory(API_PATH, username, repo, slug, path_section)
...@@ -29,8 +29,7 @@ pipeline { ...@@ -29,8 +29,7 @@ pipeline {
TOPIC_BRANCH = selectTopicBranch(env.BRANCH_NAME, env.CHANGE_BRANCH) TOPIC_BRANCH = selectTopicBranch(env.BRANCH_NAME, env.CHANGE_BRANCH)
DEFAULT_BRANCH = 'development' DEFAULT_BRANCH = 'development'
NRP_COVERAGE_BRANCH=0 CODE_COVERAGE_LINE = 29
NRP_COVERAGE_LINE=23
} }
agent { agent {
docker { docker {
...@@ -106,18 +105,7 @@ pipeline { ...@@ -106,18 +105,7 @@ pipeline {
sh 'sudo -H -u bbpnrsoa bash .ci/build.bash' sh 'sudo -H -u bbpnrsoa bash .ci/build.bash'
// deliver artifacts // deliver artifacts
step([$class: 'CoberturaPublisher', makeReports(false, env.CODE_COVERAGE_LINE)
autoUpdateHealth: true,
autoUpdateStability: false,
coberturaReportFile: 'coverage.xml',
failUnhealthy: true,
failUnstable: false,
maxNumberOfBuilds: 0,
onlyStable: false,
sourceEncoding: 'ASCII',
zoomCoverageChart: false,
lineCoverageTargets: "0.0, 0, 0"])
archiveArtifacts 'coverage.xml'
} }
} }
} }
...@@ -128,8 +116,7 @@ pipeline { ...@@ -128,8 +116,7 @@ pipeline {
dir(env.GIT_CHECKOUT_DIR){ dir(env.GIT_CHECKOUT_DIR){
archiveArtifacts 'p*.*' archiveArtifacts 'p*.*'
archiveArtifacts 'test-reports/*.*' archiveArtifacts 'test-reports/*.*'
junit 'test-reports/*.xml' archiveArtifacts 'coverage.xml'
recordIssues enabledForFailure: true, tools: [pyLint(pattern: 'pylint.txt'), pep8(pattern: 'pycodestyle.txt')], qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]]
} }
} }
aborted { aborted {
......
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