aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-02-15 00:19:09 +0100
committerMatěj Cepl <mcepl@cepl.eu>2024-07-19 10:32:49 +0200
commitc8464d17de51ba92e0cdef149d131f1d0e3e4be8 (patch)
tree0ba14fc6a86aa5e2fa2da999a65c438f9a8134ec
parent7886d6d785444d54383c35fa1da7ac5b0863aece (diff)
downloadhlupak-c8464d17de51ba92e0cdef149d131f1d0e3e4be8.tar.gz
Set some attributes of new repository
Also, don't use user specific credential helpers, but git-credentials(1)
-rwxr-xr-xgh-clone.sh25
1 files changed, 22 insertions, 3 deletions
diff --git a/gh-clone.sh b/gh-clone.sh
index 1cefa32..76e7787 100755
--- a/gh-clone.sh
+++ b/gh-clone.sh
@@ -1,8 +1,6 @@
#!/bin/bash
set -eux
-USERNAME=$(git config github.user)
-PASSWORD=$(pass show dev/github.com|awk '/^token:/ {print $2}')
ORGANIZATION="openSUSE-Python"
cd /home/pymirrors/repos/
@@ -27,10 +25,31 @@ git clone "https://github.com/${ORIG_REPO}.git"
cd "${DIRNAME}"
-curl -s -u "${USERNAME}:${PASSWORD}" \
+# Get credentials
+CREDS=$(echo 'url=https://github.com/${ORIG_REPO}.git'|git credential fill)
+PASSWORD=$(awk -F= '/password/ { print $2 ; exit }')
+
+# Fork repository
+curl -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${PASSWORD}" \
--json "{ \"organization\": \"${ORGANIZATION}\" , \
\"default_branch_only\": \"true\" }" \
"https://api.github.com/repos/${ORIG_REPO}/forks" >"${GH_TMP_DATA}"
+
+# Set defaults of the repository (we have to first switch alerts on, to switch off fixes)
+curl -s -X PUT -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${PASSWORD}" \
+ "https://api.github.com/repos/${NEW_REPO}/vulnerability-alerts"
+curl -s -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${PASSWORD}" \
+ "https://api.github.com/repos/${NEW_REPO}/automated-security-fixes"
+curl -s -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${PASSWORD}" \
+ "https://api.github.com/repos/${NEW_REPO}/vulnerability-alerts"
+
+# Set the main branch protected
+# DEF_BRANCH=$(awk -F '"' '/default_branch/ {print $4; exit}' "${GH_TMP_DATA}")
+# Somehow doesn't work FIXME
+# curl -s -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${PASSWORD}" \
+# "https://api.github.com/repos/${NEW_REPO}/branches/${DEF_BRANCH}/protection/enforce_admins"
+
+# Set remotes correctly
git remote add github \
"$(awk -F '"' '/clone_url/ {print $4 ; exit}' "${GH_TMP_DATA}")"
git remote set-url --push github \