-
-
Save trumae/bd5f2b92db95e8db45b6471b3efbac35 to your computer and use it in GitHub Desktop.
Transfer issues from Gitea to Github
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Configuration | |
GITEA_REPO="username/repository" | |
GITEA_API_TOKEN="your_gitea_api_token" | |
GITHUB_REPO="username/repository" | |
GITHUB_API_TOKEN="your_github_api_token" | |
GITEA_API_URL="https://your_gitea_instance/api/v1" | |
GITHUB_API_URL="https://api.github.com" | |
ISSUE_FILE="gitea_issues.json" | |
# Check and Export Issues from Gitea | |
export_gitea_issues() { | |
if [[ -f "$ISSUE_FILE" ]]; then | |
read -p "Existing issue file found. Use it (y) or create a new one (n)? " choice | |
case "$choice" in | |
y|Y ) echo "Using existing file.";; | |
n|N ) rm "$ISSUE_FILE"; fetch_issues;; | |
* ) echo "Invalid response."; exit 1;; | |
esac | |
else | |
fetch_issues | |
fi | |
} | |
fetch_issues() { | |
curl -H "Authorization: token ${GITEA_API_TOKEN}" \ | |
-H "Content-Type: application/json" \ | |
"${GITEA_API_URL}/repos/${GITEA_REPO}/issues" > "$ISSUE_FILE" | |
} | |
# Import Issues to GitHub and Update JSON | |
import_to_github() { | |
local temp_file="temp_$ISSUE_FILE" | |
jq -c '.[]' "$ISSUE_FILE" | while read i; do | |
title=$(echo $i | jq -r '.title') | |
body=$(echo $i | jq -r '.body') | |
labels=$(echo $i | jq -r '.labels | map(.name) | @csv' | sed 's/"//g' | sed 's/,/", "/g') | |
labels="[\"$labels\"]" | |
# Import to GitHub | |
response=$(curl -H "Authorization: token ${GITHUB_API_TOKEN}" \ | |
-H "Content-Type: application/json" \ | |
-d "{\"title\":\"${title}\",\"body\":\"${body}\",\"labels\":$labels}" \ | |
"${GITHUB_API_URL}/repos/${GITHUB_REPO}/issues") | |
# Check if the issue was successfully created | |
if echo "$response" | jq -e .id >/dev/null 2>&1; then | |
# Remove the imported issue from the original JSON | |
jq "del(.[] | select(.title == \"$title\"))" "$ISSUE_FILE" > "$temp_file" && mv "$temp_file" "$ISSUE_FILE" | |
else | |
echo "Failed to import issue: $title" | |
fi | |
sleep 2 # To prevent hitting API rate limits | |
done | |
} | |
# Execute Functions | |
export_gitea_issues | |
import_to_github |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment