# GitHub Integration via LowCodeAPI

## Overview

GitHub is the world's leading developer platform with 1169+ API endpoints for managing repositories, issues, pull requests, actions, workflows, users, organizations, and more. Build powerful DevOps tools, automate workflows, and integrate with your development processes.

## Base Endpoint

```
https://api.lowcodeapi.com/github/
```

## Authentication

LowCodeAPI handles authentication automatically. You only need to:

1. **Sign up** at [GitHub](https://github.com)
2. **Create a Personal Access Token** or use OAuth
3. **Connect your account** in LowCodeAPI dashboard
4. **Use your `api_token`** in all requests

The `api_token` is your LowCodeAPI authentication token. LowCodeAPI will automatically:
- Fetch your GitHub access token from the database
- Apply it as a Bearer token to each request

**Auth Type**: OAuth2.0 (Bearer Token)

## API Categories

- **File Sharing & Collaboration** - Code repositories, version control, and collaboration tools

## Common Endpoints

### Category: Repositories

#### List Repositories

**Method**: `GET` | **LowCodeAPI Path**: `/user/repos`

**Full URL**:
```
https://api.lowcodeapi.com/github/user/repos?api_token={api_token}
```

**Description**: List repositories for the authenticated user

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `visibility` | string | No | Filter by visibility (all, public, private) |
| `sort` | string | No | Sort order (created, updated, full_name) |
| `per_page` | number | No | Results per page (max 100) |
| `page` | number | No | Page number |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/github/user/repos?visibility=all&per_page=30&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.github.com/en/rest/repos/repos#list-repositories-for-the-authenticated-user](https://docs.github.com/en/rest/repos/repos#list-repositories-for-the-authenticated-user)

---

#### Get Repository

**Method**: `GET` | **LowCodeAPI Path**: `/repos/owner/repo`

**Full URL**:
```
https://api.lowcodeapi.com/github/repos/owner/repo?owner={owner}&repo={repo}&api_token={api_token}
```

**Description**: Get a repository

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `owner` | string | Yes | Repository owner username |
| `repo` | string | Yes | Repository name |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/github/repos/owner/repo?owner=facebook&repo=react&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.github.com/en/rest/repos/repos#get-a-repository](https://docs.github.com/en/rest/repos/repos#get-a-repository)

---

#### Create Repository

**Method**: `POST` | **LowCodeAPI Path**: `/user/repos`

**Full URL**:
```
https://api.lowcodeapi.com/github/user/repos?api_token={api_token}
```

**Description**: Create a new repository for the authenticated user

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `name` | string | Yes | Repository name |
| `description` | string | No | Repository description |
| `private` | boolean | No | Whether repository is private |
| `auto_init` | boolean | No | Initialize with README |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/github/user/repos?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-new-repo",
    "description": "A new repository",
    "private": false,
    "auto_init": true
  }'
```

**Official Documentation**: [https://docs.github.com/en/rest/repos/repos#create-a-repository-for-the-authenticated-user](https://docs.github.com/en/rest/repos/repos#create-a-repository-for-the-authenticated-user)

---

### Category: Issues

#### List Issues

**Method**: `GET` | **LowCodeAPI Path**: `/repos/owner/repo/issues`

**Full URL**:
```
https://api.lowcodeapi.com/github/repos/owner/repo/issues?owner={owner}&repo={repo}&api_token={api_token}
```

**Description**: List issues in a repository

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `owner` | string | Yes | Repository owner |
| `repo` | string | Yes | Repository name |
| `state` | string | No | Filter by state (open, closed, all) |
| `labels` | string | No | Comma-separated label names |
| `per_page` | number | No | Results per page |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/github/repos/owner/repo/issues?owner=facebook&repo=react&state=open&per_page=10&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.github.com/en/rest/issues/issues#list-repository-issues](https://docs.github.com/en/rest/issues/issues#list-repository-issues)

---

#### Create Issue

**Method**: `POST` | **LowCodeAPI Path**: `/repos/owner/repo/issues`

**Full URL**:
```
https://api.lowcodeapi.com/github/repos/owner/repo/issues?owner={owner}&repo={repo}&api_token={api_token}
```

**Description**: Create an issue in a repository

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `owner` | string | Yes | Repository owner |
| `repo` | string | Yes | Repository name |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `title` | string | Yes | Issue title |
| `body` | string | No | Issue content |
| `labels` | array | No | Array of label names |
| `assignees` | array | No | Array of usernames to assign |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/github/repos/owner/repo/issues?owner=facebook&repo=react&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Bug: Component not rendering",
    "body": "Detailed description of the issue",
    "labels": ["bug", "high-priority"]
  }'
```

**Official Documentation**: [https://docs.github.com/en/rest/issues/issues#create-an-issue](https://docs.github.com/en/rest/issues/issues#create-an-issue)

---

### Category: Pull Requests

#### List Pull Requests

**Method**: `GET` | **LowCodeAPI Path**: `/repos/owner/repo/pulls`

**Full URL**:
```
https://api.lowcodeapi.com/github/repos/owner/repo/pulls?owner={owner}&repo={repo}&api_token={api_token}
```

**Description**: List pull requests in a repository

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `owner` | string | Yes | Repository owner |
| `repo` | string | Yes | Repository name |
| `state` | string | No | Filter by state (open, closed, all) |
| `per_page` | number | No | Results per page |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/github/repos/owner/repo/pulls?owner=facebook&repo=react&state=open&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.github.com/en/rest/pulls/pulls#list-pull-requests](https://docs.github.com/en/rest/pulls/pulls#list-pull-requests)

---

#### Create Pull Request

**Method**: `POST` | **LowCodeAPI Path**: `/repos/owner/repo/pulls`

**Full URL**:
```
https://api.lowcodeapi.com/github/repos/owner/repo/pulls?owner={owner}&repo={repo}&api_token={api_token}
```

**Description**: Create a pull request

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `owner` | string | Yes | Repository owner |
| `repo` | string | Yes | Repository name |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `title` | string | Yes | PR title |
| `head` | string | Yes | Branch name with changes |
| `base` | string | Yes | Branch to merge into |
| `body` | string | No | PR description |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/github/repos/owner/repo/pulls?owner=facebook&repo=react&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Add new feature",
    "head": "feature-branch",
    "base": "main",
    "body": "Description of changes"
  }'
```

**Official Documentation**: [https://docs.github.com/en/rest/pulls/pulls#create-a-pull-request](https://docs.github.com/en/rest/pulls/pulls#create-a-pull-request)

---

### Category: Actions

#### Get GitHub Actions Cache Usage

**Method**: `GET` | **LowCodeAPI Path**: `/orgs/org/actions/cache/usage`

**Full URL**:
```
https://api.lowcodeapi.com/github/orgs/org/actions/cache/usage?org={org}&api_token={api_token}
```

**Description**: Get GitHub Actions cache usage for an organization

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `org` | string | Yes | Organization name |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/github/orgs/org/actions/cache/usage?org=myorg&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.github.com/rest/reference/actions#get-github-actions-cache-usage-for-an-organization](https://docs.github.com/rest/reference/actions#get-github-actions-cache-usage-for-an-organization)

---

## Usage Examples

### Example 1: Repository Management

This example demonstrates managing GitHub repositories:

```bash
# Step 1: List all your repositories
# No ID required - lists authenticated user's repos
curl -X GET "https://api.lowcodeapi.com/github/user/repos?visibility=all&per_page=50&api_token=YOUR_API_TOKEN"

# Step 2: Create a new repository
# No ID required - creates a new repo and returns repo details
curl -X POST "https://api.lowcodeapi.com/github/user/repos?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-awesome-project",
    "description": "Built with LowCodeAPI",
    "private": false
  }'

# Step 3: Get specific repository details
# Replace OWNER and REPO with actual values (e.g., facebook/react)
curl -X GET "https://api.lowcodeapi.com/github/repos/owner/repo?owner=OWNER&repo=REPO&api_token=YOUR_API_TOKEN"
```

### Example 2: Issue and PR Workflow

This example shows working with issues and pull requests:

```bash
# Step 1: List open issues in a repository
# Replace OWNER and REPO with actual values
curl -X GET "https://api.lowcodeapi.com/github/repos/owner/repo/issues?owner=OWNER&repo=REPO&state=open&per_page=10&api_token=YOUR_API_TOKEN"

# Step 2: Create a new issue
# Use the same OWNER and REPO from Step 1
curl -X POST "https://api.lowcodeapi.com/github/repos/owner/repo/issues?owner=OWNER&repo=REPO&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Feature request: Add dark mode",
    "body": "It would be great to have dark mode support",
    "labels": ["enhancement"]
  }'

# Step 3: List pull requests
# Use the same OWNER and REPO
curl -X GET "https://api.lowcodeapi.com/github/repos/owner/repo/pulls?owner=OWNER&repo=REPO&state=open&api_token=YOUR_API_TOKEN"

# Step 4: Create a pull request
# Use the same OWNER and REPO
curl -X POST "https://api.lowcodeapi.com/github/repos/owner/repo/pulls?owner=OWNER&repo=REPO&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Implement feature X",
    "head": "feature-x-branch",
    "base": "main",
    "body": "Implements the new feature X"
  }'
```

### Example 3: Organization Management

This example demonstrates organization-level operations:

```bash
# Step 1: Get Actions cache usage for an organization
# Replace ORG with the organization name
curl -X GET "https://api.lowcodeapi.com/github/orgs/org/actions/cache/usage?org=ORG&api_token=YOUR_API_TOKEN"

# Step 2: List repositories with cache usage
# Replace ORG with the organization name
curl -X GET "https://api.lowcodeapi.com/github/orgs/org/actions/cache/usage-by-repository?org=ORG&per_page=10&api_token=YOUR_API_TOKEN"
```

## Complete Endpoint Reference

For a complete list of all endpoints and their parameters, refer to:
- **OpenAPI Definition**: `https://backend.lowcodeapi.com/github/definition`
- **Official Provider Documentation**: [https://docs.github.com/en/rest](https://docs.github.com/en/rest)

## Rate Limits & Best Practices

- **Rate limits**: 5000 requests/hour for authenticated requests
- **Best practice**: Use pagination for large result sets
- **Best practice**: Cache data that doesn't change frequently
- **Best practice**: Use conditional requests with ETag headers
- **Best practice**: Batch operations when possible

## Error Handling

Standard HTTP status codes apply:
- **200** - Success
- **400** - Bad request
- **401** - Authentication failed
- **403** - Forbidden
- **404** - Resource not found
- **422** - Validation failed
- **429** - Rate limit exceeded