Skip to content

Commit 16a04d4

Browse files
test and workflows fixed with results
1 parent 71f85f7 commit 16a04d4

File tree

11 files changed

+1902
-352
lines changed

11 files changed

+1902
-352
lines changed

.github/workflows/generate-profiles.yml

Lines changed: 87 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
env:
4343
GITHUB_REPOSITORY: ${{ github.repository }}
4444
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN || secrets.IMAGE_TOKEN }}
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4646
run: |
4747
# Install required dependencies
4848
npm install node-fetch@2
@@ -51,104 +51,150 @@ jobs:
5151
cat > generate-images.js << 'EOL'
5252
const fs = require('fs');
5353
const fetch = require('node-fetch');
54-
const { execSync } = require('child_process');
5554
5655
// Get the API URL from environment variables
57-
const API_URL = process.env.API_URL || 'http://localhost:3000';
56+
const API_URL = https://openreadme.vercel.app/api/openreadme || 'http://localhost:3000';
5857
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
5958
6059
async function generateProfileImage(username, userId) {
6160
try {
62-
console.log(`Generating image for ${username}...`);
61+
console.log(`🎨 Generating image for ${username} (${userId})...`);
6362
6463
// First, get the user data from GitHub API
6564
const userResponse = await fetch(`https://api.github.com/users/${username}`, {
6665
headers: {
6766
'Authorization': `token ${GITHUB_TOKEN}`,
68-
'Accept': 'application/vnd.github.v3+json'
67+
'Accept': 'application/vnd.github.v3+json',
68+
'User-Agent': 'OpenReadme-Workflow'
6969
}
7070
});
7171
7272
if (!userResponse.ok) {
73-
throw new Error(`GitHub API error: ${userResponse.statusText}`);
73+
console.warn(`⚠️ GitHub API warning for ${username}: ${userResponse.statusText}`);
74+
// Continue with basic data if GitHub API fails
7475
}
7576
76-
const userData = await userResponse.json();
77+
const userData = userResponse.ok ? await userResponse.json() : { login: username };
78+
79+
// Prepare the data for the OpenReadme API (using POST method)
80+
const requestBody = {
81+
username: username,
82+
github: username
83+
};
7784
78-
// Prepare the data for the OpenReadme API
85+
// Add query parameters for additional data
7986
const params = new URLSearchParams({
8087
n: userData.name || username,
8188
i: userData.avatar_url || '',
82-
github: username,
89+
g: username,
8390
x: userData.twitter_username || '',
84-
l: userData.blog || userData.html_url,
85-
p: userData.html_url,
86-
t: 'classic' // Default theme
91+
l: userData.blog || userData.html_url || '',
92+
p: userData.html_url || `https://github.com/${username}`,
93+
t: 'classic'
8794
});
8895
8996
const apiUrl = `${API_URL}?${params.toString()}`;
90-
console.log(`Calling API: ${apiUrl}`);
97+
console.log(`📡 Calling API: ${apiUrl}`);
9198
92-
// Call the OpenReadme API with proper headers
99+
// Call the OpenReadme API with POST method (as per your route.ts)
93100
const response = await fetch(apiUrl, {
94-
method: 'GET',
101+
method: 'POST',
95102
headers: {
96103
'Accept': 'application/json',
97-
'Content-Type': 'application/json'
98-
}
104+
'Content-Type': 'application/json',
105+
'User-Agent': 'OpenReadme-Workflow'
106+
},
107+
body: JSON.stringify(requestBody)
99108
});
100109
101-
console.log(`Response status: ${response.status} ${response.statusText}`);
110+
console.log(`📊 Response status: ${response.status} ${response.statusText}`);
102111
103112
if (!response.ok) {
104-
const error = await response.text();
105-
throw new Error(`API error: ${error}`);
113+
const errorText = await response.text();
114+
console.error(`❌ API error response: ${errorText}`);
115+
throw new Error(`API error (${response.status}): ${errorText}`);
106116
}
107117
108118
const result = await response.json();
109-
console.log(`✅ Successfully generated image for ${username}: ${result.url}`);
119+
console.log(`✅ Successfully generated image for ${username}`);
120+
console.log(`🔗 Image URL: ${result.url}`);
121+
console.log(`📝 Method: ${result.method}`);
110122
111123
return result.url;
112124
113125
} catch (error) {
114126
console.error(`❌ Error generating image for ${username}:`, error.message);
127+
console.error(`🔍 Stack trace:`, error.stack);
115128
return null;
116129
}
117130
}
118131
119132
// Process all users
120133
(async () => {
121-
const mappings = process.env.MAPPINGS.split(' ');
122-
console.log(`Found ${mappings.length} users to process`);
134+
try {
135+
const mappingsString = process.env.MAPPINGS || '';
136+
const mappings = mappingsString.split(' ').filter(m => m.trim());
137+
console.log(`📋 Found ${mappings.length} users to process`);
138+
console.log(`🔧 Using API URL: ${API_URL}`);
139+
140+
if (mappings.length === 0) {
141+
console.log('⚠️ No user mappings found to process');
142+
return;
143+
}
123144
124-
for (const mapping of mappings) {
125-
if (!mapping) continue;
145+
let successCount = 0;
146+
let errorCount = 0;
126147
127-
const [username, userId] = mapping.split('=');
128-
if (!username || !userId) continue;
148+
for (const mapping of mappings) {
149+
if (!mapping.trim()) continue;
129150
130-
console.log(`\n--- Processing ${username} (${userId}) ---`);
151+
const [username, userId] = mapping.split('=');
152+
if (!username || !userId) {
153+
console.warn(`⚠️ Invalid mapping format: ${mapping}`);
154+
continue;
155+
}
131156
132-
try {
133-
const imageUrl = await generateProfileImage(username, userId);
134-
if (imageUrl) {
135-
// Here you could update the user-mapping.json with the new image URL if needed
136-
console.log(`Image URL: ${imageUrl}`);
157+
console.log(`\n${'='.repeat(50)}`);
158+
console.log(`🔄 Processing ${username} (${userId})`);
159+
console.log(`${'='.repeat(50)}`);
160+
161+
try {
162+
const imageUrl = await generateProfileImage(username, userId);
163+
if (imageUrl) {
164+
successCount++;
165+
console.log(`✅ Success for ${username}: ${imageUrl}`);
166+
} else {
167+
errorCount++;
168+
console.log(`❌ Failed for ${username}`);
169+
}
170+
171+
// Add delay to avoid rate limiting (2 seconds between requests)
172+
console.log(`⏳ Waiting 2 seconds before next request...`);
173+
await new Promise(resolve => setTimeout(resolve, 2000));
174+
175+
} catch (error) {
176+
errorCount++;
177+
console.error(`💥 Error processing ${username}:`, error.message);
137178
}
179+
}
138180
139-
// Add delay to avoid rate limiting (1 second between requests)
140-
await new Promise(resolve => setTimeout(resolve, 1000));
181+
console.log(`\n${'='.repeat(60)}`);
182+
console.log(`📊 WORKFLOW SUMMARY`);
183+
console.log(`${'='.repeat(60)}`);
184+
console.log(`✅ Successful: ${successCount}`);
185+
console.log(`❌ Failed: ${errorCount}`);
186+
console.log(`📋 Total: ${successCount + errorCount}`);
187+
console.log(`${'='.repeat(60)}`);
141188
142-
} catch (error) {
143-
console.error(`Error processing ${username}:`, error);
144-
}
189+
} catch (error) {
190+
console.error('💥 Workflow failed:', error.message);
191+
process.exit(1);
145192
}
146-
147-
console.log('\n--- All users processed ---');
148193
})();
149194
EOL
150195
151-
# Run the generation script
196+
# Run the generation script with your deployed URL
197+
# TODO: Replace with your actual Vercel deployment URL
152198
MAPPINGS="${{ steps.user-mappings.outputs.mappings }}" \
153199
API_URL="https://openreadme.vercel.app/api/openreadme" \
154200
node generate-images.js

0 commit comments

Comments
 (0)