GitHub API utilities for automation - PR management, issue tracking, workflow monitoring.
- Pull Request Management - Create, update, merge, and find PRs
- Issue Operations - Create issues, list open issues, search recent closures
- Milestone Management - Create, close, and find milestones
- Release Operations - Create releases, get releases by tag
- Workflow Monitoring - Wait for workflow completion, get workflow runs
- Branch Operations - Delete branches programmatically
- Flexible Logging - Bring your own logger or use the built-in console logger
- Injectable Prompt - Provide custom prompt functions for interactive operations
npm install @eldrforge/github-toolsimport { createPullRequest, mergePullRequest, getRepoDetails } from '@eldrforge/github-tools';
// Get repository details
const { owner, repo } = await getRepoDetails();
console.log(`Repository: ${owner}/${repo}`);
// Create a pull request
const pr = await createPullRequest(
'feat: Add new feature',
'Detailed description of the changes',
'feature-branch',
'main'
);
console.log(`Created PR #${pr.number}: ${pr.html_url}`);
// Merge the pull request
await mergePullRequest(pr.number, 'squash', 'feat: Add new feature (#123)');
console.log('PR merged successfully!');Required:
GITHUB_TOKEN: GitHub personal access token with appropriate permissions
export GITHUB_TOKEN="ghp_your_token_here"By default, github-tools uses a console-based logger. You can provide your own logger implementation (e.g., Winston):
import { setLogger } from '@eldrforge/github-tools';
import winston from 'winston';
// Create Winston logger
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [new winston.transports.Console()]
});
// Use Winston with github-tools
setLogger(logger);For interactive operations (like merge confirmations), you can provide a custom prompt function:
import { setPromptFunction } from '@eldrforge/github-tools';
// Custom prompt implementation
const myPrompt = async (message: string): Promise<boolean> => {
// Your custom prompt logic (e.g., CLI prompts, UI dialogs, etc.)
const answer = await askUser(message);
return answer === 'yes';
};
// Use custom prompt with github-tools
setPromptFunction(myPrompt);import {
createPullRequest,
findOpenPullRequestByHeadRef,
updatePullRequest,
mergePullRequest
} from '@eldrforge/github-tools';
// Create PR
const pr = await createPullRequest('title', 'body', 'head', 'base');
// Find existing PR
const existingPr = await findOpenPullRequestByHeadRef('feature-branch');
// Update PR
await updatePullRequest(pr.number, {
title: 'Updated title',
body: 'Updated description'
});
// Merge PR
await mergePullRequest(pr.number, 'squash', 'Commit title');import {
createIssue,
getOpenIssues,
getRecentClosedIssuesForCommit
} from '@eldrforge/github-tools';
// Create issue
const issue = await createIssue(
'Bug: Something is broken',
'Detailed description',
['bug', 'priority-high']
);
// Get all open issues
const openIssues = await getOpenIssues();
// Get issues closed in recent commits
const closedIssues = await getRecentClosedIssuesForCommit('v1.0.0', 'v1.1.0', 50);import {
findMilestoneByTitle,
createMilestone,
closeMilestone
} from '@eldrforge/github-tools';
// Find existing milestone
const milestone = await findMilestoneByTitle('v1.0.0');
// Create new milestone
const newMilestone = await createMilestone(
'v1.1.0',
'Release 1.1.0 milestone'
);
// Close milestone
await closeMilestone(milestone.number);import {
createGitHubRelease,
getReleaseByTag,
getAllReleases
} from '@eldrforge/github-tools';
// Create release
await createGitHubRelease(
'v1.0.0',
'Release 1.0.0',
'## Changes\n- Feature 1\n- Feature 2',
false, // not a draft
false // not a prerelease
);
// Get specific release
const release = await getReleaseByTag('v1.0.0');
// Get all releases
const allReleases = await getAllReleases();import {
waitForWorkflowsToComplete,
getWorkflowRunsForCommit
} from '@eldrforge/github-tools';
// Wait for workflows to complete (with timeout)
await waitForWorkflowsToComplete('abc123', 300); // 5 minutes
// Get workflow runs for a commit
const runs = await getWorkflowRunsForCommit('abc123');| Function | Description |
|---|---|
createPullRequest(title, body, head, base?) |
Creates a new pull request |
findOpenPullRequestByHeadRef(headRef) |
Finds open PR by head branch |
updatePullRequest(number, updates) |
Updates PR title/body |
mergePullRequest(number, method, title?) |
Merges a pull request |
deleteBranch(branchName) |
Deletes a branch |
| Function | Description |
|---|---|
createIssue(title, body, labels?) |
Creates a new issue |
getOpenIssues() |
Gets all open issues |
getRecentClosedIssuesForCommit(from, to, limit) |
Gets recently closed issues |
| Function | Description |
|---|---|
findMilestoneByTitle(title) |
Finds milestone by title |
createMilestone(title, description?) |
Creates a new milestone |
closeMilestone(number) |
Closes a milestone |
| Function | Description |
|---|---|
createGitHubRelease(tag, name, body, draft, prerelease) |
Creates a GitHub release |
getReleaseByTag(tag) |
Gets release by tag name |
getAllReleases() |
Gets all releases |
| Function | Description |
|---|---|
waitForWorkflowsToComplete(sha, timeout?) |
Waits for workflows to complete |
getWorkflowRunsForCommit(sha) |
Gets workflow runs for commit |
getAllWorkflowRuns() |
Gets all workflow runs |
getCheckRunsForRef(ref) |
Gets check runs for a ref |
| Function | Description |
|---|---|
getOctokit() |
Gets configured Octokit instance |
getCurrentBranchName() |
Gets current branch name |
getRepoDetails() |
Gets owner and repo name |
setLogger(logger) |
Sets custom logger |
setPromptFunction(fn) |
Sets custom prompt function |
This library requires a GitHub personal access token with appropriate permissions:
reposcope for private repositoriespublic_reposcope for public repositoriesworkflowscope if you need to interact with GitHub Actions
Store your token securely:
# Never commit tokens to version control
export GITHUB_TOKEN="ghp_your_token_here"# Install dependencies
npm install
# Build
npm run build
# Run tests
npm run test
# Lint
npm run lint
# Watch mode
npm run watch- @eldrforge/git-tools: Git operations and utilities
- @octokit/rest: GitHub API client
- winston (peer, optional): Logging framework
Apache-2.0 - see LICENSE file for details.
Calen Varek calenvarek@gmail.com
- kodrdriv - AI-powered Git workflow automation tool
- @eldrforge/git-tools - Git utilities for automation
TEST