Add option to create forgejo repo
This commit is contained in:
parent
f8bfb898b7
commit
7124d84280
1 changed files with 33 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
function usage() {
|
function usage() {
|
||||||
echo "$(basename "${0}" .sh) [--help|-h|-?] [--author|-a 'Author name'] [--authoring-date|-d 'date of creation'] [--project-name|-n 'Name of the project'] [--project-codename|-p short_project_name] [--version|-v 'version number'] [--deployment-path|-r 'path/to/copy/skeleton'] [--author-email|-e 'email@example.org'] [--url|-u 'https://domain.com'] [--license|-l 'LICENSEv1']"
|
echo "$(basename "${0}" .sh) [--help|-h|-?] [--author|-a 'Author name'] [--authoring-date|-d 'date of creation'] [--project-name|-n 'Name of the project'] [--project-codename|-p short_project_name] [--version|-v 'version number'] [--deployment-path|-r 'path/to/copy/skeleton'] [--author-email|-e 'email@example.org'] [--url|-u 'https://domain.com'] [--license|-l 'LICENSEv1'] [--forgejo-instance|-f 'https://repos.example.org'] [--forgejo-token|-t 'Very Secret Token']"
|
||||||
echo ""
|
echo ""
|
||||||
echo " --help Show this help."
|
echo " --help Show this help."
|
||||||
echo " --author Author name, between quotes for spaces."
|
echo " --author Author name, between quotes for spaces."
|
||||||
|
@ -14,6 +14,8 @@ function usage() {
|
||||||
echo " --license License name."
|
echo " --license License name."
|
||||||
echo " --license-url License URL to fetch in plain text and save in your project folder."
|
echo " --license-url License URL to fetch in plain text and save in your project folder."
|
||||||
echo " --description Description."
|
echo " --description Description."
|
||||||
|
echo " --forgejo-instance URL to your Forgejo instance to create a repository. If present, will try to create a private repository."
|
||||||
|
echo " --forgeto-token API token to authenticate to your Forgejo instance."
|
||||||
if [ -e "$(dirname "${0}")/defaults" ]
|
if [ -e "$(dirname "${0}")/defaults" ]
|
||||||
then
|
then
|
||||||
echo "Defaults:"
|
echo "Defaults:"
|
||||||
|
@ -22,6 +24,8 @@ function usage() {
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
AUTHOR_EMAIL="${USER}@$(hostname -f)"
|
AUTHOR_EMAIL="${USER}@$(hostname -f)"
|
||||||
|
FORGEJO_INSTANCE=''
|
||||||
|
FORGEJO_TOKEN=''
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
if [ -e "$(dirname "${0}")/defaults" ]
|
if [ -e "$(dirname "${0}")/defaults" ]
|
||||||
then
|
then
|
||||||
|
@ -90,6 +94,16 @@ do
|
||||||
DESCRIPTION="${1}"
|
DESCRIPTION="${1}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
"--forgejo-instance"|"-f")
|
||||||
|
shift
|
||||||
|
FORGEJO_INSTANCE="${1}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--forgejo-token"|"-t")
|
||||||
|
shift
|
||||||
|
FORGEJO_TOKEN="${1}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Ignoring unknwon parameter '${1}'"
|
echo "Ignoring unknwon parameter '${1}'"
|
||||||
shift
|
shift
|
||||||
|
@ -141,3 +155,21 @@ do
|
||||||
sed -i "s/__license__/${LICENSE}/g" "${file}"
|
sed -i "s/__license__/${LICENSE}/g" "${file}"
|
||||||
sed -i "s/__description__/${DESCRIPTION}/g" "${file}"
|
sed -i "s/__description__/${DESCRIPTION}/g" "${file}"
|
||||||
done <<< "$(find "${destination_path}/" -type f)"
|
done <<< "$(find "${destination_path}/" -type f)"
|
||||||
|
|
||||||
|
if [ -n "${FORGEJO_INSTANCE}" ]; then
|
||||||
|
data="{ \"default_branch\": \"main\", \"description\": \"${DESCRIPTION}\", \"name\": \"${PROJECT_CODENAME}\", \"private\": true}"
|
||||||
|
response=$(curl -s "${FORGEJO_INSTANCE}/api/v1/user/repos" \
|
||||||
|
-H "Authorization: Bearer ${FORGEJO_TOKEN}" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-X POST \
|
||||||
|
-d "${data}")
|
||||||
|
git_url=$(echo "${response}" | jq '.ssh_url')
|
||||||
|
cd "${destination_path}" || exit 1
|
||||||
|
git init
|
||||||
|
git checkout -b main
|
||||||
|
git add .
|
||||||
|
git commit -m "Initial commit"
|
||||||
|
git remote add origin "${git_url}"
|
||||||
|
git push -u origin main
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in a new issue