Skip to content

Commit c036746

Browse files
committed
feat: add additional utils and extensive testing
1 parent 88d486a commit c036746

17 files changed

+3624
-8
lines changed

README.md

Lines changed: 205 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,27 @@ This package provides a comprehensive set of TypeScript utilities for interactin
66

77
## Features
88

9-
-**Sticky Comments** - Create and manage persistent, updatable comments
10-
-**Pull Request Utilities** - Find, label, and manage pull requests
11-
-**Comment Search** - Search and filter issue/PR comments
9+
### 📋 Complete Function Reference
10+
11+
| Category | Functions | Description |
12+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------- |
13+
| **💬 Comments** | `createStickyComment`, `findCommentByIdentifier`, `searchComments`, `deleteComment`, `deleteStickyComment` | Create, find, search, and manage issue/PR comments |
14+
| **🔀 Pull Requests** | `findPullRequestsByLabels`, `getPullRequest`, `addLabelsToPullRequest`, `removeLabelsFromPullRequest`, `pullRequestHasLabels`, `getPullRequestFiles` | Find, manage, and interact with pull requests |
15+
| **🔍 Advanced PR Search** | `findPRsWithLabels`, `searchPullRequests`, `findOpenPRsWithLabel`, `checkLabelConflicts` | Advanced pull request search and label conflict detection |
16+
| **🌿 Branch Management** | `checkBranchExists`, `listAllBranches`, `getBranchProtection`, `getDefaultBranch` | Branch existence, listing, and protection management |
17+
| **🚀 Deployments** | `listDeployments`, `getDeploymentStatuses`, `setDeploymentStatus`, `deleteDeployment`, `createDeployment` | Deployment lifecycle management |
18+
| **🔧 Context & Utils** | `getRepoInfo`, `getCurrentPullRequestNumber`, `getCurrentIssueNumber`, `isPullRequestContext`, `isIssueContext`, `getCurrentSHA`, `getCurrentBranch`, `getRepositoryUrl`, `getIssueUrl`, `getPullRequestUrl` | GitHub Actions context extraction and URL helpers |
19+
| **📝 Text & Formatting** | `escapeMarkdown`, `codeBlock`, `createMarkdownTable`, `truncateText`, `formatDate`, `parseGitHubDate`, `delay` | Text formatting, markdown utilities, and date handling |
20+
| **🔤 String Utilities** | `snakeToCamel`, `camelToSnake`, `kebabToCamel`, `camelToKebab`, `capitalize`, `toTitleCase` | String case conversion and text transformation |
21+
| **⚙️ Input Processing** | `sanitizeInput`, `sanitizeInputs`, `getBranch` | Input sanitization and branch extraction from various GitHub events |
22+
23+
### ✨ Key Features
24+
1225
-**Type Safety** - Full TypeScript support with comprehensive type definitions
13-
-**Context Helpers** - Extract repository and event information from GitHub Actions context
14-
-**Markdown Utilities** - Format and escape content for GitHub markdown
26+
-**Universal Compatibility** - Works with all GitHub event types and contexts
27+
-**Comprehensive Testing** - 110+ tests with 94%+ code coverage
28+
-**GitHub API Optimized** - Efficient API usage with proper error handling and pagination support
29+
-**Developer Friendly** - Intuitive APIs with TypeScript intellisense and JSDoc documentation
1530

1631
---
1732

@@ -278,6 +293,180 @@ const table = createMarkdownTable(
278293
const short = truncateText("Very long text...", 50);
279294
```
280295

296+
### String Utilities
297+
298+
#### Case Conversion
299+
300+
```ts
301+
import {
302+
snakeToCamel,
303+
camelToSnake,
304+
kebabToCamel,
305+
camelToKebab,
306+
capitalize,
307+
toTitleCase,
308+
} from "github-typescript-utils";
309+
310+
// Convert between naming conventions
311+
const camelCase = snakeToCamel("hello_world"); // "helloWorld"
312+
const snakeCase = camelToSnake("helloWorld"); // "hello_world"
313+
const kebabCase = camelToKebab("helloWorld"); // "hello-world"
314+
const camelFromKebab = kebabToCamel("hello-world"); // "helloWorld"
315+
316+
// Text transformation
317+
const capitalized = capitalize("hello"); // "Hello"
318+
const titleCase = toTitleCase("hello world"); // "Hello World"
319+
```
320+
321+
### Branch Management
322+
323+
#### Branch Operations
324+
325+
```ts
326+
import {
327+
checkBranchExists,
328+
listAllBranches,
329+
getBranchProtection,
330+
getDefaultBranch,
331+
} from "github-typescript-utils";
332+
333+
// Check if branch exists
334+
const exists = await checkBranchExists({
335+
ctx: { core, github, context },
336+
repo,
337+
branch: "feature-branch",
338+
});
339+
340+
// List all branches
341+
const branches = await listAllBranches({
342+
ctx: { core, github, context },
343+
repo,
344+
limit: 50,
345+
});
346+
347+
// Get branch protection rules
348+
const protection = await getBranchProtection({
349+
ctx: { core, github, context },
350+
repo,
351+
branch: "main",
352+
});
353+
354+
// Get default branch
355+
const defaultBranch = await getDefaultBranch({
356+
ctx: { core, github, context },
357+
repo,
358+
});
359+
```
360+
361+
### Deployment Management
362+
363+
#### Deployment Lifecycle
364+
365+
```ts
366+
import {
367+
listDeployments,
368+
createDeployment,
369+
setDeploymentStatus,
370+
getDeploymentStatuses,
371+
deleteDeployment,
372+
} from "github-typescript-utils";
373+
374+
// Create a deployment
375+
const deployment = await createDeployment({
376+
ctx: { core, github, context },
377+
repo,
378+
ref: "main",
379+
environment: "production",
380+
description: "Deploy v1.0.0",
381+
});
382+
383+
// Set deployment status
384+
await setDeploymentStatus({
385+
ctx: { core, github, context },
386+
repo,
387+
deploymentId: deployment.id,
388+
state: "success",
389+
description: "Deployment completed successfully",
390+
});
391+
392+
// List deployments
393+
const deployments = await listDeployments({
394+
ctx: { core, github, context },
395+
repo,
396+
environment: "production",
397+
});
398+
```
399+
400+
### Advanced PR Search
401+
402+
#### Enhanced PR Operations
403+
404+
```ts
405+
import {
406+
findPRsWithLabels,
407+
searchPullRequests,
408+
checkLabelConflicts,
409+
findOpenPRsWithLabel,
410+
} from "github-typescript-utils";
411+
412+
// Find PRs with multiple labels
413+
const prs = await findPRsWithLabels({
414+
ctx: { core, github, context },
415+
repo,
416+
labels: ["bug", "urgent"],
417+
excludePRs: [123], // Exclude specific PR numbers
418+
});
419+
420+
// Advanced PR search
421+
const searchResults = await searchPullRequests({
422+
ctx: { core, github, context },
423+
repo,
424+
options: {
425+
labels: ["feature"],
426+
author: "dependabot[bot]",
427+
state: "open",
428+
},
429+
});
430+
431+
// Check for label conflicts
432+
const conflict = await checkLabelConflicts({
433+
ctx: { core, github, context },
434+
repo,
435+
prNumber: 123,
436+
label: "sync-branch: main",
437+
});
438+
439+
if (conflict.hasConflict) {
440+
core.warning(`Label conflict with PR #${conflict.conflictingPR?.number}`);
441+
}
442+
```
443+
444+
### Input Processing
445+
446+
#### Input Sanitization and Branch Extraction
447+
448+
```ts
449+
import {
450+
sanitizeInput,
451+
sanitizeInputs,
452+
getBranch,
453+
} from "github-typescript-utils";
454+
455+
// Remove quotes from workflow inputs
456+
const cleanInput = sanitizeInput('"quoted-value"'); // "quoted-value"
457+
458+
// Sanitize all string properties in an object
459+
const cleanInputs = sanitizeInputs({
460+
name: '"John"',
461+
age: 30,
462+
title: '"Developer"',
463+
}); // { name: "John", age: 30, title: "Developer" }
464+
465+
// Extract branch from any GitHub event
466+
const branch = getBranch({ core, github, context });
467+
// Works with: pull_request, push, workflow_run, etc.
468+
```
469+
281470
---
282471

283472
## Type Definitions
@@ -286,13 +475,24 @@ The package exports comprehensive TypeScript types:
286475

287476
```ts
288477
import type {
478+
// Core types
289479
GitHubContext,
290480
RepoInfo,
291481
PullRequest,
292482
IssueComment,
483+
484+
// Comment types
293485
StickyCommentOptions,
294486
CommentSearchOptions,
487+
488+
// Pull request types
295489
PullRequestSearchOptions,
490+
PullRequestFile,
491+
AdvancedPRSearchOptions,
492+
493+
// Deployment types
494+
Deployment,
495+
DeploymentStatus,
296496
} from "github-typescript-utils";
297497
```
298498

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-typescript-utils",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Utility functions for GitHub REST API interactions with github-typescript",
55
"type": "module",
66
"main": "./dist/index.js",
@@ -41,14 +41,17 @@
4141
"build:watch": "tsc --watch",
4242
"clean": "rm -rf dist",
4343
"dev": "tsc --watch",
44+
"test": "vitest",
45+
"test:run": "vitest run",
46+
"test:coverage": "vitest run --coverage",
4447
"lint": "biome lint src/",
4548
"lint:fix": "biome lint --write src/",
4649
"format": "biome format src/",
4750
"format:fix": "biome format --write src/",
4851
"check": "biome check src/",
4952
"check:fix": "biome check --write src/",
5053
"type-check": "tsc --noEmit",
51-
"prepublishOnly": "pnpm run clean && pnpm run build"
54+
"prepublishOnly": "pnpm run clean && pnpm run test:run && pnpm run build"
5255
},
5356
"peerDependencies": {
5457
"@actions/core": "^1.10.0",
@@ -59,7 +62,9 @@
5962
"@actions/github": "^6.0.0",
6063
"@biomejs/biome": "^2.1.1",
6164
"@types/node": "^22.17.0",
62-
"typescript": "^5.8.3"
65+
"@vitest/coverage-v8": "^3.2.4",
66+
"typescript": "^5.8.3",
67+
"vitest": "^3.2.4"
6368
},
6469
"packageManager": "[email protected]",
6570
"engines": {

0 commit comments

Comments
 (0)