# Create GitHub Commits Feed

## User Intent

"How do I sync GitHub commits from a repository? Show me GitHub Commits feed configuration."

## Operation

**SDK Method**: `createFeed()` with FeedTypes.Commit\
**Auth**: GitHub personal access token or OAuth

***

## Code Example (TypeScript)

```typescript
import { Graphlit } from 'graphlit-client';
import {
  FeedTypes,
  FeedServiceTypes,
  GitHubCommitsFeedPropertiesInput,
  GitHubCommitAuthenticationTypes,
  GitHubRepositoriesInput,
} from 'graphlit-client/dist/generated/graphql-types';

const graphlit = new Graphlit();

// Use the GitHub credential stored in the Developer Portal
const authorizationId = process.env.GRAPHLIT_GITHUB_AUTH_ID!;

const repositoriesInput: GitHubRepositoriesInput = {
  authenticationType: GitHubCommitAuthenticationTypes.OAuth,
  authorizationId,
};

// Enumerate repositories this credential can access
const repositoriesResponse = await graphlit.queryGitHubRepositories(repositoriesInput);
const repositories = repositoriesResponse.githubRepositories?.results ?? [];

if (repositories.length === 0) {
  throw new Error('No GitHub repositories available for the authorized account');
}

const { repositoryOwner, repositoryName } = repositories[0]!;
console.log(`Using GitHub repository: ${repositoryOwner}/${repositoryName}`);

const feed = await graphlit.createFeed({
  name: 'Backend API Commits',
  type: FeedTypes.Commit,
  commit: {
    type: FeedServiceTypes.GitHubCommits,
    github: {
      authorizationId,
      authenticationType: GitHubCommitAuthenticationTypes.OAuth,
      repositoryOwner: repositoryOwner!,
      repositoryName: repositoryName!,
      branch: 'main',  // Optional: defaults to default branch
      readLimit: 100,
    },
  },
  // Optional: add workflow for content processing
  // workflow: { id: workflow.createWorkflow.id }
});

console.log(`Created GitHub Commits feed: ${feed.createFeed.id}`);
```

***

## Configuration

**repositoryOwner**: GitHub username or organization\
**repositoryName**: Repository name\
**authorizationId**: Stored GitHub credential identifier (OAuth recommended)\
**authenticationType**: `GitHubCommitAuthenticationTypes.OAuth` or `GitHubCommitAuthenticationTypes.PersonalAccessToken`\
**branch**: Specific branch to sync (defaults to repository's default branch)\
**readLimit**: Number of commits to sync (defaults to 100)

***

## GitHub Token Setup

1. Developer Portal → Connectors → GitHub
2. Complete OAuth flow with required scopes (`repo` for private repos, public repo access for public repos)
3. Store the resulting credential; note the `authorizationId`
4. Use `queryGitHubRepositories` to confirm repository access before creating feeds

***

## What Gets Synced

* Commit SHA hashes
* Commit messages
* Author information and dates
* Committer information and dates
* Branch information
* Parent commit SHAs
* File change statistics (files changed, additions, deletions)
* Associated pull request numbers (if applicable)
* Labels and tags

***

## Use Cases

**Code Review Analysis**:

```typescript
repositoryOwner: 'your-org',
repositoryName: 'backend-api',
branch: 'develop'
```

**Developer Activity Tracking**:

```typescript
repositoryOwner: 'facebook',
repositoryName: 'react',
branch: 'main',
readLimit: 500
```

**Commit History Search**:

```typescript
repositoryOwner: 'company',
repositoryName: 'monorepo',
// No branch specified - uses default branch
```

***

## OAuth vs Personal Access Token

**Use OAuth when:**

* Building multi-user applications
* Need user-specific permissions
* Want connector-based auth with automatic token refresh

**Use Personal Access Token when:**

* Single-user automation
* Service account access
* Simpler setup for personal projects

***

## Metadata Structure

Each synced commit creates content with `CommitMetadata`:

* `sha`: Commit hash
* `message`: Commit message
* `project`: Repository name
* `team`: Repository owner
* `branch`: Branch name
* `parentShas`: Array of parent commit SHAs
* `filesChanged`: Number of files modified
* `additions`: Lines added
* `deletions`: Lines deleted
* `pullRequestNumber`: Associated PR number (if applicable)
* `authorDate`: When the commit was authored
* `committerDate`: When the commit was committed
* `labels`: Associated labels/tags

***

## Related

* [GitHub Pull Requests Feed](/api-guides/use-cases/feeds/project-management/feed-create-github-pull-requests.md) - Sync pull requests
* [GitHub Issues Feed](/api-guides/use-cases/feeds/project-management/feed-create-github-issues.md) - Sync repository issues
* [GitHub Repository Feed](/api-guides/use-cases/feeds/cloud-storage/feed-create-github.md) - Sync repo files


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.graphlit.dev/api-guides/use-cases/feeds/project-management/feed-create-github-commits.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
