Created
April 4, 2023 19:06
-
-
Save BSFishy/437163239a4516a709302baf58faa40f to your computer and use it in GitHub Desktop.
Find usages of logos in OpenSearch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Octokit } from 'octokit' | |
const LOGOS = [ | |
'logoAppSearch', | |
'logoBeats', | |
'logoBusinessAnalytics', | |
'logoCloud', | |
'logoCloudEnterprise', | |
'logoCode', | |
'logoElastic', | |
'logoElasticStack', | |
'logoElasticsearch', | |
'logoEnterpriseSearch', | |
'logoKibana', | |
'logoLogging', | |
'logoLogstash', | |
'logoMaps', | |
'logoMetrics', | |
'logoObservability', | |
'logoSecurity', | |
'logoSiteSearch', | |
'logoUptime', | |
'logoWorkplaceSearch', | |
'addDataApp', | |
] | |
const APP_LOGOS = [ | |
'advancedSettingsApp', | |
'apmApp', | |
'appSearchApp', | |
'auditbeatApp', | |
'canvasApp', | |
'codeApp', | |
'consoleApp', | |
'crossClusterReplicationApp', | |
'dashboardApp', | |
'devToolsApp', | |
'discoverApp', | |
'emsApp', | |
'filebeatApp', | |
'gisApp', | |
'graphApp', | |
'grokApp', | |
'heartbeatApp', | |
'indexManagementApp', | |
'indexPatternApp', | |
'indexRollupApp', | |
'metricsApp', | |
'lensApp', | |
'logsApp', | |
'machineLearningApp', | |
'managementApp', | |
'metricbeatApp', | |
'notebookApp', | |
'packetbeatApp', | |
'pipelineApp', | |
'reportingApp', | |
'savedObjectsApp', | |
'searchProfilerApp', | |
'securityAnalyticsApp', | |
'securityApp', | |
'spacesApp', | |
'sqlApp', | |
'timelionApp', | |
'upgradeAssistantApp', | |
'uptimeApp', | |
'usersRolesApp', | |
'visualizeApp', | |
'watchesApp', | |
'workplaceSearchApp', | |
'dataVisualizer', | |
'createAdvancedJob', | |
'classificationJob', | |
'createMultiMetricJob', | |
'outlierDetectionJob', | |
'createPopulationJob', | |
'regressionJob', | |
'createSingleMetricJob', | |
] | |
const octokit = new Octokit({ | |
throttle: { | |
onRateLimit: (retryAfter: number, options: any) => { | |
if (options.request.retryCount < 5) { | |
// retry up to 5 times | |
return true; | |
} | |
}, | |
onSecondaryRateLimit: (retryAfter: number, options: any) => { | |
if (options.request.retryCount < 5) { | |
// retry up to 5 times | |
return true; | |
} | |
}, | |
} | |
}) | |
type RawData = { | |
path: string | |
html_url: string | |
repository: { | |
full_name: string | |
} | |
} | |
type FormattedData = { | |
[key: string]: { | |
[key: string]: { | |
html_url: string | |
count: number | |
} | |
} | |
} | |
function formatData(data: RawData[]): FormattedData { | |
let repos: FormattedData = {} | |
for (const item of data) { | |
const path = item.path | |
const full_name = item.repository.full_name | |
if (full_name === 'opensearch-project/oui') { | |
continue | |
} | |
if (!repos.hasOwnProperty(full_name)) { | |
repos[full_name] = {} | |
} | |
if (!repos[full_name].hasOwnProperty(path)) { | |
repos[full_name][path] = { | |
html_url: item.html_url, | |
count: 0, | |
} | |
} | |
repos[full_name][path].count++ | |
} | |
return repos | |
} | |
function countPoints(data: FormattedData): number { | |
let count = 0 | |
for (const repo of Object.keys(data)) { | |
const repoCount = Object.keys(data[repo]).length | |
count += repoCount | |
} | |
return count | |
} | |
function logData(search: string, count: number, data: FormattedData) { | |
console.log(`There are ${count} match(es) for \`${search}\`:`) | |
for (const repo of Object.keys(data)) { | |
console.log(` * In \`${repo}\` there is:`) | |
for (const match of Object.keys(data[repo])) { | |
const info = data[repo][match] | |
console.log(` * ${info.count} match(es) in [\`${match}\`](${info.html_url})`) | |
} | |
} | |
} | |
async function searchList(list: string[]) { | |
for (const logo of list) { | |
const result = await octokit.rest.search.code({ | |
q: `${logo} in:file org:opensearch-project`.replace(' ', '+') | |
}) | |
const data = formatData(result.data.items) | |
const count = countPoints(data) | |
if (count === 0) { | |
continue | |
} | |
logData(logo, count, data) | |
console.log() | |
} | |
} | |
async function run() { | |
console.log('# Usage of logos') | |
console.log() | |
await searchList(LOGOS) | |
console.log('# Usage of app logos') | |
console.log() | |
await searchList(APP_LOGOS) | |
} | |
run() | |
.catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment