Skip to content

Commit cc968ea

Browse files
committed
Add extra info from GitHub using Tags
Languages, Teams, DotNet versions
1 parent 030c126 commit cc968ea

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

src/github.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,84 @@ const getRepos = async () => {
4848
}
4949
}
5050

51+
const getLanguages = async (repo) => {
52+
try {
53+
const { data } = await octokit.request('GET /repos/{owner}/{repo}/languages', {
54+
owner: repo.full_name.split('/')[0],
55+
repo: repo.name,
56+
})
57+
const languages = Object.keys(data);
58+
return languages
59+
} catch (ex) {
60+
throw ex
61+
}
62+
}
63+
64+
const getTeams = async (repo) => {
65+
try {
66+
const { data } = await octokit.request('GET /repos/{owner}/{repo}/teams', {
67+
owner: repo.full_name.split('/')[0],
68+
repo: repo.name,
69+
})
70+
const teams = data.map((t) => t.name);
71+
return teams
72+
} catch (ex) {
73+
throw ex
74+
}
75+
}
76+
77+
78+
const getDotNetVersions = async (repo, keyword) => {
79+
try {
80+
const { data } = await octokit.request('GET https://api.github.com/search/code?q={keyword}+repo:{repo}', {
81+
repo: repo.full_name,
82+
keyword: keyword,
83+
headers: {
84+
accept: 'application/vnd.github.text-match+json'
85+
}
86+
})
87+
const matches = data.items.map((i) => {
88+
const split = i.text_matches[0].fragment.split(keyword);
89+
const foundValue = split[1]
90+
91+
const foundValue2 = foundValue.split(keyword.substring(1))[0]
92+
93+
const version = foundValue2.substring(0, foundValue2.length-2);
94+
return 'C# ' + version;
95+
});
96+
return matches.filter((x, i, a) => a.indexOf(x) == i); //only unique values
97+
} catch (ex) {
98+
throw ex
99+
}
100+
}
101+
102+
const enrichTags = async (serviceDefinition) => {
103+
if (serviceDefinition.metadata.tags === undefined || serviceDefinition.metadata.tags === null)
104+
{
105+
serviceDefinition.metadata.tags = [];
106+
}
107+
108+
const languages = await getLanguages(serviceDefinition._repo);
109+
serviceDefinition.metadata.tags.push(...languages);
110+
111+
const teams = await getTeams(serviceDefinition._repo);
112+
serviceDefinition.metadata.tags.push(...teams);
113+
114+
if (languages.includes('C#'))
115+
{
116+
const targetFrameworkVersions = await getDotNetVersions(serviceDefinition._repo, '<TargetFramework>');
117+
serviceDefinition.metadata.tags.push(...targetFrameworkVersions);
118+
119+
const targetFrameworkVersions2 = await getDotNetVersions(serviceDefinition._repo, '<TargetFrameworkVersion>');
120+
serviceDefinition.metadata.tags.push(...targetFrameworkVersions2);
121+
122+
//SLEEP NEEDED BECAUSE OF MAX CALLS/MINUTE - https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#rate-limit
123+
124+
}
125+
126+
serviceDefinition.metadata.tags = serviceDefinition.metadata.tags.filter((x, i, a) => a.indexOf(x) == i); //only unique values
127+
}
128+
51129
const parseServiceDefinition = async (repo, path) => {
52130
const repoData = []
53131
try {
@@ -61,6 +139,9 @@ const getRepos = async () => {
61139
serviceDefinition._catalog_file = data.html_url
62140
serviceDefinition._repo = repo
63141
serviceDefinition.status = 'OK'
142+
143+
await enrichTags(serviceDefinition);
144+
64145
repoData.push(serviceDefinition)
65146
}
66147
}
@@ -76,6 +157,7 @@ const getRepos = async () => {
76157
core.debug(`✋ Unable to find ${path} in ${repo.name}, not processing as 'push_missing' is false`)
77158
}
78159
}
160+
79161
return repoData
80162
}
81163

0 commit comments

Comments
 (0)