Merge branch 'main' into feat/chatbot_provider

Resolve conflicts in package.json by:
- Keeping TypeScript support (.{js,ts}) for test patterns
- Preserving chatbot-specific test script
- Maintaining compatibility with new TypeScript infrastructure

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jonathan Flatt
2025-05-27 20:04:34 -05:00
10 changed files with 3021 additions and 73 deletions

4
.gitignore vendored
View File

@@ -24,6 +24,10 @@ pids
coverage/
test-results/
# TypeScript build artifacts
dist/
*.tsbuildinfo
# Temporary files
tmp/
temp/

View File

@@ -18,17 +18,25 @@ This repository contains a webhook service that integrates Claude with GitHub, a
## Build & Run Commands
### TypeScript Build Commands
- **Build TypeScript**: `npm run build` (compiles to `dist/` directory)
- **Build TypeScript (watch mode)**: `npm run build:watch`
- **Type checking only**: `npm run typecheck` (no compilation)
- **Clean build artifacts**: `npm run clean`
### Setup and Installation
- **Initial setup**: `./scripts/setup.sh`
- **Setup secure credentials**: `./scripts/setup/setup-secure-credentials.sh`
- **Start with Docker (recommended)**: `docker compose up -d`
- **Start the server locally**: `npm start`
- **Development mode with auto-restart**: `npm run dev`
- **Start production build**: `npm start` (runs compiled JavaScript from `dist/`)
- **Start development build**: `npm run start:dev` (runs JavaScript directly from `src/`)
- **Development mode with TypeScript**: `npm run dev` (uses ts-node)
- **Development mode with auto-restart**: `npm run dev:watch` (uses nodemon + ts-node)
- **Start on specific port**: `./scripts/runtime/start-api.sh` (uses port 3003)
- **Run tests**: `npm test`
- Run specific test types:
- Unit tests: `npm run test:unit`
- End-to-end tests: `npm run test:e2e`
- Unit tests: `npm run test:unit` (supports both `.js` and `.ts` files)
- End-to-end tests: `npm run test:e2e` (supports both `.js` and `.ts` files)
- Test with coverage: `npm run test:coverage`
- Watch mode: `npm run test:watch`
@@ -205,9 +213,34 @@ The `awsCredentialProvider.js` utility handles credential retrieval and rotation
- `PR_REVIEW_MAX_WAIT_MS`: Maximum time to wait for stale in-progress check suites before considering them failed (default: `"1800000"` = 30 minutes).
- `PR_REVIEW_CONDITIONAL_TIMEOUT_MS`: Time to wait for conditional jobs that never start before skipping them (default: `"300000"` = 5 minutes).
## TypeScript Infrastructure
The project is configured with TypeScript for enhanced type safety and developer experience:
### Configuration Files
- **tsconfig.json**: TypeScript compiler configuration with strict mode enabled
- **eslint.config.js**: ESLint configuration with TypeScript support and strict rules
- **jest.config.js**: Jest configuration with ts-jest for TypeScript test support
- **babel.config.js**: Babel configuration for JavaScript file transformation
### Build Process
- TypeScript source files in `src/` compile to JavaScript in `dist/`
- Support for both `.js` and `.ts` files during the transition period
- Source maps enabled for debugging compiled code
- Watch mode available for development with automatic recompilation
### Migration Strategy
- **Phase 1** (Current): Infrastructure setup with TypeScript tooling
- **Phase 2** (Future): Gradual conversion of JavaScript files to TypeScript
- **Backward Compatibility**: Existing JavaScript files continue to work during transition
## Code Style Guidelines
- JavaScript with Node.js
- **TypeScript/JavaScript** with Node.js (ES2022 target)
- Use async/await for asynchronous operations
- Comprehensive error handling and logging
- camelCase variable and function naming
- Input validation and sanitization for security
- Input validation and sanitization for security
- **TypeScript specific**:
- Strict mode enabled for all TypeScript files
- Interface definitions preferred over type aliases
- Type imports when importing only for types
- No explicit `any` types (use `unknown` or proper typing)

View File

@@ -40,9 +40,22 @@ WORKDIR /app
# Copy package files and install dependencies
COPY package*.json ./
RUN npm install --omit=dev
COPY tsconfig.json ./
COPY babel.config.js ./
# Copy application code
# Install all dependencies (including dev for build)
RUN npm ci
# Copy source code
COPY src/ ./src/
# Build TypeScript
RUN npm run build
# Remove dev dependencies to reduce image size
RUN npm prune --omit=dev && npm cache clean --force
# Copy remaining application files
COPY . .
# Consolidate permission changes into a single RUN instruction

12
babel.config.js Normal file
View File

@@ -0,0 +1,12 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: '20'
}
}
]
]
};

View File

@@ -1,4 +1,6 @@
const js = require('@eslint/js');
const tseslint = require('@typescript-eslint/eslint-plugin');
const tsparser = require('@typescript-eslint/parser');
module.exports = [
js.configs.recommended,
@@ -65,8 +67,47 @@ module.exports = [
'no-buffer-constructor': 'error'
}
},
// TypeScript files configuration
{
files: ['test/**/*.js', '**/*.test.js'],
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: tsparser,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'commonjs',
project: './tsconfig.json'
}
},
plugins: {
'@typescript-eslint': tseslint
},
rules: {
// Disable base rules that are covered by TypeScript equivalents
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { 'argsIgnorePattern': '^_', 'varsIgnorePattern': '^_', 'caughtErrorsIgnorePattern': '^_' }],
// TypeScript specific rules
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-unnecessary-condition': 'warn',
// Style rules
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }]
}
},
// Test files (JavaScript and TypeScript)
{
files: ['test/**/*.js', '**/*.test.js', 'test/**/*.ts', '**/*.test.ts'],
languageOptions: {
globals: {
jest: 'readonly',
@@ -81,7 +122,8 @@ module.exports = [
}
},
rules: {
'no-console': 'off'
'no-console': 'off',
'@typescript-eslint/no-explicit-any': 'off' // Allow any in tests for mocking
}
}
];

View File

@@ -1,17 +1,37 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: [
'**/test/unit/**/*.test.js',
'**/test/integration/**/*.test.js',
'**/test/e2e/scenarios/**/*.test.js'
'**/test/unit/**/*.test.{js,ts}',
'**/test/integration/**/*.test.{js,ts}',
'**/test/e2e/scenarios/**/*.test.{js,ts}'
],
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.js$': 'babel-jest'
},
moduleFileExtensions: ['ts', 'js', 'json'],
collectCoverage: true,
coverageReporters: ['text', 'lcov'],
coverageDirectory: 'coverage',
collectCoverageFrom: [
'src/**/*.{js,ts}',
'!src/**/*.d.ts',
'!**/node_modules/**',
'!**/dist/**'
],
testTimeout: 30000, // Some tests might take longer due to container initialization
verbose: true,
reporters: [
'default',
['jest-junit', { outputDirectory: 'test-results/jest', outputName: 'results.xml' }]
],
// For TypeScript tests, prefer importing from '@jest/globals' instead of relying on globals
// e.g., import { describe, it, expect } from '@jest/globals'
globals: {
'ts-jest': {
useESM: false,
tsconfig: 'tsconfig.json'
}
}
};

2812
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,17 +2,23 @@
"name": "claude-github-webhook",
"version": "1.0.0",
"description": "A webhook endpoint for Claude to perform git and GitHub actions",
"main": "src/index.js",
"main": "dist/index.js",
"scripts": {
"start": "node src/index.js",
"dev": "nodemon src/index.js",
"build": "tsc",
"build:watch": "tsc --watch",
"start": "node dist/index.js",
"start:dev": "node src/index.js",
"dev": "ts-node src/index.js",
"dev:watch": "nodemon --exec ts-node src/index.js",
"clean": "rm -rf dist",
"typecheck": "tsc --noEmit",
"test": "jest",
"test:unit": "jest --testMatch='**/test/unit/**/*.test.js'",
"test:chatbot": "jest --testMatch='**/test/unit/providers/**/*.test.js' --testMatch='**/test/unit/controllers/chatbotController.test.js'",
"test:e2e": "jest --testMatch='**/test/e2e/**/*.test.js'",
"test:unit": "jest --testMatch='**/test/unit/**/*.test.{js,ts}'",
"test:chatbot": "jest --testMatch='**/test/unit/providers/**/*.test.{js,ts}' --testMatch='**/test/unit/controllers/chatbotController.test.{js,ts}'",
"test:e2e": "jest --testMatch='**/test/e2e/**/*.test.{js,ts}'",
"test:coverage": "jest --coverage",
"test:watch": "jest --watch",
"test:ci": "jest --ci --coverage --testPathPattern='test/(unit|integration).*\\.test\\.js$'",
"test:ci": "jest --ci --coverage --testPathPattern='test/(unit|integration).*\\.test\\.(js|ts)$'",
"pretest": "./scripts/utils/ensure-test-dirs.sh",
"lint": "eslint src/ test/ --fix",
"lint:check": "eslint src/ test/",
@@ -34,7 +40,16 @@
"pino-pretty": "^13.0.0"
},
"devDependencies": {
"@babel/core": "^7.27.3",
"@babel/preset-env": "^7.27.2",
"@jest/globals": "^30.0.0-beta.3",
"@types/body-parser": "^1.19.5",
"@types/express": "^5.0.2",
"@types/jest": "^29.5.14",
"@types/node": "^22.15.23",
"@typescript-eslint/eslint-plugin": "^8.33.0",
"@typescript-eslint/parser": "^8.33.0",
"babel-jest": "^29.7.0",
"eslint": "^9.27.0",
"eslint-config-node": "^4.1.0",
"husky": "^9.1.7",
@@ -42,7 +57,10 @@
"jest-junit": "^16.0.0",
"nodemon": "^3.0.1",
"prettier": "^3.0.0",
"supertest": "^7.1.1"
"supertest": "^7.1.1",
"ts-jest": "^29.3.4",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
},
"engines": {
"node": ">=20.0.0"

49
src/types.ts Normal file
View File

@@ -0,0 +1,49 @@
// TypeScript type definitions for the claude-github-webhook project
// This file establishes the TypeScript infrastructure
export interface GitHubWebhookPayload {
action?: string;
issue?: {
number: number;
title: string;
body: string;
user: {
login: string;
};
};
comment?: {
id: number;
body: string;
user: {
login: string;
};
};
repository?: {
full_name: string;
name: string;
owner: {
login: string;
};
};
pull_request?: {
number: number;
title: string;
body: string;
user: {
login: string;
};
};
}
export interface ClaudeApiResponse {
success: boolean;
response?: string;
error?: string;
}
export interface ContainerExecutionOptions {
command: string;
repository: string;
timeout?: number;
environment?: Record<string, string>;
}

49
tsconfig.json Normal file
View File

@@ -0,0 +1,49 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"lib": ["ES2022"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"removeComments": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"exactOptionalPropertyTypes": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"noFallthroughCasesInSwitch": true,
"noErrorTruncation": true,
"types": ["node", "jest"]
},
"include": [
"src/**/*",
"test/**/*"
],
"exclude": [
"node_modules",
"dist",
"coverage",
"test-results"
],
"ts-node": {
"files": true,
"compilerOptions": {
"module": "CommonJS"
}
}
}