@@ -5,11 +5,15 @@ const FS = require('fs');
55
66const TAG = 'cleanup-gh-pages:' ;
77
8+ // Directories that should never be removed by cleanup
9+ const PROTECTED_DIRS = [ 'main' ] ;
10+
811const removeOldFromPath = ( isTag , data ) => {
912 const path = `public/${ isTag ? 'version' : 'review' } ` ;
1013 if ( FS . existsSync ( path ) && data ?. length > 0 ) {
14+ const dataNames = data . map ( ( item ) => item . name ) ;
1115 const dirsToDelete = FS . readdirSync ( path ) . filter (
12- ( file ) => ! data . find ( ( branch ) => branch . name === file )
16+ ( file ) => ! PROTECTED_DIRS . includes ( file ) && ! dataNames . includes ( file )
1317 ) ;
1418 if ( dirsToDelete ?. length > 0 ) {
1519 console . log (
@@ -35,18 +39,20 @@ const removeOldFromPath = (isTag, data) => {
3539
3640module . exports = async ( { github, context } ) => {
3741 const { repo, owner } = context . repo ;
38- const branches = await github . rest . repos . listBranches ( {
42+
43+ // Use pagination to fetch all branches and tags
44+ const branches = await github . paginate ( github . rest . repos . listBranches , {
3945 owner,
40- repo
46+ repo,
47+ per_page : 100
4148 } ) ;
42- const tags = await github . rest . repos . listTags ( {
49+ const tags = await github . paginate ( github . rest . repos . listTags , {
4350 owner,
44- repo
51+ repo,
52+ per_page : 100
4553 } ) ;
4654
4755 return {
48- deploy :
49- removeOldFromPath ( false , branches . data ) ||
50- removeOldFromPath ( true , tags . data )
56+ deploy : removeOldFromPath ( false , branches ) || removeOldFromPath ( true , tags )
5157 } ;
5258} ;
0 commit comments