Skip to content

Epic: Claude-Powered GitHub Issue Processor - Stage 1: Authentication, Logging & Project Setup #1

Closed

Description

@integry

General Goal of the Epic

To create an automated system that monitors GitHub issues, uses Anthropic's Claude Code to generate solutions, and automates the Git workflow including PR creation. This system aims to streamline development by offloading specific coding tasks to an AI agent, with human oversight for review and merging.

Current Stage (Issue 1 of N)

This is the first foundational issue in a series to build the Automated GitHub Issue Processor.

  • What's being done in this issue: Establish secure authentication mechanisms for GitHub and Claude, set up a basic project structure (Node.js preferred), and implement initial configurable logging and basic error handling utilities.
  • What's been done: This is the starting point.
  • What's remaining: Subsequent issues will cover issue detection, task queuing, Git environment management, Claude Code integration, automated PR creation, and more advanced features like pre-PR checks and optimized context provisioning.

Task Details

This issue focuses on creating the bedrock for the entire system:

  1. Project Setup:
    • Initialize a new Node.js project (npm init -y).
    • Define a basic directory structure (e.g., src/, scripts/, config/, utils/).
  2. GitHub Authentication (Node.js):
    • Guidance on creating a new GitHub App with the necessary permissions (detailed below).
    • Develop a Node.js module (e.g., src/auth/githubAuth.js) to:
      • Read GitHub App ID, Installation ID, and Private Key from environment variables (GH_APP_ID, GH_INSTALLATION_ID, GH_PRIVATE_KEY_PATH).
      • Generate short-lived installation access tokens using these credentials.
      • Provide a utility function to get an authenticated Octokit instance or just the access token.
    • Document the process for obtaining these credentials and securely setting them as environment variables.
    • Relevant Proposal Section: 3.1
  3. Claude Code Authentication Preparation:
    • Document the manual process for end-users/operators to perform claude login to generate the ~/.config/claude-code/auth.json file.
    • This file will be crucial for non-interactive Claude Code CLI execution under a Claude Max plan. The strategy for securely mounting this into a Docker container will be detailed in the Claude execution issue.
    • Relevant Proposal Section: 3.2
  4. Logging Utility (Node.js):
    • Implement a simple, reusable logging module (e.g., src/utils/logger.js) using a library like pino or winston.
    • The logger should support:
      • Multiple log levels (DEBUG, INFO, WARN, ERROR).
      • Configuration of log level via an environment variable (e.g., LOG_LEVEL).
      • Structured JSON output for easier parsing by log management systems.
      • Timestamping for all log messages.
    • Relevant Proposal Section: 4.2
  5. Basic Error Handling Framework:
    • Establish conventions for error handling within the project.
    • Promote consistent use of try-catch blocks for operations that can fail.
    • Ensure errors are logged with sufficient context (e.g., stack traces, relevant IDs).
    • Relevant Proposal Section: 4.1
  6. Configuration Management:
    • Implement a basic mechanism for loading non-sensitive configurations (e.g., using a config.js file that can be extended with environment variables via dotenv).
    • Reiterate that sensitive credentials must always be loaded from environment variables or a secrets management system, never hardcoded.

GitHub App Permissions Required

The GitHub App should be configured with the following minimum permissions:

  • Repository Permissions:
    • Contents: Read & Write (for cloning, fetching, creating commits, pushing branches)
    • Metadata: Read (default, for repository information)
  • Account Permissions (for the app itself, not user permissions):
    • Issues: Read & Write (for reading issue details, adding/removing labels, creating comments)
    • Pull requests: Read & Write (for creating pull requests, adding comments to PRs)

Acceptance Criteria

  • A Node.js project structure is created.
  • A githubAuth.js module can successfully generate a GitHub installation access token.
  • A logger.js module provides basic structured logging capabilities.
  • Documentation exists for setting up GitHub App credentials and auth.json for Claude.
  • Basic error handling patterns are demonstrated.

Activity

  1. integry commented on May 23, 2025

    @integry
    OwnerAuthor

    Suggested Implementation Snippets (Node.js)

    This provides a starting point for some of the core components outlined in this issue.

    1. GitHub Authentication (src/auth/githubAuth.js)

    First, install necessary packages:

    npm install @octokit/core @octokit/auth-app jsonwebtoken dotenv
    // src/auth/githubAuth.js
    import { Octokit } from '@octokit/core';
    import { createAppAuth } from '@octokit/auth-app';
    import fs from 'fs';
    import path from 'path';
    import 'dotenv/config'; // Ensure .env variables are loaded
    
    const appId = process.env.GH_APP_ID;
    const privateKeyPath = process.env.GH_PRIVATE_KEY_PATH; // e.g., './your-private-key.pem'
    const installationId = process.env.GH_INSTALLATION_ID;
    
    let privateKey;
    try {
        privateKey = fs.readFileSync(path.resolve(privateKeyPath), 'utf8');
    } catch (error) {
        console.error('Failed to read GitHub App private key:', error.message);
        console.error('Ensure GH_PRIVATE_KEY_PATH is set correctly in your .env file and points to a valid private key file.');
        process.exit(1);
    }
    
    if (!appId || !privateKey || !installationId) {
        console.error('GH_APP_ID, GH_PRIVATE_KEY_PATH, and GH_INSTALLATION_ID must be set in .env file.');
        process.exit(1);
    }
    
    const appOctokit = new Octokit({
        authStrategy: createAppAuth,
        auth: {
            appId,
            privateKey,
            installationId,
        },
    });
    
    /**
     * Gets an installation access token for the GitHub App.
     * @returns {Promise<string>} The installation access token.
     */
    export async function getGitHubInstallationToken() {
        try {
            const { token } = await appOctokit.auth({ type: "installation" });
            return token;
        } catch (error) {
            console.error("Error getting GitHub installation token:", error);
            throw error;
        }
    }
    
    /**
     * Gets an Octokit instance authenticated as an installation.
     * @returns {Promise<Octokit>} Authenticated Octokit instance.
     */
    export async function getAuthenticatedOctokit() {
        const token = await getGitHubInstallationToken();
        return new Octokit({ auth: token });
    }

    2. Logging Utility (src/utils/logger.js)

    Install pino:

    npm install pino pino-pretty
    // src/utils/logger.js
    import pino from 'pino';
    
    const logLevel = process.env.LOG_LEVEL || 'info';
    
    const logger = pino({
        level: logLevel,
        transport: process.env.NODE_ENV !== 'production' ? {
            target: 'pino-pretty',
            options: {
                colorize: true,
                translateTime: 'SYS:standard',
                ignore: 'pid,hostname',
            },
        } : undefined,
    });
    
    export default logger;

    3. Basic Configuration (config.js or similar)
    Use dotenv to manage environment variables. Create a .env file in the root:

    # .env
    GH_APP_ID=your_app_id
    GH_PRIVATE_KEY_PATH=./path/to/your-app-private-key.pem
    GH_INSTALLATION_ID=your_installation_id
    LOG_LEVEL=info
    # Add other configurations as needed

    Ensure your main script loads dotenv early: import 'dotenv/config';

    4. Claude auth.json
    Users will need to run claude login and ensure ~/.config/claude-code/auth.json is present on the machine where the Dockerized Claude instances will be orchestrated from. This file contains sensitive OAuth tokens and should be permission-restricted.


    This comment provides initial code suggestions. Implementation details may vary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions