From 6b1f906c6758a02e8eec7a27fa3640cebdf78796 Mon Sep 17 00:00:00 2001 From: Filippo Ledda Date: Tue, 9 Jan 2024 19:06:28 +0100 Subject: [PATCH] #874 from svn to git --- .../osbrepository/adapters/githubadapter.py | 17 +++++++++-------- .../server/workspaces/service/workflow.py | 7 ++++++- .../workspaces/tasks/github-copy/Dockerfile | 2 +- .../workspaces/tasks/github-copy/README.md | 11 +++++++++++ .../workspaces/tasks/github-copy/run.sh | 9 ++++++++- 5 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 applications/workspaces/tasks/github-copy/README.md diff --git a/applications/workspaces/server/workspaces/service/osbrepository/adapters/githubadapter.py b/applications/workspaces/server/workspaces/service/osbrepository/adapters/githubadapter.py index 242a2d2b..64a29182 100644 --- a/applications/workspaces/server/workspaces/service/osbrepository/adapters/githubadapter.py +++ b/applications/workspaces/server/workspaces/service/osbrepository/adapters/githubadapter.py @@ -124,24 +124,25 @@ def get_tags(self, context=None): """Topics/keywords""" tags = self.get_json(self.api_url + "topics") return tags["names"] - + def create_copy_task(self, workspace_id, name, path): # download the resource import workspaces.service.workflow as workflow name = name if name != "/" else self.osbrepository.name - folder = self.osbrepository.name + \ - path.replace(self.uri, "").replace("branches/", "/").replace("tags/", "/") + relative_path = path.replace(self.uri, "").\ + replace(self.uri, "").replace("branches/", "/").replace("tags/", "/").replace("//", "/") + folder = self.osbrepository.name + relative_path + folder = folder[: folder.rfind("/")] - # username / password are optional and future usage, - # e.g. for accessing non public repos + return workflow.create_copy_task( image_name="workspaces-github-copy", workspace_id=workspace_id, name=name, folder=folder, - path=path, - username="", - password="", + url=self.uri, + path=relative_path.split(self.osbrepository.default_context)[1][1:], + branch=self.osbrepository.default_context, ) diff --git a/applications/workspaces/server/workspaces/service/workflow.py b/applications/workspaces/server/workspaces/service/workflow.py index 0064c925..73ee7ddc 100644 --- a/applications/workspaces/server/workspaces/service/workflow.py +++ b/applications/workspaces/server/workspaces/service/workflow.py @@ -74,7 +74,12 @@ def create_task(image_name, workspace_id, **kwargs): def create_copy_task(workspace_id, name, folder, path, image_name="workflows-extract-download", **kwargs): name = name if name else path[path.rfind("/") + 1:] - return create_task(image_name=image_name, workspace_id=workspace_id, folder=folder or '', url=path, **kwargs) + return create_task( + image_name=image_name, + workspace_id=workspace_id, + folder=folder or '', + path=path, + **kwargs) def create_scan_task(workspace_id, **kwargs): diff --git a/applications/workspaces/tasks/github-copy/Dockerfile b/applications/workspaces/tasks/github-copy/Dockerfile index 89fdeaa3..c4edc4f0 100644 --- a/applications/workspaces/tasks/github-copy/Dockerfile +++ b/applications/workspaces/tasks/github-copy/Dockerfile @@ -1,7 +1,7 @@ ARG CLOUDHARNESS_BASE FROM $CLOUDHARNESS_BASE -RUN apk add subversion +RUN apk add git ADD . / diff --git a/applications/workspaces/tasks/github-copy/README.md b/applications/workspaces/tasks/github-copy/README.md new file mode 100644 index 00000000..d20d22c0 --- /dev/null +++ b/applications/workspaces/tasks/github-copy/README.md @@ -0,0 +1,11 @@ +# Github copy task + + +How to test + +``` +shared_directory=/tmp folder=osbv2/develop url=https://github.com/OpenSourceBrain/OSBv2 branch=develop path=applications/workspaces ./run.sh + +shared_directory=/tmp folder=osbv2/develop url=https://github.com/OpenSourceBrain/OSBv2 branch=develop path=README.md ./run.sh +``` + diff --git a/applications/workspaces/tasks/github-copy/run.sh b/applications/workspaces/tasks/github-copy/run.sh index af79e353..458489d5 100644 --- a/applications/workspaces/tasks/github-copy/run.sh +++ b/applications/workspaces/tasks/github-copy/run.sh @@ -12,7 +12,14 @@ cd "${download_path}" export filename=`echo "${url##*/}"` echo GitHub copy "$filename" to "$download_path" -svn export --username "${username}" --password "${password}" --force "${url}" "${download_path}"/"${filename}" +# do the next command only if download path does not exist +if [ ! -d "${filename}" ]; then + git clone -n "${url}" --branch $branch "${filename}" +fi + +cd "${download_path}"/"${filename}" + +git checkout HEAD "${path}" # fix permissions chown -R 1000:1000 "${download_path}"