Skip to content

Commit b85bb54

Browse files
gitea
1 parent 8d22b8e commit b85bb54

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

packages/backend/src/gitea.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AppContext, GitRepository } from './types.js';
55
import fetch from 'cross-fetch';
66
import { createLogger } from './logger.js';
77
import path from 'path';
8+
import micromatch from 'micromatch';
89

910
const logger = createLogger('Gitea');
1011

@@ -79,10 +80,68 @@ export const getGiteaReposFromConfig = async (config: GiteaConfig, ctx: AppConte
7980
repos = excludeReposByName(repos, config.exclude.repos, logger);
8081
}
8182
}
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+
}
82119

83120
return repos;
84121
}
85122

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+
86145
const getReposOwnedByUsers = async <T>(users: string[], api: Api<T>) => {
87146
const repos = (await Promise.all(users.map(async (user) => {
88147
logger.debug(`Fetching repos for user ${user}...`);

packages/backend/src/schemas/v2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export interface GiteaConfig {
167167
*/
168168
repos?: string[];
169169
};
170+
revisions?: GitRevisions;
170171
}
171172
export interface LocalConfig {
172173
/**

schemas/v2/index.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@
344344
}
345345
},
346346
"additionalProperties": false
347+
},
348+
"revisions": {
349+
"$ref": "#/definitions/GitRevisions"
347350
}
348351
},
349352
"required": [

0 commit comments

Comments
 (0)