Adds a Scripts CI workflow that runs npm ci, build, and test in scripts/ on every pull request and on pushes to main, so Dependabot security PRs can be gated by CI (remediation-path campaign, KP-1196126). Also renames scripts/jest.config.js to jest.config.cjs: package.json sets "type": "module", so Jest's CommonJS config failed to load and npm test errored on main. No config content changed.
GitHub Issue Automation Scripts
TypeScript modules for automated GitHub issue management using AWS Bedrock AI.
Architecture
scripts/
├── data_models.ts # Data structures and interfaces
├── bedrock_classifier.ts # AWS Bedrock integration for classification
├── assign_labels.ts # Label assignment logic
├── detect_duplicates.ts # Duplicate detection using AI
├── retry_utils.ts # Retry logic with exponential backoff
├── rate_limit_utils.ts # GitHub API rate limit handling
├── workflow_summary.ts # Workflow summary generation
├── triage_issue.ts # Main triage orchestration script
├── close_duplicates.ts # Duplicate closer script
└── close_stale.ts # Stale issue closer script
Modules
Core Data Models (data_models.ts)
Defines the data structures used throughout the system:
ClassificationResult- AI classification outputDuplicateMatch- Duplicate issue informationLabelTaxonomy- Complete label taxonomyIssueData- GitHub issue data
Bedrock Classifier (bedrock_classifier.ts)
Integrates with AWS Bedrock Claude Sonnet 4.5 for issue classification:
async function classifyIssue(
issueTitle: string,
issueBody: string,
labelTaxonomy: LabelTaxonomy
): Promise<ClassificationResult>
Features:
- Constructs prompts with label taxonomy
- Parses AI responses
- Handles errors gracefully
- Uses retry logic for reliability
Label Assignment (assign_labels.ts)
Assigns labels to GitHub issues with validation:
async function assignLabels(
owner: string,
repo: string,
issueNumber: number,
recommendedLabels: string[],
githubToken: string,
taxonomy: LabelTaxonomy
): Promise<boolean>
Features:
- Validates labels against taxonomy
- Filters out invalid labels
- Always adds "pending-triage" label
- Handles GitHub API errors
Duplicate Detection (detect_duplicates.ts)
Detects duplicate issues using semantic similarity:
async function detectDuplicates(
newTitle: string,
newBody: string,
owner: string,
repo: string,
currentIssueNumber: number,
githubToken: string
): Promise<DuplicateMatch[]>
Features:
- Fetches existing open issues (last 90 days)
- Processes in batches of 10
- Uses AI for semantic similarity
- Returns matches with score > 0.80
- Generates formatted comments
Retry Utilities (retry_utils.ts)
Provides retry logic with exponential backoff:
async function retryWithBackoff<T>(
fn: () => Promise<T>,
options?: RetryOptions
): Promise<T>
Configuration:
- Max retries: 3
- Base delay: 1 second
- Max delay: 8 seconds
- Retryable errors: ThrottlingException, ServiceUnavailable, etc.
Rate Limit Utilities (rate_limit_utils.ts)
Handles GitHub API rate limiting:
async function checkRateLimit(client: Octokit): Promise<void>
async function processBatch<T, R>(
items: T[],
batchSize: number,
processor: (item: T) => Promise<R>,
delayMs?: number
): Promise<R[]>
Features:
- Monitors rate limit status
- Pauses when approaching limits
- Processes items in batches
- Adds delays between batches
Workflow Summary (workflow_summary.ts)
Generates workflow run summaries:
function createSummary(summary: WorkflowSummary): void
function logError(
errors: WorkflowSummary["errors"],
step: string,
error: any,
issueNumber?: number
): void
Features:
- Creates formatted summaries
- Tracks success/failure counts
- Logs detailed error information
- Writes to GitHub Actions summary
Main Scripts
Issue Triage (triage_issue.ts)
Orchestrates the complete triage process:
- Classifies issue using Bedrock
- Assigns labels
- Detects duplicates
- Posts duplicate comments
- Adds duplicate label if needed
Environment Variables:
ISSUE_NUMBER- Issue number to triageISSUE_TITLE- Issue titleISSUE_BODY- Issue bodyREPOSITORY_OWNER- Repository ownerREPOSITORY_NAME- Repository nameGITHUB_TOKEN- GitHub API tokenAWS_ACCESS_KEY_ID- AWS access keyAWS_SECRET_ACCESS_KEY- AWS secret keyAWS_REGION- AWS region (optional)
Close Duplicates (close_duplicates.ts)
Closes issues marked as duplicate for 3+ days:
- Fetches issues with "duplicate" label
- Checks label application date
- Closes issues older than threshold
- Posts closing comment
Environment Variables:
REPOSITORY_OWNER- Repository ownerREPOSITORY_NAME- Repository nameGITHUB_TOKEN- GitHub API token
Close Stale (close_stale.ts)
Closes inactive issues with "pending-response" label:
- Fetches issues with "pending-response" label
- Checks last activity date
- Closes issues inactive for 7+ days
- Posts closing comment
Environment Variables:
REPOSITORY_OWNER- Repository ownerREPOSITORY_NAME- Repository nameGITHUB_TOKEN- GitHub API token
Development
Setup
npm install
Build
npm run build
This compiles TypeScript to JavaScript in the dist/ directory.
Clean
npm run clean
Local Testing
You can test scripts locally by setting environment variables:
export ISSUE_NUMBER=123
export ISSUE_TITLE="Test issue"
export ISSUE_BODY="Test description"
export REPOSITORY_OWNER="owner"
export REPOSITORY_NAME="repo"
export GITHUB_TOKEN="your-token"
export AWS_ACCESS_KEY_ID="your-key"
export AWS_SECRET_ACCESS_KEY="your-secret"
export AWS_REGION="us-east-1"
node dist/triage_issue.js
Configuration
Thresholds
Duplicate Closure:
// close_duplicates.ts
const DAYS_THRESHOLD = 3;
Stale Issues:
// close_stale.ts
const DAYS_THRESHOLD = 7;
Duplicate Similarity:
// detect_duplicates.ts
const SIMILARITY_THRESHOLD = 0.8;
Batch Size:
// detect_duplicates.ts
const BATCH_SIZE = 10;
Search Window:
// detect_duplicates.ts
const DAYS_TO_SEARCH = 90;
Bedrock Configuration
// bedrock_classifier.ts
const MODEL_ID = "us.anthropic.claude-sonnet-4-20250514-v1:0"; // Inference profile
const MAX_TOKENS = 2048;
const TEMPERATURE = 0.3;
const TOP_P = 0.9;
Error Handling
All modules implement comprehensive error handling:
- Retry Logic - Automatic retries with exponential backoff
- Graceful Degradation - Continue processing on non-critical errors
- Detailed Logging - Log all errors with context
- Fault Isolation - Individual failures don't stop batch processing
- Workflow Summaries - Track and report all errors
Testing
Unit Tests
(To be implemented)
npm test
Integration Tests
Test against a real repository:
- Create a test repository
- Set up AWS credentials
- Run workflows manually
- Verify results
Performance
Optimization Strategies
- Batch Processing - Process issues in batches to reduce API calls
- Rate Limit Handling - Proactively check and respect rate limits
- Caching - Fetch existing issues once per run
- Parallel Processing - Process batches in parallel where possible
- Filtering - Only compare against recent issues (90 days)
Expected Performance
- Issue Triage: 10-15 seconds per issue
- Duplicate Detection: 5-10 seconds per batch of 10 issues
- Duplicate Closure: 2-3 seconds per issue
- Stale Issue Closure: 2-3 seconds per issue
Security
Best Practices
- Never commit credentials - Use environment variables
- Least privilege - IAM policies grant only necessary permissions
- Secure secrets - Store in GitHub Secrets
- Audit logs - Monitor AWS CloudTrail
- Dependency scanning - Regular
npm audit
Credentials
Required credentials:
- AWS Access Key ID (Bedrock access)
- AWS Secret Access Key
- GitHub Token (automatically provided in workflows)
Troubleshooting
Common Issues
TypeScript compilation errors:
npm run clean
npm install
npm run build
Module not found errors:
- Ensure all imports use
.jsextension (for ES modules) - Check
tsconfig.jsonmodule resolution
AWS authentication errors:
- Verify credentials are set correctly
- Check IAM permissions
- Ensure Bedrock model access is approved
GitHub API errors:
- Check token permissions
- Verify rate limits
- Ensure labels exist
Contributing
When adding new features:
- Follow existing code structure
- Add comprehensive error handling
- Include logging for debugging
- Update documentation
- Test thoroughly
License
See repository LICENSE file.