Skip to content

Commit ed15f2f

Browse files
Merge pull request Open-Dev-Society#38 from ravixalgorithm/main
test implement for checking the system and workflows fixed with results
2 parents 1f1ec82 + d353c9d commit ed15f2f

File tree

11 files changed

+1942
-315
lines changed

11 files changed

+1942
-315
lines changed

.github/workflows/generate-profiles.yml

Lines changed: 120 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,92 +59,196 @@ jobs:
5959
env:
6060
GITHUB_REPOSITORY: ${{ github.repository }}
6161
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
62-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN || secrets.IMAGE_TOKEN }}
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6363
run: |
6464
npm install node-fetch@2
6565
6666
cat > generate-images.js << 'EOL'
6767
const fs = require('fs');
6868
const fetch = require('node-fetch');
69-
const { execSync } = require('child_process');
7069
70+
<<<<<<< HEAD
71+
// Get the API URL from environment variables
72+
const API_URL = https://openreadme.vercel.app/api/openreadme || 'http://localhost:3000';
73+
=======
7174
const API_URL = process.env.API_URL || 'http://localhost:3000';
75+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
7276
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
7377
const REPO_OWNER = 'Open-Dev-Society';
7478
const REPO_NAME = 'openreadme';
7579

7680
async function generateProfileImage(username, userId) {
7781
try {
78-
console.log(`Generating image for ${username}...`);
82+
console.log(`🎨 Generating image for ${username} (${userId})...`);
7983

8084
// Get user data from GitHub API
8185
const userResponse = await fetch(`https://api.github.com/users/${username}`, {
8286
headers: {
8387
'Authorization': `token ${GITHUB_TOKEN}`,
84-
'Accept': 'application/vnd.github.v3+json'
88+
'Accept': 'application/vnd.github.v3+json',
89+
'User-Agent': 'OpenReadme-Workflow'
8590
}
8691
});
8792

8893
if (!userResponse.ok) {
89-
throw new Error(`GitHub API error: ${userResponse.statusText}`);
94+
console.warn(`⚠️ GitHub API warning for ${username}: ${userResponse.statusText}`);
95+
// Continue with basic data if GitHub API fails
9096
}
9197

92-
const userData = await userResponse.json();
98+
const userData = userResponse.ok ? await userResponse.json() : { login: username };
99+
100+
<<<<<<< HEAD
101+
// Prepare the data for the OpenReadme API (using POST method)
102+
const requestBody = {
103+
username: username,
104+
github: username
105+
};
93106

107+
// Add query parameters for additional data
108+
=======
94109
// Build API URL with repository parameters
110+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
95111
const params = new URLSearchParams({
96112
n: userData.name || username,
97113
i: userData.avatar_url || '',
98-
github: username,
114+
g: username,
99115
x: userData.twitter_username || '',
116+
<<<<<<< HEAD
117+
l: userData.blog || userData.html_url || '',
118+
p: userData.html_url || `https://github.com/${username}`,
119+
t: 'classic'
120+
=======
100121
l: userData.blog || userData.html_url,
101122
p: userData.html_url,
102123
t: 'classic',
103124
repo: `${REPO_OWNER}/${REPO_NAME}`,
104125
path: 'stats/usage-log.json'
126+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
105127
});
106128

107129
const apiUrl = `${API_URL}?${params.toString()}`;
108-
console.log(`Calling API: ${apiUrl}`);
130+
console.log(`📡 Calling API: ${apiUrl}`);
109131

132+
<<<<<<< HEAD
133+
// Call the OpenReadme API with POST method (as per your route.ts)
134+
=======
135+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
110136
const response = await fetch(apiUrl, {
111-
method: 'GET',
137+
method: 'POST',
112138
headers: {
113139
'Accept': 'application/json',
114140
'Content-Type': 'application/json',
141+
<<<<<<< HEAD
142+
'User-Agent': 'OpenReadme-Workflow'
143+
},
144+
body: JSON.stringify(requestBody)
145+
=======
115146
'Authorization': `token ${GITHUB_TOKEN}`
116147
}
148+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
117149
});
118150

119-
console.log(`Response status: ${response.status} ${response.statusText}`);
151+
console.log(`📊 Response status: ${response.status} ${response.statusText}`);
120152

121153
if (!response.ok) {
122-
const error = await response.text();
123-
throw new Error(`API error: ${error}`);
154+
const errorText = await response.text();
155+
console.error(`❌ API error response: ${errorText}`);
156+
throw new Error(`API error (${response.status}): ${errorText}`);
124157
}
125158

126159
const result = await response.json();
160+
<<<<<<< HEAD
161+
console.log(`✅ Successfully generated image for ${username}`);
162+
console.log(`🔗 Image URL: ${result.url}`);
163+
console.log(`📝 Method: ${result.method}`);
164+
165+
=======
127166
console.log(`✅ Successfully generated image for ${username}: ${result.url}`);
167+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
128168
return result.url;
129169

130170
} catch (error) {
131171
console.error(`❌ Error generating image for ${username}:`, error.message);
172+
console.error(`🔍 Stack trace:`, error.stack);
132173
return null;
133174
}
134175
}
135176

136177
// Process all users
137178
(async () => {
138-
const mappings = process.env.MAPPINGS.split(' ');
139-
console.log(`Found ${mappings.length} users to process`);
179+
try {
180+
const mappingsString = process.env.MAPPINGS || '';
181+
const mappings = mappingsString.split(' ').filter(m => m.trim());
182+
console.log(`📋 Found ${mappings.length} users to process`);
183+
console.log(`🔧 Using API URL: ${API_URL}`);
184+
185+
<<<<<<< HEAD
186+
if (mappings.length === 0) {
187+
console.log('⚠️ No user mappings found to process');
188+
return;
189+
}
140190

191+
let successCount = 0;
192+
let errorCount = 0;
193+
=======
141194
for (const mapping of mappings) {
142195
if (!mapping) continue;
143196
const [username, userId] = mapping.split('=');
144197
if (!username || !userId) continue;
198+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
199+
200+
for (const mapping of mappings) {
201+
if (!mapping.trim()) continue;
202+
203+
<<<<<<< HEAD
204+
const [username, userId] = mapping.split('=');
205+
if (!username || !userId) {
206+
console.warn(`⚠️ Invalid mapping format: ${mapping}`);
207+
continue;
208+
}
209+
210+
console.log(`\n${'='.repeat(50)}`);
211+
console.log(`🔄 Processing ${username} (${userId})`);
212+
console.log(`${'='.repeat(50)}`);
145213

146-
console.log(`\n--- Processing ${username} (${userId}) ---`);
214+
try {
215+
const imageUrl = await generateProfileImage(username, userId);
216+
if (imageUrl) {
217+
successCount++;
218+
console.log(`✅ Success for ${username}: ${imageUrl}`);
219+
} else {
220+
errorCount++;
221+
console.log(`❌ Failed for ${username}`);
222+
}
223+
224+
// Add delay to avoid rate limiting (2 seconds between requests)
225+
console.log(`⏳ Waiting 2 seconds before next request...`);
226+
await new Promise(resolve => setTimeout(resolve, 2000));
227+
228+
} catch (error) {
229+
errorCount++;
230+
console.error(`💥 Error processing ${username}:`, error.message);
231+
}
232+
}
233+
234+
console.log(`\n${'='.repeat(60)}`);
235+
console.log(`📊 WORKFLOW SUMMARY`);
236+
console.log(`${'='.repeat(60)}`);
237+
console.log(`✅ Successful: ${successCount}`);
238+
console.log(`❌ Failed: ${errorCount}`);
239+
console.log(`📋 Total: ${successCount + errorCount}`);
240+
console.log(`${'='.repeat(60)}`);
241+
242+
} catch (error) {
243+
console.error('💥 Workflow failed:', error.message);
244+
process.exit(1);
245+
}
246+
})();
247+
EOL
147248

249+
# Run the generation script with your deployed URL
250+
# TODO: Replace with your actual Vercel deployment URL
251+
=======
148252
try {
149253
const imageUrl = await generateProfileImage(username, userId);
150254
if (imageUrl) {
@@ -159,6 +263,7 @@ jobs:
159263
})();
160264
EOL
161265

266+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
162267
MAPPINGS="${{ steps.user-mappings.outputs.mappings }}" \
163268
API_URL="https://openreadme.vercel.app/api/openreadme" \
164269
node generate-images.js

0 commit comments

Comments
 (0)