-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload-social-preview.js
More file actions
66 lines (51 loc) · 2.23 KB
/
Copy pathupload-social-preview.js
File metadata and controls
66 lines (51 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const puppeteer = require("puppeteer");
const path = require("path");
const TOKEN = process.argv[2];
const REPO = process.argv[3]; // e.g. "OpenAEC-Foundation/PDFjs-Claude-Skill-Package"
const IMG_PATH = process.argv[4];
async function uploadSocialPreview() {
const browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
});
const page = await browser.newPage();
// Login via token - GitHub accepts PAT as password with any username
const settingsUrl = `https://github.com/${REPO}/settings`;
// Set auth header for all requests
await page.setExtraHTTPHeaders({
'Authorization': `Bearer ${TOKEN}`
});
// Try direct navigation with auth
const response = await page.goto(settingsUrl, { waitUntil: "networkidle2", timeout: 30000 });
console.log(`Settings page status: ${response.status()}`);
// Check if we're authenticated
const title = await page.title();
console.log(`Page title: ${title}`);
// Check if we see the social preview section
const content = await page.content();
const hasSocialPreview = content.includes('social-preview') || content.includes('Social preview');
console.log(`Has social preview section: ${hasSocialPreview}`);
if (response.status() !== 200 || !hasSocialPreview) {
// Try basic auth approach instead
console.log("Trying basic auth...");
await page.setExtraHTTPHeaders({});
// Navigate to login
await page.goto('https://github.com/login', { waitUntil: "networkidle2" });
// Fill in credentials using token as password
await page.type('#login_field', 'FreekHeijting');
await page.type('#password', TOKEN);
await page.click('[name="commit"]');
await page.waitForNavigation({ waitUntil: "networkidle2", timeout: 15000 }).catch(() => {});
const loginTitle = await page.title();
console.log(`After login title: ${loginTitle}`);
// Now go to settings
await page.goto(settingsUrl, { waitUntil: "networkidle2", timeout: 15000 });
const settingsTitle = await page.title();
console.log(`Settings title: ${settingsTitle}`);
}
await browser.close();
}
uploadSocialPreview().catch(err => {
console.error("Error:", err.message);
process.exit(1);
});