Create GitHub Pull Requests Feed

User Intent

"How do I sync GitHub pull requests from a repository? Show me GitHub Pull Requests feed configuration."

Operation

SDK Method: createFeed() with FeedTypes.PullRequest Auth: GitHub personal access token or OAuth


Code Example (TypeScript)

import { Graphlit } from 'graphlit-client';
import {
  FeedTypes,
  FeedServiceTypes,
  GitHubPullRequestsFeedPropertiesInput,
  GitHubPullRequestAuthenticationTypes,
  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: GitHubPullRequestAuthenticationTypes.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 Pull Requests',
  type: FeedTypes.PullRequest,
  pullRequest: {
    type: FeedServiceTypes.GitHubPullRequests,
    github: {
      authorizationId,
      authenticationType: GitHubPullRequestAuthenticationTypes.OAuth,
      repositoryOwner: repositoryOwner!,
      repositoryName: repositoryName!,
      readLimit: 100,
    },
  },
  // Optional: add workflow for content processing
  // workflow: { id: workflow.createWorkflow.id }
});

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

Configuration

repositoryOwner: GitHub username or organization repositoryName: Repository name authorizationId: Stored GitHub credential identifier (OAuth recommended) authenticationType: GitHubPullRequestAuthenticationTypes.OAuth or GitHubPullRequestAuthenticationTypes.PersonalAccessToken readLimit: Number of pull requests 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

  • Pull request numbers and titles

  • PR descriptions and bodies

  • Status (open/closed/merged)

  • Base and head branches

  • Draft status

  • Merge status and commit SHA

  • Merge timestamps

  • File change statistics (files changed, additions, deletions)

  • Labels and tags

  • Reviewer information

  • Author information


Use Cases

Code Review Tracking:

repositoryOwner: 'your-org',
repositoryName: 'backend-api',
readLimit: 200  // Track last 200 PRs

PR Workflow Analysis:

repositoryOwner: 'facebook',
repositoryName: 'react',
readLimit: 500

Merge Velocity Monitoring:

repositoryOwner: 'company',
repositoryName: 'product-repo'

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 pull request creates content with PullRequestMetadata:

  • identifier: PR number

  • title: PR title

  • project: Repository name

  • team: Repository owner

  • status: PR state (open/closed/merged)

  • type: PR type (if specified)

  • baseBranch: Target branch

  • headBranch: Source branch

  • isDraft: Whether PR is a draft

  • isMergeable: Whether PR can be merged

  • mergeCommitSha: SHA of merge commit (if merged)

  • mergedAt: Timestamp when merged

  • filesChanged: Number of files modified

  • additions: Lines added

  • deletions: Lines deleted

  • labels: Associated labels


Once synced, you can search and filter pull requests:

Search by status:

const openPRs = await graphlit.queryContents({
  filter: {
    types: [ContentTypes.PullRequest],
    contents: [{
      pullRequest: {
        status: 'open'
      }
    }]
  }
});

Search by branch:

const mainPRs = await graphlit.queryContents({
  filter: {
    types: [ContentTypes.PullRequest],
    contents: [{
      pullRequest: {
        baseBranch: 'main'
      }
    }]
  }
});

Last updated

Was this helpful?