Welcome to the GitBridge API Reference. This page highlights the main public classes and modules. For in‑code docs, see the source in the gitbridge/ package.
fromgitbridge.api_syncimportGitHubAPISyncsync=GitHubAPISync(repo_url="https://github.com/user/repo",local_path="/path/to/local/repo",)success=sync.sync()print("ok"ifsuccesselse"failed")```pythonimportosimporttempfilefromgitbridgeimportGitHubAPISyncdeftest_real_sync():"""Integration test with real repository."""withtempfile.TemporaryDirectory()astmpdir:sync=GitHubAPISync(repo_url="https://github.com/github/gitignore",local_path=tmpdir,)# Test connectionassertsync.test_connection()# Perform syncassertsync.sync()# Verify a known file existsassertos.path.exists(os.path.join(tmpdir,"Python.gitignore"))
Playwright‑based browser automation for fallback synchronization: GitHubBrowserSync.
importosfromgitbridgeimportGitHubAPISync# Using token from environmenttoken=os.getenv("GITHUB_TOKEN")sync=GitHubAPISync(repo_url="https://github.com/company/private-repo",local_path="/path/to/local",token=token)# Sync with authenticationsync.sync()
fromgitbridge.browser_syncimportGitHubBrowserSync# Use browser automation when API is blockedbrowser_sync=GitHubBrowserSync(repo_url="https://github.com/user/repo",local_path="/path/to/local",browser_type="chromium",headless=True)# Perform browser-based syncbrowser_sync.sync()
fromgitbridgeimportGitHubAPISyncfromgitbridge.configimportConfig# Load configuration from fileconfig=Config.from_file("config.yaml")# Create sync with configurationsync=GitHubAPISync(repo_url=config.repository.url,local_path=config.local.path,token=config.auth.token,proxy=config.network.proxy,verify_ssl=config.network.ssl.verify)
# Stream large files instead of loading to memorysync=GitHubAPISync(repo_url=repo_url,local_path=local_path,stream_large_files=True,large_file_threshold=52428800# 50MB)
importunittestfromunittest.mockimportMock,patchfromgitbridgeimportGitHubAPISyncclassTestGitBridge(unittest.TestCase):@patch('gitbridge.api_sync.requests.Session')deftest_sync(self,mock_session):"""Test repository sync."""# Mock API responsesmock_response=Mock()mock_response.json.return_value={"sha":"abc123"}mock_session.return_value.get.return_value=mock_response# Test syncsync=GitHubAPISync("https://github.com/user/repo","/tmp/test")result=sync.sync()self.assertTrue(result)
importtempfileimportshutilfromgitbridgeimportGitHubAPISyncdeftest_real_sync():"""Integration test with real repository."""withtempfile.TemporaryDirectory()astmpdir:tmpdir)# Test connectionassertsync.test_connection()# Perform syncassertsync.sync()# Verify files existassertos.path.exists(os.path.join(tmpdir,"Python.gitignore"))