@@ -5,6 +5,7 @@ import { AppContext, GitRepository } from './types.js';
5
5
import fetch from 'cross-fetch' ;
6
6
import { createLogger } from './logger.js' ;
7
7
import path from 'path' ;
8
+ import micromatch from 'micromatch' ;
8
9
9
10
const logger = createLogger ( 'Gitea' ) ;
10
11
@@ -79,10 +80,68 @@ export const getGiteaReposFromConfig = async (config: GiteaConfig, ctx: AppConte
79
80
repos = excludeReposByName ( repos , config . exclude . repos , logger ) ;
80
81
}
81
82
}
83
+
84
+ logger . debug ( `Found ${ repos . length } total repositories.` ) ;
85
+
86
+ if ( config . revisions ) {
87
+ if ( config . revisions . branches ) {
88
+ const branchGlobs = config . revisions . branches ;
89
+ repos = await Promise . all (
90
+ repos . map ( async ( repo ) => {
91
+ const [ owner , name ] = repo . name . split ( '/' ) ;
92
+ let branches = ( await getBranchesForRepo ( owner , name , api ) ) . map ( branch => branch . name ! ) ;
93
+ branches = micromatch . match ( branches , branchGlobs ) ;
94
+
95
+ return {
96
+ ...repo ,
97
+ branches,
98
+ } ;
99
+ } )
100
+ )
101
+ }
102
+
103
+ if ( config . revisions . tags ) {
104
+ const tagGlobs = config . revisions . tags ;
105
+ repos = await Promise . all (
106
+ repos . map ( async ( repo ) => {
107
+ const [ owner , name ] = repo . name . split ( '/' ) ;
108
+ let tags = ( await getTagsForRepo ( owner , name , api ) ) . map ( tag => tag . name ! ) ;
109
+ tags = micromatch . match ( tags , tagGlobs ) ;
110
+
111
+ return {
112
+ ...repo ,
113
+ tags,
114
+ } ;
115
+ } )
116
+ )
117
+ }
118
+ }
82
119
83
120
return repos ;
84
121
}
85
122
123
+ const getTagsForRepo = async < T > ( owner : string , repo : string , api : Api < T > ) => {
124
+ logger . debug ( `Fetching tags for repo ${ owner } /${ repo } ...` ) ;
125
+ const { durationMs, data : tags } = await measure ( ( ) =>
126
+ paginate ( ( page ) => api . repos . repoListTags ( owner , repo , {
127
+ page
128
+ } ) )
129
+ ) ;
130
+ logger . debug ( `Found ${ tags . length } tags in repo ${ owner } /${ repo } in ${ durationMs } ms.` ) ;
131
+ return tags ;
132
+ }
133
+
134
+ const getBranchesForRepo = async < T > ( owner : string , repo : string , api : Api < T > ) => {
135
+ logger . debug ( `Fetching branches for repo ${ owner } /${ repo } ...` ) ;
136
+ const { durationMs, data : branches } = await measure ( ( ) =>
137
+ paginate ( ( page ) => api . repos . repoListBranches ( owner , repo , {
138
+ page
139
+ } ) )
140
+ ) ;
141
+ logger . debug ( `Found ${ branches . length } branches in repo ${ owner } /${ repo } in ${ durationMs } ms.` ) ;
142
+ return branches ;
143
+ }
144
+
86
145
const getReposOwnedByUsers = async < T > ( users : string [ ] , api : Api < T > ) => {
87
146
const repos = ( await Promise . all ( users . map ( async ( user ) => {
88
147
logger . debug ( `Fetching repos for user ${ user } ...` ) ;
0 commit comments