Skip to content

Commit 775e305

Browse files
Add examples directory with usage scripts
- Add basic usage examples (evaluate-popular-repos, create-interactive, evaluate-with-token) - Add advanced examples (batch-evaluate, compare-repositories, export-results, check-org-repos) - Add integration examples (GitHub Actions, pre-commit hook, Slack integration) - Add sample data files and expected results - Add comprehensive README with usage instructions Closes #9
1 parent 2e801ac commit 775e305

13 files changed

Lines changed: 1163 additions & 0 deletions

examples/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Examples Directory
2+
3+
This directory contains practical examples of using RepoReady in various scenarios.
4+
5+
## Getting Started
6+
7+
1. Build RepoReady: `npm run build`
8+
2. Set GitHub token: `export GITHUB_TOKEN=your_token_here`
9+
3. Run examples: `node examples/basic/evaluate-popular-repos.js`
10+
11+
## Directory Structure
12+
13+
- `basic/` - Simple usage examples for beginners
14+
- `advanced/` - Complex scenarios and batch operations
15+
- `integrations/` - Integration with other tools and services
16+
- `data/` - Sample data files and expected results
17+
18+
## Requirements
19+
20+
- Node.js 16+
21+
- Built RepoReady (`npm run build`)
22+
- GitHub token (for API access)
23+
24+
## Examples Overview
25+
26+
### Basic Examples
27+
- **evaluate-popular-repos.js** - Evaluate famous repositories
28+
- **create-repo-interactive.js** - Interactive repository creation
29+
- **evaluate-with-token.js** - Token usage best practices
30+
31+
### Advanced Examples
32+
- **batch-evaluate.js** - Evaluate multiple repos with export
33+
- **compare-repositories.js** - Side-by-side repository comparison
34+
- **export-results.js** - Export evaluation results to JSON/CSV
35+
- **check-org-repos.js** - Evaluate all repos in an organization
36+
37+
### Integration Examples
38+
- **github-actions-example.yml** - CI/CD integration
39+
- **pre-commit-hook.js** - Git hook integration
40+
- **slack-integration.js** - Notifications integration
41+
42+
## Benefits
43+
44+
📚 Provides practical learning materials
45+
🚀 Helps users get started quickly
46+
💡 Demonstrates advanced use cases
47+
🔧 Shows integration possibilities
48+
📊 Includes real-world scenarios
49+
🎯 Reduces support burden with self-service examples
50+
51+
## Integration with Documentation
52+
53+
Link examples from main README.md
54+
Reference examples in CLI help text
55+
Include in getting started guides
56+
Use in tutorials and blog posts
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env node
2+
// examples/advanced/batch-evaluate.js
3+
4+
/**
5+
* Example: Batch Repository Evaluation with Export
6+
*
7+
* Evaluates multiple repositories and exports results to JSON
8+
*/
9+
10+
const fs = require('fs').promises;
11+
const path = require('path');
12+
const { exec } = require('child_process');
13+
const util = require('util');
14+
15+
const execPromise = util.promisify(exec);
16+
17+
class BatchEvaluator {
18+
constructor(githubToken) {
19+
this.githubToken = githubToken;
20+
this.results = [];
21+
}
22+
23+
async evaluateRepository(owner, repo) {
24+
try {
25+
console.log(`📊 Evaluating ${owner}/${repo}...`);
26+
27+
const command = this.githubToken
28+
? `node ../../dist/index.js evaluate ${owner}/${repo} --token ${this.githubToken}`
29+
: `node ../../dist/index.js evaluate ${owner}/${repo}`;
30+
31+
const { stdout } = await execPromise(command);
32+
33+
// Parse the output to extract score information
34+
const scoreMatch = stdout.match(/Score: (\d+)%/);
35+
const ratingMatch = stdout.match(/Rating: (\w+)/);
36+
37+
const result = {
38+
repository: `${owner}/${repo}`,
39+
timestamp: new Date().toISOString(),
40+
score: scoreMatch ? parseInt(scoreMatch[1]) : 0,
41+
rating: ratingMatch ? ratingMatch[1] : 'Unknown',
42+
rawOutput: stdout
43+
};
44+
45+
this.results.push(result);
46+
console.log(` Score: ${result.score}% (${result.rating})`);
47+
48+
return result;
49+
} catch (error) {
50+
console.error(`❌ Error evaluating ${owner}/${repo}:`, error.message);
51+
return null;
52+
}
53+
}
54+
55+
async evaluateBatch(repositories) {
56+
for (const repo of repositories) {
57+
const [owner, name] = repo.split('/');
58+
await this.evaluateRepository(owner, name);
59+
60+
// Respect rate limits
61+
await new Promise(resolve => setTimeout(resolve, 1000));
62+
}
63+
}
64+
65+
async exportResults(filename = 'evaluation-results.json') {
66+
const outputPath = path.join(__dirname, '..', 'data', filename);
67+
await fs.writeFile(outputPath, JSON.stringify(this.results, null, 2));
68+
console.log(`📄 Results exported to ${outputPath}`);
69+
}
70+
71+
generateSummary() {
72+
if (this.results.length === 0) return;
73+
74+
const avgScore = this.results.reduce((sum, r) => sum + r.score, 0) / this.results.length;
75+
const ratingCounts = this.results.reduce((counts, r) => {
76+
counts[r.rating] = (counts[r.rating] || 0) + 1;
77+
return counts;
78+
}, {});
79+
80+
console.log('\n📈 Batch Evaluation Summary');
81+
console.log(` Repositories evaluated: ${this.results.length}`);
82+
console.log(` Average score: ${avgScore.toFixed(1)}%`);
83+
console.log(` Rating distribution:`, ratingCounts);
84+
}
85+
}
86+
87+
// Example usage
88+
const exampleRepos = [
89+
'OpenSource-Communities/RepoReady',
90+
'facebook/react',
91+
'microsoft/typescript'
92+
];
93+
94+
async function main() {
95+
const token = process.env.GITHUB_TOKEN;
96+
if (!token) {
97+
console.error('Please set GITHUB_TOKEN environment variable');
98+
process.exit(1);
99+
}
100+
101+
const batchEvaluator = new BatchEvaluator(token);
102+
103+
await batchEvaluator.evaluateBatch(exampleRepos);
104+
batchEvaluator.generateSummary();
105+
await batchEvaluator.exportResults();
106+
}
107+
108+
if (require.main === module) {
109+
main().catch(console.error);
110+
}
111+
112+
module.exports = { BatchEvaluator };
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/usr/bin/env node
2+
// examples/advanced/check-org-repos.js
3+
4+
/**
5+
* Example: Check Organization Repositories
6+
*
7+
* This script demonstrates how to evaluate all repositories
8+
* in a GitHub organization for contributor readiness.
9+
*/
10+
11+
const { exec } = require('child_process');
12+
const util = require('util');
13+
const fs = require('fs').promises;
14+
const path = require('path');
15+
16+
const execPromise = util.promisify(exec);
17+
18+
class OrganizationEvaluator {
19+
constructor(githubToken) {
20+
this.githubToken = githubToken;
21+
this.results = [];
22+
}
23+
24+
async getOrganizationRepos(orgName) {
25+
try {
26+
console.log(`🔍 Fetching repositories for organization: ${orgName}`);
27+
28+
// Use GitHub API to get organization repositories
29+
const command = `curl -H "Authorization: token ${this.githubToken}" "https://api.github.com/orgs/${orgName}/repos?per_page=100"`;
30+
const { stdout } = await execPromise(command);
31+
32+
const repos = JSON.parse(stdout);
33+
return repos.map(repo => `${repo.owner.login}/${repo.name}`);
34+
} catch (error) {
35+
console.error(`❌ Error fetching organization repos:`, error.message);
36+
return [];
37+
}
38+
}
39+
40+
async evaluateRepository(owner, repo) {
41+
try {
42+
console.log(`📊 Evaluating ${owner}/${repo}...`);
43+
44+
const command = this.githubToken
45+
? `node ../../dist/index.js evaluate ${owner}/${repo} --token ${this.githubToken}`
46+
: `node ../../dist/index.js evaluate ${owner}/${repo}`;
47+
48+
const { stdout } = await execPromise(command);
49+
50+
// Parse the output to extract score information
51+
const scoreMatch = stdout.match(/Score: (\d+)%/);
52+
const ratingMatch = stdout.match(/Rating: (\w+)/);
53+
54+
const result = {
55+
repository: `${owner}/${repo}`,
56+
score: scoreMatch ? parseInt(scoreMatch[1]) : 0,
57+
rating: ratingMatch ? ratingMatch[1] : 'Unknown',
58+
timestamp: new Date().toISOString()
59+
};
60+
61+
this.results.push(result);
62+
console.log(` Score: ${result.score}% (${result.rating})`);
63+
64+
return result;
65+
} catch (error) {
66+
console.error(`❌ Error evaluating ${owner}/${repo}:`, error.message);
67+
return null;
68+
}
69+
}
70+
71+
async evaluateOrganization(orgName) {
72+
console.log(`🏢 Evaluating Organization: ${orgName}\n`);
73+
74+
const repositories = await this.getOrganizationRepos(orgName);
75+
76+
if (repositories.length === 0) {
77+
console.log('No repositories found for this organization');
78+
return;
79+
}
80+
81+
console.log(`Found ${repositories.length} repositories to evaluate\n`);
82+
83+
for (const repo of repositories) {
84+
const [owner, name] = repo.split('/');
85+
await this.evaluateRepository(owner, name);
86+
87+
// Respect rate limits
88+
await new Promise(resolve => setTimeout(resolve, 1000));
89+
}
90+
91+
this.generateOrganizationReport(orgName);
92+
await this.exportOrganizationResults(orgName);
93+
}
94+
95+
generateOrganizationReport(orgName) {
96+
if (this.results.length === 0) return;
97+
98+
console.log(`\n📊 Organization Report: ${orgName}`);
99+
console.log('='.repeat(60));
100+
101+
const avgScore = this.results.reduce((sum, r) => sum + r.score, 0) / this.results.length;
102+
const ratingCounts = this.results.reduce((counts, r) => {
103+
counts[r.rating] = (counts[r.rating] || 0) + 1;
104+
return counts;
105+
}, {});
106+
107+
// Sort by score
108+
const sortedResults = this.results.sort((a, b) => b.score - a.score);
109+
110+
console.log(`Total Repositories: ${this.results.length}`);
111+
console.log(`Average Score: ${avgScore.toFixed(1)}%`);
112+
console.log(`Rating Distribution:`, ratingCounts);
113+
114+
console.log('\nTop Performing Repositories:');
115+
sortedResults.slice(0, 5).forEach((result, index) => {
116+
console.log(` ${index + 1}. ${result.repository} - ${result.score}% (${result.rating})`);
117+
});
118+
119+
console.log('\nRepositories Needing Attention:');
120+
sortedResults.slice(-5).reverse().forEach((result, index) => {
121+
console.log(` ${index + 1}. ${result.repository} - ${result.score}% (${result.rating})`);
122+
});
123+
}
124+
125+
async exportOrganizationResults(orgName) {
126+
const outputPath = path.join(__dirname, '..', 'data', `${orgName}-evaluation.json`);
127+
await fs.writeFile(outputPath, JSON.stringify(this.results, null, 2));
128+
console.log(`\n📄 Organization results exported to ${outputPath}`);
129+
}
130+
}
131+
132+
// Example usage
133+
async function main() {
134+
const orgName = process.argv[2];
135+
const token = process.env.GITHUB_TOKEN;
136+
137+
if (!orgName) {
138+
console.error('Please provide organization name: node check-org-repos.js <org-name>');
139+
process.exit(1);
140+
}
141+
142+
if (!token) {
143+
console.error('Please set GITHUB_TOKEN environment variable');
144+
process.exit(1);
145+
}
146+
147+
const evaluator = new OrganizationEvaluator(token);
148+
await evaluator.evaluateOrganization(orgName);
149+
}
150+
151+
if (require.main === module) {
152+
main().catch(console.error);
153+
}
154+
155+
module.exports = { OrganizationEvaluator };

0 commit comments

Comments
 (0)