|
| 1 | +const { Octokit } = require('octokit') |
| 2 | +const YAML = require('yaml') |
| 3 | +const core = require('@actions/core') |
| 4 | + |
| 5 | +const getRepos = async () => { |
| 6 | + const GITHUB_TOKEN = core.getInput('github_token') |
| 7 | + const repositoryType = core.getInput('repository_type') || 'all' |
| 8 | + const repositoryFilter = core.getInput('repository_filter') || '.*' |
| 9 | + const owner = core.getInput('github_owner') |
| 10 | + const catalogFile = core.getInput('catalog_file') || 'catalog-info.yaml' |
| 11 | + const repositoryFilterRegex = new RegExp(repositoryFilter) |
| 12 | + |
| 13 | + const octokit = new Octokit({ auth: GITHUB_TOKEN }) |
| 14 | + |
| 15 | + const repos = await octokit.paginate('GET /orgs/{owner}/repos', |
| 16 | + { |
| 17 | + owner: owner, |
| 18 | + type: repositoryType, |
| 19 | + sort: 'full_name', |
| 20 | + per_page: 100 |
| 21 | + }) |
| 22 | + core.info(`Using repository filter: ${repositoryFilter}`) |
| 23 | + core.info(`Found ${repos.length} github repositories, now getting service data for those that match the filter ...`) |
| 24 | + const repoData = [] |
| 25 | + for (const repo of repos) { |
| 26 | + if (repo.name.match(repositoryFilterRegex)) { |
| 27 | + try { |
| 28 | + const { data } = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', { |
| 29 | + owner: repo.full_name.split('/')[0], |
| 30 | + repo: repo.name, |
| 31 | + path: catalogFile |
| 32 | + }) |
| 33 | + if (data) { |
| 34 | + const base64content = Buffer.from(data.content, 'base64') |
| 35 | + const serviceDefinition = YAML.parse(base64content.toString('utf8')) |
| 36 | + serviceDefinition._repo = repo |
| 37 | + serviceDefinition.status = 'OK' |
| 38 | + repoData.push(serviceDefinition) |
| 39 | + } |
| 40 | + } catch (ex) { |
| 41 | + repoData.push({ |
| 42 | + status: `${catalogFile} missing`, |
| 43 | + _repo: repo |
| 44 | + }) |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + core.info(`Processed ${repoData.length} matching repositories`) |
| 49 | + return repoData |
| 50 | +} |
| 51 | + |
| 52 | +exports.getRepos = getRepos |
0 commit comments