instatic-cms / docs_brain /github.md
Dolor David Prince
feat: InStatic CMS AI pipeline with docs brain
407171a
|
Raw
History Blame Contribute Delete
7.64 kB
# GitHub Developer Markdown Brain
> Used by AI pipeline to generate repos, CI/CD workflows, Actions, and GitHub API integrations.
---
## GitHub REST API v3
### Base URL
```
https://api.github.com
```
### Authentication
```http
Authorization: Bearer ghp_your_token
Accept: application/vnd.github+json
X-GitHub-Api-Version: 2022-11-28
```
### Core Endpoints
```
GET /repos/{owner}/{repo} # Repo info
GET /repos/{owner}/{repo}/contents/{path} # File content
POST /repos/{owner}/{repo}/contents/{path} # Create file
PUT /repos/{owner}/{repo}/contents/{path} # Update file
GET /repos/{owner}/{repo}/git/trees/{sha} # File tree
GET /search/repositories?q={query} # Search repos
GET /repos/{owner}/{repo}/issues # List issues
POST /repos/{owner}/{repo}/issues # Create issue
GET /repos/{owner}/{repo}/pulls # List PRs
POST /repos/{owner}/{repo}/pulls # Create PR
GET /repos/{owner}/{repo}/releases # List releases
POST /repos/{owner}/{repo}/releases # Create release
GET /repos/{owner}/{repo}/actions/runs # Workflow runs
POST /repos/{owner}/{repo}/deployments # Create deployment
```
### Create/Update File
```python
import base64, requests
def push_file(owner, repo, path, content, message, token, sha=None):
url = f"https://api.github.com/repos/{owner}/{repo}/contents/{path}"
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
}
body = {
"message": message,
"content": base64.b64encode(content.encode()).decode(),
}
if sha:
body["sha"] = sha # required for updates
r = requests.put(url, json=body, headers=headers)
return r.json()
```
### Search Repositories
```
GET /search/repositories?q=react+language:typescript&sort=stars&per_page=10
```
Response:
```json
{
"total_count": 1234,
"items": [
{
"full_name": "owner/repo",
"description": "...",
"stargazers_count": 5000,
"language": "TypeScript",
"html_url": "https://github.com/owner/repo",
"topics": ["react", "typescript"],
"updated_at": "2024-01-01T00:00:00Z"
}
]
}
```
---
## GitHub Actions Workflows
### Standard CI/CD Pipeline
```yaml
# .github/workflows/ci.yml
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
NODE_VERSION: '20'
PYTHON_VERSION: '3.11'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build
run: npm run build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
command: pages deploy dist/ --project-name=my-project
```
### Python FastAPI CI
```yaml
name: FastAPI CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- run: pip install -r requirements.txt
- name: Run tests
run: pytest tests/ -v --cov=app --cov-report=xml
- name: Lint
run: |
pip install ruff
ruff check .
deploy-hf:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Push to HuggingFace Space
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
git remote add hf https://Daviddolor:${HF_TOKEN}@huggingface.co/spaces/Daviddolor/instatic-cms
git push hf main --force
```
### Android Build Workflow
```yaml
name: Android CI
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- name: Build Debug APK
run: ./gradlew assembleDebug
- name: Run Unit Tests
run: ./gradlew test
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: debug-apk
path: app/build/outputs/apk/debug/app-debug.apk
- name: Sign Release APK
if: github.ref == 'refs/heads/main'
run: |
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > keystore.jks
./gradlew assembleRelease \
-Pandroid.injected.signing.store.file=keystore.jks \
-Pandroid.injected.signing.store.password="${{ secrets.KEYSTORE_PASSWORD }}" \
-Pandroid.injected.signing.key.alias="${{ secrets.KEY_ALIAS }}" \
-Pandroid.injected.signing.key.password="${{ secrets.KEY_PASSWORD }}"
```
---
## GitHub Flavored Markdown (GFM)
### Headings
```markdown
# H1 ## H2 ### H3 #### H4
```
### Code Blocks with Syntax Highlighting
```markdown
```python
def hello():
return "world"
```
```
### Tables
```markdown
| Column A | Column B | Column C |
|----------|:--------:|---------:|
| left | center | right |
```
### Task Lists
```markdown
- [x] Completed task
- [ ] Pending task
- [ ] Another task
```
### Alerts (GitHub only)
```markdown
> [!NOTE]
> Information users should know.
> [!WARNING]
> Critical content demanding attention.
> [!TIP]
> Helpful advice.
```
### Mermaid Diagrams
````markdown
```mermaid
graph TD
A[User Prompt] --> B[Analyzer]
B --> C[Planner]
C --> D[Code Generator]
D --> E{Validator}
E -->|Pass| F[Deploy]
E -->|Fail| G[Auto-Fix]
G --> D
```
````
---
## .gitignore Templates
### Python / FastAPI
```gitignore
__pycache__/
*.py[cod]
*.egg-info/
.env
.env.*
!.env.example
venv/
.venv/
dist/
build/
*.log
.pytest_cache/
.coverage
htmlcov/
```
### Node / React
```gitignore
node_modules/
dist/
build/
.env
.env.local
.env.*.local
*.log
.DS_Store
.cache/
.parcel-cache/
```
### Android
```gitignore
*.iml
.gradle/
local.properties
.idea/
.DS_Store
build/
captures/
*.jks
*.keystore
google-services.json
```
---
## GitHub Release Automation
```python
import requests
def create_release(owner, repo, tag, name, body, token):
url = f"https://api.github.com/repos/{owner}/{repo}/releases"
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json",
}
data = {
"tag_name": tag, # "v1.0.0"
"name": name, # "Release v1.0.0"
"body": body, # Markdown release notes
"draft": False,
"prerelease": False,
"generate_release_notes": True, # Auto-generate from PRs
}
return requests.post(url, json=data, headers=headers).json()
```