initial commit
This commit is contained in:
43
cloneissues.sh
Executable file
43
cloneissues.sh
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script fetches all the issues from a GitHub project and saves them in a JSON file.
|
||||
# It needs the GitHub CLI to be installed and configured.
|
||||
# You can find the GitHub CLI here: https://cli.github.com/
|
||||
|
||||
PROJECT=$1
|
||||
# Check if the project is set
|
||||
if [ -z "$PROJECT" ]; then
|
||||
echo "Usage: $0 <project> [open|closed|all]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set the state
|
||||
STATE=${2:-open}
|
||||
|
||||
# Set the target file name
|
||||
TARGET_FILE="$(echo ${PROJECT}|sed -r 's/\//-/g')_$(date +"%Y-%m-%d-%H-%M-%S").json"
|
||||
# Check if the file already exists
|
||||
if [ -f "${TARGET_FILE}" ]; then
|
||||
echo "File ${TARGET_FILE} already exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create the file
|
||||
touch "${TARGET_FILE}"
|
||||
|
||||
# Fetch the issues
|
||||
echo "Fetching issues from $1"
|
||||
ISSUES_NUMBERS=$(gh issue list -R "${PROJECT}" -s "${STATE}" -L 10000000 |awk '{print $1}')
|
||||
|
||||
ISSUES_OUTPUT=""
|
||||
# Process the issues
|
||||
for ISSUE_NUMBER in $ISSUES_NUMBERS
|
||||
do
|
||||
echo "Processing issue $ISSUE_NUMBER"
|
||||
ISSUE=$(gh issue view "${ISSUE_NUMBER}" -R "${PROJECT}" --json assignees,author,body,closed,closedAt,comments,createdAt,id,isPinned,labels,milestone,number,projectCards,projectItems,reactionGroups,state,stateReason,title,updatedAt,url |jq .)
|
||||
# Append the issue to the file
|
||||
printf "\n---\n%s\n" "${ISSUE}" >> "${TARGET_FILE}"
|
||||
done
|
||||
|
||||
# Display the file
|
||||
cat "${TARGET_FILE}"
|
||||
59
gitbackup.sh
Executable file
59
gitbackup.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
# Set the organization name as the first argument
|
||||
ORG=$1
|
||||
|
||||
# Check if the organization name is provided
|
||||
if [ -z "${ORG}" ]; then
|
||||
echo "Usage: $0 <github-organization|user>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a temporary directory with current date and time
|
||||
TEMPDIR="${ORG}-$(date +"%Y-%m-%d-%H-%M-%S")"
|
||||
mkdir $TEMPDIR
|
||||
pushd $TEMPDIR
|
||||
echo "Getting all repos for ${ORG}"
|
||||
REPOS=$(curl "https://api.github.com/users/${ORG}/repos?per_page=1000" | grep -o 'git@[^"]*'| sed 's/git@/https:\/\//g' | sed 's/\.com:/\.com\//g')
|
||||
|
||||
# Check if any repos are found, exit if none
|
||||
if [ -z "${REPOS}" ]; then
|
||||
echo "No repos found for ${ORG}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clone all repos
|
||||
for REPO in $REPOS; do
|
||||
echo "Cloning ${REPO}"
|
||||
git clone ${REPO} || ERROR_CODE=$?
|
||||
if [ -n "${ERROR_CODE}" ]; then
|
||||
echo "Error cloning ${REPO}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove the .git extension from the repo name & enter the directory
|
||||
pushd $(echo ${REPO}|sed -e 's/.*\///' -e 's/\.git$//')
|
||||
# Fetch all branches
|
||||
git fetch --all
|
||||
# Pull all branches
|
||||
git pull --all
|
||||
# Fetch all tags
|
||||
git fetch --tags --all
|
||||
BRANCHES=$(git branch -r | grep -v '\->' | sed 's/origin\///')
|
||||
for BRANCH in $BRANCHES; do
|
||||
echo "Checking out branch ${BRANCH}"
|
||||
git checkout ${BRANCH}
|
||||
git pull origin ${BRANCH}
|
||||
done
|
||||
popd
|
||||
done
|
||||
popd
|
||||
|
||||
# Compress the directory into a tarball
|
||||
echo "Compressing ${TEMPDIR} into ${TEMPDIR}.tar.gz"
|
||||
tar -czf ${TEMPDIR}.tar.gz $TEMPDIR
|
||||
|
||||
# Remove the directory
|
||||
rm -rf ${TEMPDIR}
|
||||
|
||||
# Show the tarball details
|
||||
ls -lisah ${TEMPDIR}.tar.gz
|
||||
Reference in New Issue
Block a user