This repository has been archived on 2024-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
joomla/bin/inc_new_project/remote_git_setup.sh

50 lines
1.2 KiB
Bash

#!/bin/bash
PROJECTNAME=$(basename "$(pwd)")
echo -e "\n\e[32mSetup Git Remotely\e[0m\n";
if [ "$DEBUG" = "true" ]; then
# Debugging
echo "DEBUGGING"
echo "GITEA API url: $GITEA_API_URL"
echo "Access token: $ACCESS_TOKEN"
echo "Project name: $PROJECTNAME";
fi
DESC="Repo auto created by Joomla remote git script creator for $PROJECTNAME"
# Create the repository using Gitea API
RESPONSE=$(curl -s -X POST \
-H "Authorization: token $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"name\":\"$PROJECTNAME\",\"private\": true,\"description\": \"$DESC\"}" \
$GITEA_API_URL/user/repos)
if [ "$DEBUG" = "true" ]; then
echo "The RESPONSE:"
echo "$RESPONSE"
fi
if [ -z "$RESPONSE" ] || [ "$(echo "$RESPONSE" | jq -r '.id')" = "null" ]; then
echo "Error: Failed to create $PROJECTNAME repository."
exit 1
fi
SSH_URL=$(echo "$RESPONSE" | jq -r '.ssh_url')
if [ "$SSH_URL" = "null" ]; then
echo "Error: Failed to retrieve SSH URL for $PROJECTNAME repository."
exit 1
fi
if [ "$DEBUG" = "true" ]; then
echo "SSH URL:"
echo "$SSH_URL"
fi
# Add new remote repository
git remote add origin "$SSH_URL"
git remote -v
# Commit existing changes
git push -u origin master