@@ -79,14 +79,34 @@ EOF`, 'Setting up branch protection');
7979
8080function addToFileSyncAutomation ( repoUrl ) {
8181 console . log ( '⏳ Adding repository to file sync automation...' ) ;
82- const syncConfigUrl = 'repos/domdomegg/domdomegg/contents/.github/workflows/repo-file-sync.yaml' ;
83- const syncConfig = exec ( `gh api ${ syncConfigUrl } --jq .content | base64 -d` ) ;
8482
8583 const repoMatch = repoUrl . match ( / g i t h u b \. c o m [ / : ] ( [ \w - ] + ) \/ ( [ \w - ] + ) / ) ;
84+ if ( ! repoMatch ) {
85+ throw new Error ( `Could not parse repository URL: ${ repoUrl } ` ) ;
86+ }
87+
8688 const [ , owner , repo ] = repoMatch ;
8789 const newRepoEntry = ` ${ owner } /${ repo } ` ;
8890
89- if ( ! syncConfig . includes ( newRepoEntry . trim ( ) ) ) {
91+ // Create a temporary directory for cloning
92+ const tempDir = path . join ( __dirname , `.temp-clone-${ Date . now ( ) } ` ) ;
93+
94+ try {
95+ // Clone the repository
96+ console . log ( '⏳ Cloning domdomegg/domdomegg repository...' ) ;
97+ exec ( `git clone git@github.com:domdomegg/domdomegg.git ${ tempDir } ` ) ;
98+
99+ // Read the sync config file
100+ const syncConfigPath = path . join ( tempDir , '.github/workflows/repo-file-sync.yaml' ) ;
101+ const syncConfig = fs . readFileSync ( syncConfigPath , 'utf8' ) ;
102+
103+ // Check if already exists
104+ if ( syncConfig . includes ( newRepoEntry . trim ( ) ) ) {
105+ console . log ( 'ℹ️ Repository already in file sync automation' ) ;
106+ return ;
107+ }
108+
109+ // Update the file content
90110 let updatedConfig = syncConfig ;
91111
92112 // Add to Dependabot automation section
@@ -101,20 +121,21 @@ function addToFileSyncAutomation(repoUrl) {
101121 `$1$2\n${ newRepoEntry } ` ,
102122 ) ;
103123
104- const currentSha = exec ( `gh api ${ syncConfigUrl } --jq .sha` ) . trim ( ) ;
105-
106- const updatePayload = {
107- message : `Add ${ owner } /${ repo } to file sync automation` ,
108- content : Buffer . from ( updatedConfig ) . toString ( 'base64' ) ,
109- sha : currentSha ,
110- } ;
111-
112- exec ( `gh api ${ syncConfigUrl } -X PUT --input - << 'EOF'
113- ${ JSON . stringify ( updatePayload ) }
114- EOF` ) ;
115- console . log ( '✅ Added to file sync automation' ) ;
116- } else {
117- console . log ( 'ℹ️ Repository already in file sync automation' ) ;
124+ // Write the updated config back to the file
125+ fs . writeFileSync ( syncConfigPath , updatedConfig ) ;
126+
127+ // Commit and push changes
128+ console . log ( '⏳ Committing and pushing changes...' ) ;
129+ exec ( `cd ${ tempDir } && git add .github/workflows/repo-file-sync.yaml` ) ;
130+ exec ( `cd ${ tempDir } && git commit -m "Add ${ owner } /${ repo } to file sync automation"` ) ;
131+ exec ( `cd ${ tempDir } && git push origin master` ) ;
132+
133+ console . log ( '✅ Added to file sync automation via direct push' ) ;
134+ } finally {
135+ // Clean up temporary directory
136+ if ( fs . existsSync ( tempDir ) ) {
137+ exec ( `rm -rf ${ tempDir } ` ) ;
138+ }
118139 }
119140}
120141
0 commit comments