@@ -13,6 +13,7 @@ interface GitLabTreeItem {
13
13
type : 'tree' | 'blob' ;
14
14
}
15
15
16
+ // Validate GitHub and GitLab URLs
16
17
export const validateGitHubUrl = ( url : string ) : boolean => {
17
18
const githubUrlPattern = / ^ h t t p s ? : \/ \/ g i t h u b \. c o m \/ [ \w - ] + \/ [ \w . - ] + \/ ? $ / ;
18
19
return githubUrlPattern . test ( url ) ;
@@ -24,15 +25,14 @@ export const validateGitLabUrl = (url: string): boolean => {
24
25
} ;
25
26
26
27
const getOctokit = ( ) => {
27
- const token = process . env . NEXT_PUBLIC_GITHUB_TOKEN ;
28
28
return new Octokit ( {
29
- auth : token ,
30
29
request : {
31
30
fetch : fetch ,
32
31
} ,
33
32
} ) ;
34
33
} ;
35
34
35
+ // Fetch project structure from GitHub or GitLab
36
36
export const fetchProjectStructure = async ( repoUrl : string , repoType : 'github' | 'gitlab' ) : Promise < TreeItem [ ] > => {
37
37
if ( repoType === 'github' ) {
38
38
return fetchGitHubProjectStructure ( repoUrl ) ;
@@ -81,16 +81,10 @@ const fetchGitHubProjectStructure = async (repoUrl: string): Promise<TreeItem[]>
81
81
82
82
const fetchGitLabProjectStructure = async ( repoUrl : string ) : Promise < TreeItem [ ] > => {
83
83
const projectId = encodeURIComponent ( repoUrl . split ( 'gitlab.com/' ) [ 1 ] ) ;
84
- const token = process . env . NEXT_PUBLIC_GITLAB_TOKEN ;
85
-
86
- if ( ! token ) {
87
- throw new Error ( 'Missing GitLab token.' ) ;
88
- }
89
84
90
85
try {
91
86
const response = await axios . get < GitLabTreeItem [ ] > ( `https://gitlab.com/api/v4/projects/${ projectId } /repository/tree` , {
92
87
params : { recursive : true , per_page : 100 } ,
93
- headers : { 'PRIVATE-TOKEN' : token } ,
94
88
} ) ;
95
89
96
90
return response . data . map ( ( item : GitLabTreeItem ) => ( {
@@ -106,6 +100,7 @@ const fetchGitLabProjectStructure = async (repoUrl: string): Promise<TreeItem[]>
106
100
}
107
101
} ;
108
102
103
+ // Generate and build project structure
109
104
export const generateStructure = ( tree : TreeItem [ ] ) : DirectoryMap => {
110
105
const structureMap : DirectoryMap = new Map ( ) ;
111
106
tree . forEach ( ( item : TreeItem ) => {
0 commit comments