-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
62 lines (49 loc) · 2.2 KB
/
test.js
File metadata and controls
62 lines (49 loc) · 2.2 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
import 'dotenv/config';
import { Octokit } from '@octokit/rest';
async function testSetup() {
console.log('🧪 Testing GitHub Console Setup...\n');
// Check if token is provided
if (!process.env.GITHUB_TOKEN) {
console.error('❌ GITHUB_TOKEN not found in environment variables.');
console.log('📝 Please create a .env file with your GitHub token:');
console.log(' cp .env.example .env');
console.log(' # Edit .env and add your token');
process.exit(1);
}
console.log('✅ GitHub token found in environment');
try {
// Test GitHub API connection
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
console.log('🔗 Testing GitHub API connection...');
const { data: user } = await octokit.rest.users.getAuthenticated();
console.log(`✅ Successfully connected to GitHub API`);
console.log(`👤 Authenticated as: ${user.name || user.login} (@${user.login})`);
console.log(`📊 Public repos: ${user.public_repos}`);
console.log(`👥 Following: ${user.following}`);
console.log(`👥 Followers: ${user.followers}`);
// Test following list access
console.log('\n📥 Testing following list access...');
const { data: following } = await octokit.rest.users.listFollowingForUser({
username: user.login,
per_page: 5
});
console.log(`✅ Can access following list (showing first ${following.length} users):`);
following.forEach((user, index) => {
console.log(` ${index + 1}. ${user.login}`);
});
console.log('\n🎉 Setup test completed successfully!');
console.log('🚀 You can now run: npm run unfollow');
} catch (error) {
console.error('❌ GitHub API Error:', error.message);
if (error.status === 401) {
console.log('\n💡 This usually means:');
console.log(' - Invalid GitHub token');
console.log(' - Token doesn\'t have required scopes (user:follow)');
console.log(' - Token has expired');
}
process.exit(1);
}
}
testSetup();