CatPtain commited on
Commit
cd3995d
·
verified ·
1 Parent(s): 08a9a1b

Upload githubService.js

Browse files
backend/src/services/githubService.js CHANGED
@@ -37,19 +37,48 @@ class GitHubService {
37
 
38
  console.log('GitHub API connection successful:', response.data.login);
39
 
40
- // 测试仓库访问
41
  const repoResults = [];
42
  for (const repoUrl of this.repositories) {
43
  try {
44
  const { owner, repo } = this.parseRepoUrl(repoUrl);
 
 
45
  const repoResponse = await axios.get(`${this.apiUrl}/repos/${owner}/${repo}`, {
46
  headers: {
47
  'Authorization': `token ${this.token}`,
48
  'Accept': 'application/vnd.github.v3+json'
49
  }
50
  });
51
- repoResults.push({ url: repoUrl, accessible: true, name: repoResponse.data.full_name });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  } catch (error) {
 
53
  repoResults.push({ url: repoUrl, accessible: false, error: error.message });
54
  }
55
  }
 
37
 
38
  console.log('GitHub API connection successful:', response.data.login);
39
 
40
+ // 测试仓库访问和权限
41
  const repoResults = [];
42
  for (const repoUrl of this.repositories) {
43
  try {
44
  const { owner, repo } = this.parseRepoUrl(repoUrl);
45
+
46
+ // 检查仓库基本信息
47
  const repoResponse = await axios.get(`${this.apiUrl}/repos/${owner}/${repo}`, {
48
  headers: {
49
  'Authorization': `token ${this.token}`,
50
  'Accept': 'application/vnd.github.v3+json'
51
  }
52
  });
53
+
54
+ // 检查权限
55
+ const permissions = repoResponse.data.permissions;
56
+ console.log(`Repository permissions for ${owner}/${repo}:`, permissions);
57
+
58
+ // 测试是否可以访问仓库内容
59
+ let canAccessContents = false;
60
+ try {
61
+ await axios.get(`${this.apiUrl}/repos/${owner}/${repo}/contents`, {
62
+ headers: {
63
+ 'Authorization': `token ${this.token}`,
64
+ 'Accept': 'application/vnd.github.v3+json'
65
+ }
66
+ });
67
+ canAccessContents = true;
68
+ } catch (contentsError) {
69
+ console.log(`Cannot access repository contents: ${contentsError.message}`);
70
+ }
71
+
72
+ repoResults.push({
73
+ url: repoUrl,
74
+ accessible: true,
75
+ name: repoResponse.data.full_name,
76
+ permissions,
77
+ canAccessContents,
78
+ defaultBranch: repoResponse.data.default_branch
79
+ });
80
  } catch (error) {
81
+ console.error(`Repository access error for ${repoUrl}:`, error.response?.data || error.message);
82
  repoResults.push({ url: repoUrl, accessible: false, error: error.message });
83
  }
84
  }