Check for existing project
This commit is contained in:
parent
447c5706d2
commit
e5a2ce913e
3 changed files with 18 additions and 21 deletions
13
defaults
13
defaults
|
@ -1,13 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
export AUTHOR="Antonio J. Delgado"
|
|
||||||
export AUTHORING_DATE=$(date +%Y)
|
|
||||||
export PROJECT_NAME="Project Name"
|
|
||||||
export PROJECT_CODENAME="project-codename"
|
|
||||||
export VERSION=0.0.1
|
|
||||||
export DEPLOYMENT_PATH="${HOME}/src/"
|
|
||||||
export DESCRIPTION=""
|
|
||||||
export AUTHOR_EMAIL=""
|
|
||||||
export URL=""
|
|
||||||
export LICENSE="GPLv3"
|
|
||||||
export LICENSE_URL="https://www.gnu.org/licenses/gpl-3.0.txt"
|
|
|
@ -1,6 +1,6 @@
|
||||||
AUTHOR="Foo Bar"
|
AUTHOR="Foo Bar"
|
||||||
AUTHOR_EMAIL="${USER}@$(hostname -f)"
|
AUTHOR_EMAIL="${USER}@$(hostname -f)"
|
||||||
VERSION='0.1'
|
VERSION='0.0.1'
|
||||||
DEPLOYMENT_PATH="${HOME}/src"
|
DEPLOYMENT_PATH="${HOME}/src"
|
||||||
LICENSE='GPLv3'
|
LICENSE='GPLv3'
|
||||||
LICENSE_URL='https://www.gnu.org/licenses/gpl-3.0.txt'
|
LICENSE_URL='https://www.gnu.org/licenses/gpl-3.0.txt'
|
||||||
|
|
|
@ -30,6 +30,7 @@ function usage() {
|
||||||
AUTHOR_EMAIL="${USER}@$(hostname -f)"
|
AUTHOR_EMAIL="${USER}@$(hostname -f)"
|
||||||
FORGEJO_INSTANCE=''
|
FORGEJO_INSTANCE=''
|
||||||
FORGEJO_TOKEN=''
|
FORGEJO_TOKEN=''
|
||||||
|
|
||||||
if [ -r "${HOME}/.config/deploy_new_python_project.conf" ]; then
|
if [ -r "${HOME}/.config/deploy_new_python_project.conf" ]; then
|
||||||
perms=$(stat -c %a "${HOME}/.config/deploy_new_python_project.conf")
|
perms=$(stat -c %a "${HOME}/.config/deploy_new_python_project.conf")
|
||||||
if [ "${perms:1:2}" != "00" ]; then
|
if [ "${perms:1:2}" != "00" ]; then
|
||||||
|
@ -40,11 +41,6 @@ if [ -r "${HOME}/.config/deploy_new_python_project.conf" ]; then
|
||||||
source "${HOME}/.config/deploy_new_python_project.conf"
|
source "${HOME}/.config/deploy_new_python_project.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e "$(dirname "${0}")/defaults" ]
|
|
||||||
then
|
|
||||||
# shellcheck disable=SC1091
|
|
||||||
source "$(dirname "${0}")/defaults"
|
|
||||||
fi
|
|
||||||
while [ $# -gt 0 ]
|
while [ $# -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -156,6 +152,20 @@ mv "${destination_path}/${PROJECT_CODENAME}/project_codename.py" "${destination_
|
||||||
mv "${destination_path}/project_codename.sh" "${destination_path}/${PROJECT_CODENAME}.sh"
|
mv "${destination_path}/project_codename.sh" "${destination_path}/${PROJECT_CODENAME}.sh"
|
||||||
|
|
||||||
if [ -n "${FORGEJO_INSTANCE}" ]; then
|
if [ -n "${FORGEJO_INSTANCE}" ]; then
|
||||||
|
forgejo_username=$(curl -s "${FORGEJO_INSTANCE}/api/v1/user" \
|
||||||
|
-H "Authorization: Bearer ${FORGEJO_TOKEN}" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-X GET | jq '.username' | sed 's/"//g')
|
||||||
|
repo_url=$(curl -s "${FORGEJO_INSTANCE}/api/v1/repos/${forgejo_username}/${PROJECT_CODENAME}" \
|
||||||
|
-H "Authorization: Bearer ${FORGEJO_TOKEN}" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-X GET | jq '.html_url' | sed 's/"//g')
|
||||||
|
if [ "${repo_url}" != "null" ]; then
|
||||||
|
echo "Error! There is a repo with URL '${repo_url}' with the same project code name"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
data="{ \"default_branch\": \"main\", \"description\": \"${DESCRIPTION}\", \"name\": \"${PROJECT_CODENAME}\", \"private\": true}"
|
data="{ \"default_branch\": \"main\", \"description\": \"${DESCRIPTION}\", \"name\": \"${PROJECT_CODENAME}\", \"private\": true}"
|
||||||
repo_response=$(curl -s "${FORGEJO_INSTANCE}/api/v1/user/repos" \
|
repo_response=$(curl -s "${FORGEJO_INSTANCE}/api/v1/user/repos" \
|
||||||
-H "Authorization: Bearer ${FORGEJO_TOKEN}" \
|
-H "Authorization: Bearer ${FORGEJO_TOKEN}" \
|
||||||
|
@ -163,9 +173,9 @@ if [ -n "${FORGEJO_INSTANCE}" ]; then
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-X POST \
|
-X POST \
|
||||||
-d "${data}")
|
-d "${data}")
|
||||||
git_url=$(echo "${repo_response}" | jq '.ssh_url')
|
git_url=$(echo "${repo_response}" | jq '.ssh_url' | sed 's/"//g')
|
||||||
if [ -z "${URL}" ]; then
|
if [ -z "${URL}" ]; then
|
||||||
URL=$(echo "${repo_response}" | jq '.html_url')
|
URL=$(echo "${repo_response}" | jq '.html_url'| sed 's/"//g')
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue