Skip to content

Commit

Permalink
#874 from svn to git
Browse files Browse the repository at this point in the history
  • Loading branch information
filippomc committed Jan 9, 2024
1 parent dd54089 commit 6b1f906
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion applications/workspaces/tasks/github-copy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG CLOUDHARNESS_BASE
FROM $CLOUDHARNESS_BASE

RUN apk add subversion
RUN apk add git

ADD . /

Expand Down
11 changes: 11 additions & 0 deletions applications/workspaces/tasks/github-copy/README.md
Original file line number Diff line number Diff line change
@@ -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
```

9 changes: 8 additions & 1 deletion applications/workspaces/tasks/github-copy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

0 comments on commit 6b1f906

Please sign in to comment.