summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-23 23:26:52 +0300
committerPaul Buetow <paul@buetow.org>2025-06-23 23:26:52 +0300
commit006724744a943aad877a92406a5e2b4d5d12acd3 (patch)
treece79e6481d3a9ae38bebf3a7acd1d3a7edd520a8 /test
parent125e2a2c50bcb3eaa5dfb8802c6de3b2f406b3d2 (diff)
Add GitHub repository creation and improve error handling
- Add --create-github-repos flag to automatically create missing GitHub repositories - Implement GitHub API client with token support from config/env/file - Add Codeberg API integration to sync all public repositories - Make sync operations stop on first error for better debugging - Support GitHub repo creation for all sync commands (--sync, --sync-all, --sync-codeberg-public) - Add comprehensive error messages and debug logging 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'test')
-rwxr-xr-xtest/test_branch_creation.sh92
-rwxr-xr-xtest/test_codeberg_list.sh22
2 files changed, 114 insertions, 0 deletions
diff --git a/test/test_branch_creation.sh b/test/test_branch_creation.sh
new file mode 100755
index 0000000..cf02426
--- /dev/null
+++ b/test/test_branch_creation.sh
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+# Test script for branch creation functionality
+set -e
+
+echo "Testing automatic branch creation on remotes..."
+
+TEST_DIR="$(cd "$(dirname "$0")" && pwd)"
+REPOS_DIR="$TEST_DIR/repos"
+mkdir -p "$REPOS_DIR"
+
+# Clean up if they exist
+rm -rf "$REPOS_DIR/org1" "$REPOS_DIR/org2"
+mkdir -p "$REPOS_DIR/org1" "$REPOS_DIR/org2"
+
+# Create a repository in org1 with multiple branches
+echo "Creating repository in org1 with branches..."
+cd "$REPOS_DIR/org1"
+git init --bare test-branch-repo.git
+
+# Create only the same repository in org2 but with just main branch
+echo "Creating repository in org2..."
+cd "$REPOS_DIR/org2"
+git init --bare test-branch-repo.git
+
+# Add content and branches to org1
+WORK_DIR="$REPOS_DIR/work"
+rm -rf "$WORK_DIR"
+mkdir -p "$WORK_DIR"
+
+echo "Creating branches in org1..."
+cd "$WORK_DIR"
+git clone "$REPOS_DIR/org1/test-branch-repo.git"
+cd test-branch-repo
+
+# Create main branch
+echo "# Test Repo" > README.md
+git add README.md
+git commit -m "Initial commit"
+git push origin main
+
+# Create feature branch
+git checkout -b feature/new-feature
+echo "New feature" > feature.txt
+git add feature.txt
+git commit -m "Add new feature"
+git push origin feature/new-feature
+
+# Create hotfix branch
+git checkout -b hotfix/urgent-fix
+echo "Urgent fix" > hotfix.txt
+git add hotfix.txt
+git commit -m "Apply urgent fix"
+git push origin hotfix/urgent-fix
+
+# Push only main to org2
+git checkout main
+git remote add org2 "$REPOS_DIR/org2/test-branch-repo.git"
+git push org2 main
+
+# Clean up work directory
+cd "$TEST_DIR"
+rm -rf "$WORK_DIR"
+
+# Create test config
+cat > "$TEST_DIR/branch-test-config.json" << EOF
+{
+ "organizations": [
+ {
+ "host": "file://$REPOS_DIR/org1",
+ "name": ""
+ },
+ {
+ "host": "file://$REPOS_DIR/org2",
+ "name": ""
+ }
+ ],
+ "repositories": [
+ "test-branch-repo"
+ ]
+}
+EOF
+
+echo ""
+echo "Test setup complete!"
+echo ""
+echo "Initial state:"
+echo "- org1 has: main, feature/new-feature, hotfix/urgent-fix"
+echo "- org2 has: main only"
+echo ""
+echo "Run sync to see branch creation:"
+echo " ./gitsyncer --config test/branch-test-config.json --sync test-branch-repo" \ No newline at end of file
diff --git a/test/test_codeberg_list.sh b/test/test_codeberg_list.sh
new file mode 100755
index 0000000..d285be6
--- /dev/null
+++ b/test/test_codeberg_list.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# Test script to list Codeberg public repos without syncing
+set -e
+
+echo "Testing Codeberg API to list public repositories..."
+
+# Use curl to test the API directly
+USER="snonux"
+echo "Fetching public repos for user: $USER"
+
+# Try as user
+echo ""
+echo "Trying user endpoint..."
+curl -s "https://codeberg.org/api/v1/users/$USER/repos?limit=50" | \
+ jq -r '.[] | select(.private == false and .fork == false and .archived == false) | .name' | \
+ sort
+
+echo ""
+echo "Total public repos (non-fork, non-archived):"
+curl -s "https://codeberg.org/api/v1/users/$USER/repos?limit=50" | \
+ jq '[.[] | select(.private == false and .fork == false and .archived == false)] | length' \ No newline at end of file