|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import os |
| 3 | +import sys |
| 4 | +import json |
| 5 | +import requests |
| 6 | +from datetime import datetime |
| 7 | + |
| 8 | +TOKEN = os.environ.get('GITHUB_TOKEN') |
| 9 | +if not TOKEN: |
| 10 | + print("Error: GITHUB_TOKEN environment variable not set") |
| 11 | + sys.exit(1) |
| 12 | + |
| 13 | +HEADERS = { |
| 14 | + 'Accept': 'application/vnd.github+json', |
| 15 | + 'Authorization': f'Bearer {TOKEN}', |
| 16 | + 'User-Agent': 'GitHub-Action-Search' |
| 17 | +} |
| 18 | + |
| 19 | +def search_code(query, limit=100): |
| 20 | + """Search GitHub code and return results.""" |
| 21 | + url = 'https://api.github.com/search/code' |
| 22 | + params = { |
| 23 | + 'q': query, |
| 24 | + 'per_page': min(limit, 100) |
| 25 | + } |
| 26 | + |
| 27 | + try: |
| 28 | + response = requests.get(url, headers=HEADERS, params=params, timeout=30) |
| 29 | + response.raise_for_status() |
| 30 | + return response.json().get('items', []) |
| 31 | + except requests.exceptions.RequestException as e: |
| 32 | + print(f"Error searching: {e}") |
| 33 | + return [] |
| 34 | + |
| 35 | +def main(): |
| 36 | + print("=== Searching for shadcn in Cloudflare Workers projects ===\n") |
| 37 | + |
| 38 | + # Search for wrangler.toml |
| 39 | + print("📦 Searching for shadcn in repos with wrangler.toml...") |
| 40 | + toml_results = search_code('shadcn path:wrangler.toml', limit=100) |
| 41 | + print(f" Found {len(toml_results)} code matches") |
| 42 | + |
| 43 | + # Search for wrangler.jsonc |
| 44 | + print("📦 Searching for shadcn in repos with wrangler.jsonc...") |
| 45 | + jsonc_results = search_code('shadcn path:wrangler.jsonc', limit=100) |
| 46 | + print(f" Found {len(jsonc_results)} code matches") |
| 47 | + |
| 48 | + # Combine and deduplicate by repository |
| 49 | + repos = {} |
| 50 | + for item in toml_results + jsonc_results: |
| 51 | + repo = item['repository'] |
| 52 | + repo_id = repo['full_name'] |
| 53 | + if repo_id not in repos: |
| 54 | + repos[repo_id] = { |
| 55 | + 'full_name': repo['full_name'], |
| 56 | + 'html_url': repo['html_url'], |
| 57 | + 'description': repo.get('description', ''), |
| 58 | + 'stargazers_count': repo.get('stargazers_count', 0), |
| 59 | + 'language': repo.get('language', ''), |
| 60 | + 'pushed_at': repo.get('pushed_at', ''), |
| 61 | + 'created_at': repo.get('created_at', ''), |
| 62 | + } |
| 63 | + |
| 64 | + print(f"\n✨ Found {len(repos)} unique repositories\n") |
| 65 | + |
| 66 | + if not repos: |
| 67 | + print("No repositories found!") |
| 68 | + return |
| 69 | + |
| 70 | + # Sort by stars |
| 71 | + print("=== 🌟 Top 20 by Stars ===") |
| 72 | + sorted_by_stars = sorted(repos.values(), key=lambda x: x['stargazers_count'], reverse=True)[:20] |
| 73 | + for i, repo in enumerate(sorted_by_stars, 1): |
| 74 | + lang = f"[{repo['language']}]" if repo['language'] else "" |
| 75 | + print(f"{i:2}. {repo['full_name']:40} ⭐ {repo['stargazers_count']:5} {lang:15} {repo['html_url']}") |
| 76 | + |
| 77 | + # Sort by last updated |
| 78 | + print("\n=== 📅 Top 20 by Last Updated ===") |
| 79 | + sorted_by_updated = sorted(repos.values(), key=lambda x: x['pushed_at'], reverse=True)[:20] |
| 80 | + for i, repo in enumerate(sorted_by_updated, 1): |
| 81 | + pushed = repo['pushed_at'][:10] if repo['pushed_at'] else 'Unknown' |
| 82 | + print(f"{i:2}. {repo['full_name']:40} ⭐ {repo['stargazers_count']:5} Updated: {pushed} {repo['html_url']}") |
| 83 | + |
| 84 | + # Save results to JSON |
| 85 | + output = { |
| 86 | + 'search_date': datetime.utcnow().isoformat(), |
| 87 | + 'total_repos': len(repos), |
| 88 | + 'repositories': list(repos.values()) |
| 89 | + } |
| 90 | + |
| 91 | + with open('results.json', 'w') as f: |
| 92 | + json.dump(output, f, indent=2) |
| 93 | + |
| 94 | + print(f"\n✅ Full results saved to results.json ({len(repos)} repositories)") |
| 95 | + |
| 96 | +if __name__ == '__main__': |
| 97 | + main() |
0 commit comments