1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/weblate_ynh.git synced 2024-10-01 13:35:04 +02:00

allow connection to both github and gitlab

This commit is contained in:
ericgaspar 2022-08-11 19:48:34 +02:00
parent 5ea9dc1ede
commit 102e67035c
6 changed files with 61 additions and 20 deletions

View file

@ -5,8 +5,9 @@
is_public=1
admin="john"
password="1Strong-Password"
github_account="myaccount"
github_token="myoauthtoken"
used_forge="GitLab"
forge_account="myaccount"
forge_token="myoauthtoken"
; Checks
pkg_linter=1
setup_sub_dir=1

View file

@ -229,13 +229,13 @@ TEMPLATES = [
# GitHub username and token for sending pull requests.
# Please see the documentation for more details.
GITHUB_USERNAME = "__GITHUB_ACCOUNT__"
GITHUB_TOKEN = "__GITHUB_TOKEN__"
GITHUB_USERNAME = __GITHUB_USERNAME__
GITHUB_TOKEN = __GITHUB_TOKEN__
# GitLab username and token for sending merge requests.
# Please see the documentation for more details.
GITLAB_USERNAME = None
GITLAB_TOKEN = None
GITLAB_USERNAME = __GITLAB_USERNAME__
GITLAB_TOKEN = __GITLAB_TOKEN__
# Authentication configuration
AUTHENTICATION_BACKENDS = (

View file

@ -58,20 +58,30 @@
"type": "password"
},
{
"name": "github_account",
"name": "used_forge",
"type": "string",
"ask": {
"en": "GitHub's username",
"fr": "Nom d'utilisateur de GitHub"
"en":"Choose the forge you use",
"fr":"Choisissez la forge que vous utilisez"
},
"example": "Github account"
"choices": ["GitHub", "GitLab"],
"default": "GitHub"
},
{
"name": "github_token",
"name": "forge_username",
"type": "string",
"ask": {
"en": "GitHub's token (OAuth)",
"fr": "Jeton GitHub (OAuth)"
"en": "Your forge's username",
"fr": "Nom d'utilisateur sur votre forge"
},
"example": "Your account"
},
{
"name": "forge_token",
"type": "string",
"ask": {
"en": "Your forge's token (OAuth)",
"fr": "Jeton de votre forge (OAuth)"
},
"example": "A secret token"
}

View file

@ -31,6 +31,20 @@ fi
# PERSONAL HELPERS
#=================================================
set_forge_variables() {
if [ $used_forge -eq "GitHub" ]
github_username="\"$forge_username\""
github_token="\"$forge_token\""
gitlab_username="None"
gitlab_token="None"
else
github_username="None"
github_token="None"
gitlab_username="\"$forge_username\""
gitlab_token="\"$forge_token\""
fi
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================

View file

@ -28,8 +28,9 @@ path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
admin=$YNH_APP_ARG_ADMIN
password=$YNH_APP_ARG_PASSWORD
github_account=$YNH_APP_ARG_GITHUB_ACCOUNT
github_token=$YNH_APP_ARG_GITHUB_TOKEN
used_forge=$YNH_APP_ARG_USED_FORGE
forge_account=$YNH_APP_ARG_FORGE_USERNAME
forge_token=$YNH_APP_ARG_FORGE_TOKEN
app=$YNH_APP_INSTANCE_NAME
@ -55,8 +56,9 @@ ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=github_account --value=$github_account
ynh_app_setting_set --app=$app --key=github_token --value=$github_token
ynh_app_setting_set --app=$app --key=used_forge --value=$used_forge
ynh_app_setting_set --app=$app --key=forge_username --value=$forge_username
ynh_app_setting_set --app=$app --key=forge_token --value=$forge_token
#=================================================
# STANDARD MODIFICATIONS
@ -174,6 +176,8 @@ ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
path_url="${path_url%/}"
settings="$final_path/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
set_forge_variables
ynh_add_config --template="../conf/settings.py" --destination="$settings"
ynh_add_config --template="../conf/celery-weblate" --destination="$final_path/celery-weblate"
ynh_add_config --template="../conf/uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini"

View file

@ -23,8 +23,9 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
github_account=$(ynh_app_setting_get --app=$app --key=github_account)
github_token=$(ynh_app_setting_get --app=$app --key=github_token)
used_forge=$(ynh_app_setting_get --app=$app --key=used_forge)
forge_account=$(ynh_app_setting_get --app=$app --key=forge_account)
forge_token=$(ynh_app_setting_get --app=$app --key=forge_token)
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
@ -33,7 +34,6 @@ key=$(ynh_string_random --length=50)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
@ -88,6 +88,16 @@ then
ynh_secure_remove --file="/var/log/$app-celery"
fi
# If used_forge, forge_account, forge_token don't exist, create them
if [ -z "$used_forge" ]; then
used_forge="GitHub"
forge_account=$(ynh_app_setting_get --app=$app --key=github_account)
forge_token=$(ynh_app_setting_get --app=$app --key=github_token)
ynh_app_setting_set --app=$app --key=used_forge --value=$used_forge
ynh_app_setting_set --app=$app --key=forge_account --value=$forge_account
ynh_app_setting_set --app=$app --key=forge_token --value=$forge_token
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
@ -198,6 +208,8 @@ upgrade() {
settings="$final_path/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
path_url="${path_url%/}"
set_forge_variables
ynh_add_config --template="../conf/settings.py" --destination="$settings"
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"