Compare commits
2 Commits
f06d537ffb
...
038424b526
Author | SHA1 | Date |
---|---|---|
Lucas Frérot | 038424b526 | |
Lucas Frérot | c229c9dd81 |
77
rtenets
77
rtenets
|
@ -117,9 +117,17 @@ gitea() {
|
||||||
|
|
||||||
local method="$1"
|
local method="$1"
|
||||||
local request="$2"
|
local request="$2"
|
||||||
\curl -X "${request}" \
|
local data=""
|
||||||
|
|
||||||
|
if [[ $# > 2 ]]; then
|
||||||
|
data="$3"
|
||||||
|
fi
|
||||||
|
|
||||||
|
\curl -s -X "${request}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "Authorization: token ${TOKEN}" "${ENDPOINT}/${method}"
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-d "${data}" \
|
||||||
|
"${ENDPOINT}/${method}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ----------------- Git commands -----------------------
|
# ----------------- Git commands -----------------------
|
||||||
|
@ -255,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