added gitea methods to setup remote repo
This commit is contained in:
parent
c229c9dd81
commit
038424b526
67
rtenets
67
rtenets
|
@ -119,7 +119,7 @@ gitea() {
|
||||||
local request="$2"
|
local request="$2"
|
||||||
local data=""
|
local data=""
|
||||||
|
|
||||||
if [[ $# > 3 ]]; then
|
if [[ $# > 2 ]]; then
|
||||||
data="$3"
|
data="$3"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -263,6 +263,71 @@ create_tenet_file_tree() {
|
||||||
script_stub make_all_figures "Generating figures..."
|
script_stub make_all_figures "Generating figures..."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_gitea_owner() {
|
||||||
|
gitea /user GET | jq -r '.login'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if repository exists
|
||||||
|
get_gitea_repo() {
|
||||||
|
local owner="$1"
|
||||||
|
local repo_name="$2"
|
||||||
|
gitea "/repos/${owner}/${repo_name}" GET
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a repository on gitea
|
||||||
|
create_gitea_repo() {
|
||||||
|
local owner="$1"
|
||||||
|
local repo_name="$2"
|
||||||
|
local get_response="$(get_gitea_repo "${owner}" "${repo_name}")"
|
||||||
|
|
||||||
|
# Check if repo already exits
|
||||||
|
if [[ "$(jq '.id' <<< "${get_response}")" == "null" ]]; then
|
||||||
|
info "creating repository '${repo_name}' on gitea"
|
||||||
|
gitea /user/repos POST "{ \"name\": \"${repo_name}\", \"private\": true }"
|
||||||
|
else
|
||||||
|
info "found repository '${repo_name}' on gitea"
|
||||||
|
printf "%s" "${get_response}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# API call to setup the software heritage webhook
|
||||||
|
setup_software_heritage_hook() {
|
||||||
|
local owner="$1"
|
||||||
|
local repo_name="$2"
|
||||||
|
local remote_url="$3"
|
||||||
|
#gitea "/repos/${owner}/${repo_name}/hooks" GET
|
||||||
|
gitea "/repos/${owner}/${repo_name}/hooks" POST \
|
||||||
|
"{ \"type\": \"gitea\",
|
||||||
|
\"config\": {
|
||||||
|
\"content_type\": \"json\",
|
||||||
|
\"url\": \"https://archive.softwareheritage.org/api/1/origin/save/git/url/${remote_url}\"
|
||||||
|
},
|
||||||
|
\"events\": [\"release\"],
|
||||||
|
\"active\": true
|
||||||
|
}"
|
||||||
|
info "created Software Hertiage webhook for releases in gitea"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Setup remote
|
||||||
|
setup_dalembert_gitea() {
|
||||||
|
local repo_name="$(basename <<< "${PWD}")"
|
||||||
|
local owner="$(get_gitea_owner)"
|
||||||
|
local repo_json="$(create_gitea_repo "${repo_name}")"
|
||||||
|
local remote_ssh="$(jq '.ssh_url' <<< "${repo_json}")"
|
||||||
|
local remote_http="$(jq '.clone_url' <<< "${repo_json}")"
|
||||||
|
|
||||||
|
if [[ "$(\git remote | \grep -c '^dalembert$')" == "0" ]]; then
|
||||||
|
\git remote add dalembert "${remote_ssh}"
|
||||||
|
info "created remote dalembert with '${remote_ssh}"
|
||||||
|
else
|
||||||
|
\git remote set-url dalembert "${remote_ssh}"
|
||||||
|
info "set remote dalembert with '${remote_ssh}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
setup_software_heritage_hook "${owner}" "${repo_name}" "${remote_http}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Create git repository
|
# Create git repository
|
||||||
create_repo() {
|
create_repo() {
|
||||||
local repo_name="$1"
|
local repo_name="$1"
|
||||||
|
|
Loading…
Reference in New Issue