05.b - Repository-Cloning-Automation
Relevant source files
Purpose and ScopeLink copied!
This document details the automated repository cloning pipeline that processes customer repositories after GitHub App installation. The pipeline extracts installation IDs from ntfy notifications, generates access tokens, clones customer repositories, and creates private mirrors in the klaudioz GitHub account.
For information about the ntfy message broker integration, see ntfy Integration & Message Broker. For details about the automation script variants and setup, see Automation Scripts.
Sources: scripts/README.md L1-L81
Pipeline ArchitectureLink copied!
The automation pipeline operates as a stateless, event-driven system triggered by ntfy notifications containing GitHub installation details.
System Components DiagramLink copied!
Sources: scripts/ntfy-godeep-automation.sh L1-L152
Workflow StagesLink copied!
Installation ID ExtractionLink copied!
The script listens for ntfy notifications and filters for GitHub installation events using title pattern matching.
| Operation | Implementation | Line Reference |
|---|---|---|
| Subscribe to topic | ntfy subscribe "$TOPIC" | scripts/ntfy-godeep-automation.sh L39 |
| Parse JSON | jq -r '.message // empty' | scripts/ntfy-godeep-automation.sh L41-L42 |
| Title filtering | grep -q "GitHub Connected|GitHub Installation" | scripts/ntfy-godeep-automation.sh L49 |
| Extract ID | grep -o 'Installation ID: [0-9]*' | scripts/ntfy-godeep-automation.sh L53 |
The extraction uses macOS-compatible regex patterns to parse the installation ID from notification messages containing the format Installation ID: 12345678.
Sources: scripts/ntfy-godeep-automation.sh L39-L54
Token Generation via Admin APILink copied!
The script authenticates with the admin API to generate installation access tokens with repository metadata.
Request Payload Structure:
{ "installationId": "12345678", "password": "<ADMIN_PASSWORD from .env>"}
Response Structure Extraction:
token: Installation access token (scripts/ntfy-godeep-automation.sh L68 )repositories[0].full_name: Full repo name likecustomer-org/repo-name(scripts/ntfy-godeep-automation.sh L69 )repositories[0].name: Repository name only (scripts/ntfy-godeep-automation.sh L70 )user.emailoruser.username: Customer identifier (scripts/ntfy-godeep-automation.sh L71 )
Sources: scripts/ntfy-godeep-automation.sh L16-L28
scripts/ntfy-godeep-automation.sh L62-L72
Repository CloningLink copied!
The script clones the customer repository using GitHub's token-based authentication over HTTPS.
Clone Command Pattern:
git clone "https://x-access-token:${token}@github.com/${repo_full_name}.git" "$clone_path"
Directory Path Construction:
- Extract email prefix:
sed 's/@/_/g; s/\./_/g'(scripts/ntfy-godeep-automation.sh L80 ) - Convert to lowercase:
tr '[:upper:]' '[:lower:]'(scripts/ntfy-godeep-automation.sh L80 ) - Format as:
email_prefix-repo_name(scripts/ntfy-godeep-automation.sh L81 ) - Full path:
$HOME/godeep-clones/email_prefix-repo_name(scripts/ntfy-godeep-automation.sh L87 )
Example Transformations:
| Customer Email | Repository Name | Formatted Path |
|---|---|---|
user@example.com | my-app | ~/godeep-clones/user_example_com-my-app |
John.Doe@Company.io | api-server | ~/godeep-clones/john_doe_company_io-api-server |
Sources: scripts/ntfy-godeep-automation.sh L78-L90
Git Re-initializationLink copied!
After cloning, the script removes the original Git history and creates a new repository to avoid linking to the customer's repository.
Re-initialization Sequence:
Commit Message Format:
Initial commit from GoDeep.wiki customer: <customer_email>
This preserves the customer identifier for tracking purposes while creating an independent Git history.
Sources: scripts/ntfy-godeep-automation.sh L100-L103
Private Repository CreationLink copied!
The script uses GitHub CLI (gh) to create private repositories in the klaudioz account.
Creation Command:
gh repo create "klaudioz/$formatted_repo_name" --private --source=. --push
Command Breakdown:
| Flag | Purpose | Details |
|---|---|---|
klaudioz/$formatted_repo_name | Repository path | Owner/repo format with formatted name |
--private | Visibility | Ensures repository is not public |
--source=. | Source directory | Current directory (cloned repo) |
--push | Auto-push | Immediately pushes commits to new repo |
Authentication Requirement:
The gh CLI must be authenticated with credentials that have repository creation permissions on the klaudioz account. This is separate from the installation access token used for cloning.
Sources: scripts/ntfy-godeep-automation.sh L106-L117
Cleanup and Disk ManagementLink copied!
The script deletes local clones after successful repository creation to conserve disk space.
Cleanup Flow:
Critical Safety Measure:
The script always changes back to the parent directory with cd - > /dev/null before deletion (scripts/ntfy-godeep-automation.sh L110
scripts/ntfy-godeep-automation.sh L122
) to prevent deleting the current working directory.
Disk Space Management:
- Clones are temporary and immediately deleted after processing
- Failed clones are also deleted to prevent orphaned directories
- Clone directory is
~/godeep-clones/(scripts/ntfy-godeep-automation.sh L8 )
Sources: scripts/ntfy-godeep-automation.sh L109-L130
Data Flow and State ManagementLink copied!
Complete Processing PipelineLink copied!
Sources: scripts/ntfy-godeep-automation.sh L39-L151
Directory Structure and File NamingLink copied!
Clone Directory LayoutLink copied!
The script maintains a structured directory hierarchy for temporary clones:
$HOME/
└── godeep-clones/
├── user_example_com-frontend-app/ # Temporary (deleted after push)
├── john_doe_company_io-api-server/ # Temporary (deleted after push)
└── admin_test_org-microservice/ # Temporary (deleted after push)
Directory Configuration:
- Base path:
$HOME/godeep-clones(scripts/ntfy-godeep-automation.sh L8 ) - Auto-created if missing:
mkdir -p "$CLONE_DIR"(scripts/ntfy-godeep-automation.sh L31 ) - Subdirectories use formatted naming:
$CLONE_DIR/$formatted_repo_name(scripts/ntfy-godeep-automation.sh L87 )
Repository Naming ConventionLink copied!
Formatting Rules:
| Step | Operation | Code Reference |
|---|---|---|
| 1. Extract email | jq -r '.user.email // .user.username // empty' | scripts/ntfy-godeep-automation.sh L71 |
| 2. Replace @ and . | sed 's/@/_/g; s/\./_/g' | scripts/ntfy-godeep-automation.sh L80 |
| 3. Lowercase | tr '[:upper:]' '[:lower:]' | scripts/ntfy-godeep-automation.sh L80 |
| 4. Combine | "${email_prefix}-${repo_name}" | scripts/ntfy-godeep-automation.sh L81 |
| 5. Fallback | If no email, use "$repo_name" | scripts/ntfy-godeep-automation.sh L83 |
Result: GitHub repository at github.com/klaudioz/email_prefix-repo_name
Sources: scripts/ntfy-godeep-automation.sh L78-L87
Error Handling and NotificationsLink copied!
macOS Notification SystemLink copied!
The script provides visual feedback through macOS osascript notifications at each stage:
| Event | Notification Title | Message Content | Line Reference |
|---|---|---|---|
| Installation detected | "GoDeep.wiki Automation" | "Processing Installation ID: {id}" | scripts/ntfy-godeep-automation.sh L59 |
| Clone complete | "✅ GoDeep.wiki - Clone Complete" | "Repository cloned to {path}" | scripts/ntfy-godeep-automation.sh L94 |
| Repo created | "✅ GoDeep.wiki - Complete!" | "Repository created: klaudioz/{name}" | scripts/ntfy-godeep-automation.sh L117 |
| Repo creation failed | "❌ GoDeep.wiki Error" | "Failed to create repo: {name}" | scripts/ntfy-godeep-automation.sh L129 |
| Clone failed | "❌ GoDeep.wiki Error" | "Clone failed for {repo}" | scripts/ntfy-godeep-automation.sh L134 |
| Token generation failed | "❌ GoDeep.wiki Error" | "Failed to process Installation ID: {id}" | scripts/ntfy-godeep-automation.sh L139 |
Notification Command Pattern:
osascript -e "display notification \"<message>\" with title \"<title>\""
Error ScenariosLink copied!
Error Recovery:
- The script never exits on errors; it continues listening for new notifications
- Failed clones are deleted to prevent disk space accumulation
- Errors are logged to stdout with emoji indicators (❌, ⚠️)
Sources: scripts/ntfy-godeep-automation.sh L117-L148
Technical Implementation DetailsLink copied!
Token Authentication FlowLink copied!
The pipeline uses two distinct authentication mechanisms:
| Stage | Token Type | Usage | Expiry |
|---|---|---|---|
| Clone | Installation access token | x-access-token in git URL | 1 hour |
| Push | GitHub CLI credentials | gh authenticated session | Persistent |
Installation Token Usage:
git clone "https://x-access-token:${token}@github.com/${repo_full_name}.git"
The x-access-token is a special GitHub authentication mechanism that accepts any value as the username when using a personal access token or installation token.
Sources: scripts/ntfy-godeep-automation.sh L90
Script ConfigurationLink copied!
Environment Variables:
| Variable | Purpose | Line Reference |
|---|---|---|
TOPIC | ntfy.sh topic name | scripts/ntfy-godeep-automation.sh L6 |
ADMIN_URL | Admin API endpoint | scripts/ntfy-godeep-automation.sh L7 |
CLONE_DIR | Base clone directory | scripts/ntfy-godeep-automation.sh L8 |
SCRIPT_DIR | Script location | scripts/ntfy-godeep-automation.sh L11 |
PROJECT_ROOT | Project root directory | scripts/ntfy-godeep-automation.sh L13 |
ENV_FILE | Path to .env file | scripts/ntfy-godeep-automation.sh L16 |
ADMIN_PASSWORD | Admin API password | scripts/ntfy-godeep-automation.sh L23 |
Path Resolution Strategy:
The script uses $( cd ... && pwd ) for absolute path resolution (scripts/ntfy-godeep-automation.sh L11-L13
), ensuring it can be executed from any directory.
Sources: scripts/ntfy-godeep-automation.sh L6-L28
JSON Parsing and Data ExtractionLink copied!
The script uses jq for JSON processing at multiple stages:
Notification Parsing:
message=$(echo "$line" | jq -r '.message // empty')title=$(echo "$line" | jq -r '.title // "ntfy"')
API Response Parsing:
token=$(echo "$response" | jq -r '.token // empty')repo_full_name=$(echo "$response" | jq -r '.repositories[0].full_name // empty')repo_name=$(echo "$response" | jq -r '.repositories[0].name // empty')customer_email=$(echo "$response" | jq -r '.user.email // .user.username // empty')
Fallback Strategy:
- Uses
// emptyto return empty string if field is missing - Uses
// .user.usernameas fallback if email is unavailable - Checks for empty strings before proceeding with processing
Sources: scripts/ntfy-godeep-automation.sh L41-L42
scripts/ntfy-godeep-automation.sh L68-L71
Integration PointsLink copied!
Dependencies on Other SystemsLink copied!
Required Tool Installations:
ntfy: Message subscription clientjq: JSON parsing utilitygit: Repository cloninggh: GitHub CLI for repository creationosascript: macOS notification system (built-in)
Sources: scripts/README.md L67-L71
Refresh this wiki
Last indexed: 23 November 2025 (922b35)
On this page
- Repository Cloning Automation
- Purpose and Scope
- Pipeline Architecture
- System Components Diagram
- Workflow Stages
- Installation ID Extraction
- Token Generation via Admin API
- Repository Cloning
- Git Re-initialization
- Private Repository Creation
- Cleanup and Disk Management
- Data Flow and State Management
- Complete Processing Pipeline
- Directory Structure and File Naming
- Clone Directory Layout
- Repository Naming Convention
- Error Handling and Notifications
- macOS Notification System
- Error Scenarios
- Technical Implementation Details
- Token Authentication Flow
- Script Configuration
- JSON Parsing and Data Extraction
- Integration Points
- Dependencies on Other Systems
Ask Devin about godeep.wiki-jb
Syntax error in text
mermaid version 11.4.1