Skip to content

Commit bcb6307

Browse files
2 parents 16a04d4 + b4ad335 commit bcb6307

File tree

2 files changed

+100
-22
lines changed

2 files changed

+100
-22
lines changed

.github/workflows/generate-profiles.yml

Lines changed: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ on:
77
- cron: '0 0 * * *'
88

99
permissions:
10-
contents: write # Required for pushing changes
11-
pull-requests: write # Required for creating pull requests
12-
packages: read # Required for reading package information
10+
contents: write
11+
pull-requests: write
12+
packages: read
1313
actions: read
1414

1515
jobs:
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/checkout@v4
2121
with:
2222
token: ${{ secrets.IMAGE_TOKEN || github.token }}
23-
fetch-depth: 0 # Fetch all history for all branches and tags
23+
fetch-depth: 0
2424

2525
- name: Setup Node.js
2626
uses: actions/setup-node@v4
@@ -34,33 +34,54 @@ jobs:
3434
- name: Read user mappings
3535
id: user-mappings
3636
run: |
37-
# Read the user-mapping.json file
3837
MAPPINGS=$(jq -r 'to_entries | map("\(.key)=\(.value)") | join(" ")' data/user-mapping.json)
3938
echo "mappings=${MAPPINGS}" >> $GITHUB_OUTPUT
4039
40+
- name: Configure Git
41+
run: |
42+
git config --global user.name "github-actions[bot]"
43+
git config --global user.email "[email protected]"
44+
git config --global --add safe.directory /github/workspace
45+
46+
- name: Stage any existing changes
47+
run: |
48+
git config --global --add safe.directory /github/workspace
49+
git add .
50+
51+
- name: Commit any existing changes
52+
run: |
53+
git diff-index --quiet HEAD || git commit -m "chore: update generated files [skip ci]"
54+
55+
- name: Pull latest changes
56+
run: git pull origin main --rebase
57+
4158
- name: Generate profile images
4259
env:
4360
GITHUB_REPOSITORY: ${{ github.repository }}
4461
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
4562
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4663
run: |
47-
# Install required dependencies
4864
npm install node-fetch@2
4965
50-
# Create the generation script
5166
cat > generate-images.js << 'EOL'
5267
const fs = require('fs');
5368
const fetch = require('node-fetch');
5469
70+
<<<<<<< HEAD
5571
// Get the API URL from environment variables
5672
const API_URL = https://openreadme.vercel.app/api/openreadme || 'http://localhost:3000';
73+
=======
74+
const API_URL = process.env.API_URL || 'http://localhost:3000';
75+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
5776
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
77+
const REPO_OWNER = 'Open-Dev-Society';
78+
const REPO_NAME = 'openreadme';
5879

5980
async function generateProfileImage(username, userId) {
6081
try {
6182
console.log(`🎨 Generating image for ${username} (${userId})...`);
6283

63-
// First, get the user data from GitHub API
84+
// Get user data from GitHub API
6485
const userResponse = await fetch(`https://api.github.com/users/${username}`, {
6586
headers: {
6687
'Authorization': `token ${GITHUB_TOKEN}`,
@@ -76,35 +97,55 @@ jobs:
7697

7798
const userData = userResponse.ok ? await userResponse.json() : { login: username };
7899

100+
<<<<<<< HEAD
79101
// Prepare the data for the OpenReadme API (using POST method)
80102
const requestBody = {
81103
username: username,
82104
github: username
83105
};
84106

85107
// Add query parameters for additional data
108+
=======
109+
// Build API URL with repository parameters
110+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
86111
const params = new URLSearchParams({
87112
n: userData.name || username,
88113
i: userData.avatar_url || '',
89114
g: username,
90115
x: userData.twitter_username || '',
116+
<<<<<<< HEAD
91117
l: userData.blog || userData.html_url || '',
92118
p: userData.html_url || `https://github.com/${username}`,
93119
t: 'classic'
120+
=======
121+
l: userData.blog || userData.html_url,
122+
p: userData.html_url,
123+
t: 'classic',
124+
repo: `${REPO_OWNER}/${REPO_NAME}`,
125+
path: 'stats/usage-log.json'
126+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
94127
});
95128

96129
const apiUrl = `${API_URL}?${params.toString()}`;
97130
console.log(`📡 Calling API: ${apiUrl}`);
98131

132+
<<<<<<< HEAD
99133
// Call the OpenReadme API with POST method (as per your route.ts)
134+
=======
135+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
100136
const response = await fetch(apiUrl, {
101137
method: 'POST',
102138
headers: {
103139
'Accept': 'application/json',
104140
'Content-Type': 'application/json',
141+
<<<<<<< HEAD
105142
'User-Agent': 'OpenReadme-Workflow'
106143
},
107144
body: JSON.stringify(requestBody)
145+
=======
146+
'Authorization': `token ${GITHUB_TOKEN}`
147+
}
148+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
108149
});
109150

110151
console.log(`📊 Response status: ${response.status} ${response.statusText}`);
@@ -116,10 +157,14 @@ jobs:
116157
}
117158

118159
const result = await response.json();
160+
<<<<<<< HEAD
119161
console.log(`✅ Successfully generated image for ${username}`);
120162
console.log(`🔗 Image URL: ${result.url}`);
121163
console.log(`📝 Method: ${result.method}`);
122164

165+
=======
166+
console.log(`✅ Successfully generated image for ${username}: ${result.url}`);
167+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
123168
return result.url;
124169

125170
} catch (error) {
@@ -137,17 +182,25 @@ jobs:
137182
console.log(`📋 Found ${mappings.length} users to process`);
138183
console.log(`🔧 Using API URL: ${API_URL}`);
139184

185+
<<<<<<< HEAD
140186
if (mappings.length === 0) {
141187
console.log('⚠️ No user mappings found to process');
142188
return;
143189
}
144190

145191
let successCount = 0;
146192
let errorCount = 0;
193+
=======
194+
for (const mapping of mappings) {
195+
if (!mapping) continue;
196+
const [username, userId] = mapping.split('=');
197+
if (!username || !userId) continue;
198+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
147199

148200
for (const mapping of mappings) {
149201
if (!mapping.trim()) continue;
150202

203+
<<<<<<< HEAD
151204
const [username, userId] = mapping.split('=');
152205
if (!username || !userId) {
153206
console.warn(`⚠️ Invalid mapping format: ${mapping}`);
@@ -195,21 +248,33 @@ jobs:
195248

196249
# Run the generation script with your deployed URL
197250
# TODO: Replace with your actual Vercel deployment URL
251+
=======
252+
try {
253+
const imageUrl = await generateProfileImage(username, userId);
254+
if (imageUrl) {
255+
console.log(`Image URL: ${imageUrl}`);
256+
}
257+
await new Promise(resolve => setTimeout(resolve, 1000));
258+
} catch (error) {
259+
console.error(`Error processing ${username}:`, error);
260+
}
261+
}
262+
console.log('\n--- All users processed ---');
263+
})();
264+
EOL
265+
266+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
198267
MAPPINGS="${{ steps.user-mappings.outputs.mappings }}" \
199268
API_URL="https://openreadme.vercel.app/api/openreadme" \
200269
node generate-images.js
201270

202-
- name: Pull latest changes
203-
run: git pull origin main --rebase
204271
- name: Commit and push changes
205272
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main'
206273
env:
207274
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN || secrets.IMAGE_TOKEN }}
208275
run: |
209-
git config --global user.name "github-actions[bot]"
210-
git config --global user.email "[email protected]"
211-
git config --global --add safe.directory /github/workspace
212276
git add .
213-
git diff --quiet && git diff --staged --quiet || \
214-
(git commit -m "chore: update profile images [skip ci]" && \
215-
git push https://${{ github.actor }}:[email protected]/${{ github.repository }}.git HEAD:main)
277+
if ! git diff-index --quiet HEAD --; then
278+
git commit -m "chore: update profile images [skip ci]" && \
279+
git push https://${{ github.actor }}:[email protected]/${{ github.repository }}.git HEAD:main
280+
fi

generate-images.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ const fs = require('fs');
22
const fetch = require('node-fetch');
33
const { execSync } = require('child_process');
44

5-
// Get the API URL from environment variables
65
const API_URL = process.env.API_URL || 'http://localhost:3000';
6+
<<<<<<< HEAD
77
const GITHUB_TOKEN = process.env.GITHUB_TOKEN || process.env.IMAGE_TOKEN;
8+
=======
9+
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
10+
const REPO_OWNER = 'Open-Dev-Society';
11+
const REPO_NAME = 'openreadme';
12+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
813

914
async function generateProfileImage(username, userId) {
1015
try {
1116
console.log(`Generating image for ${username}...`);
1217

13-
// First, get the user data from GitHub API
18+
// Get user data from GitHub API
1419
const userResponse = await fetch(`https://api.github.com/users/${username}`, {
1520
headers: {
1621
'Authorization': `token ${GITHUB_TOKEN}`,
@@ -25,21 +30,32 @@ async function generateProfileImage(username, userId) {
2530

2631
const userData = await userResponse.json();
2732

33+
<<<<<<< HEAD
2834
// Prepare the data for the OpenReadme API
35+
=======
36+
// Build API URL with repository parameters
37+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
2938
const params = new URLSearchParams({
3039
n: userData.name || username,
3140
i: userData.avatar_url || '',
3241
github: username,
3342
x: userData.twitter_username || '',
43+
<<<<<<< HEAD
3444
l: userData.blog || userData.html_url || '',
3545
p: userData.html_url || '',
3646
t: 'classic'
47+
=======
48+
l: userData.blog || userData.html_url,
49+
p: userData.html_url,
50+
t: 'classic',
51+
repo: `${REPO_OWNER}/${REPO_NAME}`,
52+
path: 'stats/usage-log.json'
53+
>>>>>>> b4ad3355e213c9e7566f12029203124cdbcaa453
3754
});
3855

3956
const apiUrl = `${API_URL}?${params.toString()}`;
4057
console.log(`Calling API: ${apiUrl}`);
4158

42-
// Call the OpenReadme API with proper headers
4359
const response = await fetch(apiUrl, {
4460
method: 'GET',
4561
headers: {
@@ -58,7 +74,6 @@ async function generateProfileImage(username, userId) {
5874

5975
const result = await response.json();
6076
console.log(`✅ Successfully generated image for ${username}: ${result.url}`);
61-
6277
return result.url;
6378

6479
} catch (error) {
@@ -74,7 +89,6 @@ async function generateProfileImage(username, userId) {
7489

7590
for (const mapping of mappings) {
7691
if (!mapping) continue;
77-
7892
const [username, userId] = mapping.split('=');
7993
if (!username || !userId) continue;
8094

@@ -90,6 +104,5 @@ async function generateProfileImage(username, userId) {
90104
console.error(`Error processing ${username}:`, error);
91105
}
92106
}
93-
94107
console.log('\n--- All users processed ---');
95108
})();

0 commit comments

Comments
 (0)