Browse Source

Import dist plugin in gitea

master
cam.lafit 4 years ago
parent
commit
c0f8042966
  1. 101
      ImportOneRepository.sh
  2. 2
      ImportToGitea.conf.sample
  3. 11
      models/dist.conf

101
ImportOneRepository.sh

@ -0,0 +1,101 @@
#!/usr/bin/env bash
# Manage arguments
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-r|--repository)
REPOSITORY="$2"
shift # past argument
shift # past value
;;
-o|--organization)
ORGANIZATION="$2"
shift # past argument
shift # past value
;;
-m|--model)
MODEL="$2"
shift # past argument
shift # past value
;;
-h|--help)
shift # past argument
echo "ImportOneRepository, a command line interface to import a svn repository to gitea"
echo " -r <repository> or --repository <reposoitoy> \t\t specify the svn repository name to import"
echo " -o <organization> or --orgnanization <organization> \t gitea organization where to import repository."
echo " -m <model> or --model <model> \t\t specify the model svn structure to respesct (dist or zone)"
exit 0
;;
-*) # unknown option
cli_output "Invalid option: ${1}. Type --help to show help" red notime
shift
exit 0
;;
--*) # unknown option
cli_output "Invalid option: ${1}. Type --help to show help" red notime
shift
exit 0
;;
*) # unknown option
FILES+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${FILES[@]}" # restore positional parameters
#Control requirement configuration
if [ ! -f ImportToGitea.conf ]; then
echo "Gitea configuration not set, can't continue"
exit 0
fi
. ImportToGitea.conf
#Control model
if [ ! -f /models/${MODEL} ]; then
echo "Model is not set, can't continue"
exit 0
fi
if [ -z ${ORGANIZATION} ]; then
echo "Organization missing, can't continue"
exit 0
fi
if [ -z ${REPOSITORY} ]; then
echo "repository missing, can't continue"
exit 0
fi
echo "$REPOSITORY will be import from svn following $MODEL to $ORGANIZATION"
#Import svn to git
repo_source=$TMP_SUBGIT_DIR/$REPOSITORY
#Restore subgit configuration
repo_target=$GITEA_REPO/$ORGANIZATION/$REPOSITORY.git
#LowerCase
repo_target=${repo_target,,}
mkdir -p $repo_source
subgit configure --svn-url svn://svn.tld $repo_source
cp models/dist.conf $repo_source/subgit/config
sed -i 's/__PLUGIN__/$REPOSITORY/' $repo_source/subgit/config
rename 's/(hooks\/)(.*).d$/$1user-$2.d/' hooks/*
subgit install . $repo_source
subgit uninstall . $repo_source
#Create Gitea repository
curl -H "Authorization: token $GITEA_TOKEN" \
--data "clone_addr=$repo_source&uid=$GITEA_ORGA_ID&repo_name=$REPOSITORY" \
$GITEA_HOST:$GITEA_PORT/api/v1/repos/migrate
#Restore subgit configuration
cp -bar $repo_source/{subgit,svn,db,logs} $repo_target/
subgit install . $repo_target
chown $GIT_UID:$GIT_GID -R $repo_target

2
ImportToGitea.conf.sample

@ -3,6 +3,8 @@ GITEA_REPO=
GITEA_ORGA=
GITEA_ORGA_ID=
TMP_SUBGIT_DIR=
GITEA_TOKEN=
GITEA_HOST=
GITEA_PORT=

11
models/dist.conf

@ -0,0 +1,11 @@
[svn]
# Subversion repository URL
url = svn://svn.spip.net/spip-zone/_core_
trunk = plugins/PLUGIN:refs/heads/master
branches = branches/*/plugins/__PLUGIN__:refs/heads/*
tags = tags/*/plugins/__PLUGIN__:refs/tags/*
shelves = shelves/*/__PLUGIN__:refs/shelves/*
[config]
include = /var/git/subgit/config/dist.conf
Loading…
Cancel
Save