Skip to content

Commit

Permalink
Add even more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tnm committed Dec 27, 2024
1 parent 738a276 commit c280911
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 25 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ await hypersonic.createPrFromFile(
{
title: 'Update documentation',
description: 'Updated API docs with new endpoints',
labels: ['documentation'],
reviewers: ['teammate']
labels: ['documentation']
}
);
```
Expand Down Expand Up @@ -218,6 +217,12 @@ interface PRConfig {
}
```

## Examples

For complete working examples, check out:
- [Basic Usage](examples/basic/test-hypersonic.ts) - Shows all PR creation methods and configuration options


### PR Configuration

There are two levels of configuration:
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Basic Hypersonic Example
# Hypersonic Example

This example demonstrates the basic features of hypersonic:
This example demonstrates the features of hypersonic:
- Creating PRs with multiple file changes
- Adding labels and descriptions
- Enabling auto-merge
Expand Down
8 changes: 4 additions & 4 deletions examples/basic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 88 additions & 17 deletions examples/basic/test-hypersonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ import { Hypersonic, MergeStrategy } from '@runcased/hypersonic';
import { writeFile, mkdir } from 'fs/promises';
import { join } from 'path';

async function main() {
const token = process.env.HYPERSONIC_GITHUB_TOKEN || '';
if (!token) {
console.error('❌ Please set HYPERSONIC_GITHUB_TOKEN environment variable');
process.exit(1);
}
const token = process.env.HYPERSONIC_GITHUB_TOKEN || '';
if (!token) {
console.error('❌ Please set HYPERSONIC_GITHUB_TOKEN environment variable');
process.exit(1);
}

const hypersonic = new Hypersonic(token);
const repo = process.argv[2];
if (!repo) {
console.error('❌ Please provide a repository (e.g. "org/repo")');
process.exit(1);
}

const repo = process.argv[2];
if (!repo) {
console.error('❌ Please provide a repository (e.g. "org/repo")');
process.exit(1);
}
async function main() {
// Original examples with basic client
const basic = new Hypersonic(token);

try {
// 1. Single file from content
const contentPrUrl = await hypersonic.createPrFromContent(
const contentPrUrl = await basic.createPrFromContent(
repo,
'Hello from Hypersonic!',
'docs/hello.md',
Expand All @@ -35,7 +36,7 @@ async function main() {
const localFile = join(__dirname, 'test.txt');
await writeFile(localFile, 'Local file content');

const filePrUrl = await hypersonic.createPrFromFile(
const filePrUrl = await basic.createPrFromFile(
repo,
localFile,
'test/test.txt',
Expand All @@ -47,7 +48,7 @@ async function main() {
console.log('Created PR from file:', filePrUrl);

// 3. Multiple files from content
const multiContentPrUrl = await hypersonic.createPrFromMultipleContents(
const multiContentPrUrl = await basic.createPrFromMultipleContents(
repo,
{
'config/settings.json': JSON.stringify({ setting: 'value' }, null, 2),
Expand All @@ -67,7 +68,7 @@ async function main() {
await writeFile(join(testDir, 'file1.txt'), 'Content 1');
await writeFile(join(testDir, 'file2.txt'), 'Content 2');

const multiFilePrUrl = await hypersonic.createPrFromFiles(
const multiFilePrUrl = await basic.createPrFromFiles(
repo,
{
[join(testDir, 'file1.txt')]: 'test/file1.txt',
Expand All @@ -81,10 +82,80 @@ async function main() {
);
console.log('Created PR from multiple files:', multiFilePrUrl);

// New examples with configured client
const withDefaults = new Hypersonic({
githubToken: token,
defaultPrConfig: {
title: 'Automated Update',
labels: ['automated'],
mergeStrategy: MergeStrategy.SQUASH,
autoMerge: true
}
});

// 5. Minimal PR config (uses instance defaults)
const pr5 = await withDefaults.createPrFromContent(
repo,
'Updated content',
'docs/README.md',
{
title: 'Update documentation' // Only override title
}
);
console.log('Created PR with minimal config:', pr5);

// 6. Override some defaults
const pr6 = await withDefaults.createPrFromContent(
repo,
'New feature code',
'src/feature.ts',
{
title: 'Add new feature',
labels: ['feature'], // Override default labels
autoMerge: false // Disable auto-merge for this PR
}
);
console.log('Created PR with overridden defaults:', pr6);

// 7. Full custom config
const pr7 = await withDefaults.createPrFromContent(
repo,
'Configuration update',
'config.json',
{
title: 'Update configuration',
description: 'Update service configuration with new defaults',
baseBranch: 'develop',
draft: false,
labels: ['config', 'urgent'],
mergeStrategy: 'rebase',
deleteBranchOnMerge: true,
autoMerge: true,
commitMessage: 'chore: update service configuration'
}
);
console.log('Created PR with full custom config:', pr7);

// 8. Multiple files with configured client
const pr8 = await withDefaults.createPrFromMultipleContents(
repo,
{
'config/app.json': JSON.stringify({ version: '2.0.0' }),
'README.md': '# Updated Documentation',
'CHANGELOG.md': '## 2.0.0\n- Major update'
},
{
title: 'Version 2.0.0 Release',
labels: ['release'], // Override default labels
autoMerge: false // Disable auto-merge for this release
}
);
console.log('Created PR for release:', pr8);

} catch (error) {
console.error('❌ Error:', error);
process.exit(1);
}
}

main();
main().catch(console.error);

0 comments on commit c280911

Please sign in to comment.