@@ -10,64 +10,64 @@ const ghAuthHeaders = {
10
10
Authorization : `token ${ process . env . GH_TOKEN } `
11
11
}
12
12
13
- function filterAndProcessRepos ( repos ) {
13
+ function filterAndProcessRepos ( repos ) {
14
14
return repos
15
15
. filter ( repo => ! repo . fork )
16
- . map ( ( { full_name, description, ssh_url, hooks_url} ) => ( {
17
- name : full_name ,
16
+ . map ( ( {
18
17
description,
19
- hookUrl : hooks_url ,
20
- cloneUrl : ssh_url
21
- } ) )
18
+ full_name : name ,
19
+ ssh_url : cloneUrl ,
20
+ hooks_url : hookUrl
21
+ } ) => ( { name, description, hookUrl, cloneUrl } ) )
22
22
}
23
23
24
- function getPublicRepoParams ( ) {
24
+ function getPublicRepoParams ( ) {
25
25
const searchParams = new URLSearchParams ( )
26
26
for ( const [ key , value ] of Object . entries ( config . githubRepoListParams ) ) {
27
27
searchParams . set ( key , value )
28
28
}
29
29
return searchParams
30
30
}
31
31
32
- async function getPublicRepos ( ) {
32
+ async function getPublicRepos ( ) {
33
33
const searchParams = getPublicRepoParams ( )
34
34
const response = await fetch ( `${ GH_API_BASE } /user/repos?${ searchParams } ` , { headers : ghAuthHeaders } )
35
35
const json = await response . json ( )
36
36
return filterAndProcessRepos ( json )
37
37
}
38
38
39
- async function createMetaList ( repos ) {
39
+ async function createMetaList ( repos ) {
40
40
console . log ( '[INFO]' , 'Creating list of cloned directories' )
41
41
const list = JSON . stringify ( repos . map ( repo => repo . name ) )
42
42
const filePath = path . join ( config . repositoriesPath , 'repositories.json' )
43
43
await writeFile ( filePath , list , 'utf-8' )
44
44
return repos
45
45
}
46
46
47
- async function cloneToPath ( repo , log = false ) {
48
- if ( log ) console . log ( ` [INFO] Cloning %s` , repo . name )
47
+ async function cloneToPath ( repo , log = false ) {
48
+ if ( log ) console . log ( ' [INFO] Cloning %s' , repo . name )
49
49
const remotePath = repo . cloneUrl
50
50
const localPath = path . join ( config . repositoriesPath , repo . name )
51
51
await git . clone ( remotePath , localPath )
52
52
return localPath
53
53
}
54
54
55
- async function updateDescription ( localPath , description , log = false ) {
56
- if ( log ) console . log ( ` [INFO] Adding description for %s` , repo . name )
55
+ async function updateDescription ( localPath , repo , log = false ) {
56
+ if ( log ) console . log ( ' [INFO] Adding description for %s' , repo . name )
57
57
const descriptionFilePath = path . join ( localPath , '.git' , 'description' )
58
- await writeFile ( descriptionFilePath , description || '' , 'utf-8' )
58
+ await writeFile ( descriptionFilePath , repo . description || '' , 'utf-8' )
59
59
}
60
60
61
- async function createWebhook ( webhookUrl , log = false ) {
62
- if ( log ) console . log ( ` [INFO] Creating webhook for %s` , repo . name )
61
+ async function createWebhook ( repo , log = false ) {
62
+ if ( log ) console . log ( ' [INFO] Creating webhook for %s' , repo . name )
63
63
const requestBody = {
64
64
config : {
65
65
url : config . webhookBase + '/push' ,
66
66
content_type : 'json' ,
67
67
secret : process . env . WEBHOOK_SECRET
68
68
}
69
69
}
70
- await fetch ( webhookUrl , {
70
+ await fetch ( repo . hookUrl , {
71
71
method : 'POST' ,
72
72
headers : {
73
73
'Content-Type' : 'application/json' ,
0 commit comments