This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
forked from advanced-security/set-codeql-language-matrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (47 loc) · 1.89 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import requests
import json
import sys
token = sys.argv[1]
endpoint = sys.argv[2]
exclude = sys.argv[3]
codeql_languages = ["cpp", "csharp", "go", "java", "javascript", "python", "ruby", "typescript", "kotlin"]
# Connect to the languages API and return languages
def get_languages():
headers = {'Authorization': 'Bearer ' + token, 'Accept': 'application/vnd.github.v3+json'}
response = requests.get(endpoint, headers=headers)
return response.json()
# Find the intersection of the languages returned by the API and the languages supported by CodeQL
def build_languages_list(languages):
languages = [language.lower() for language in languages.keys()]
for i in range(len(languages)):
if languages[i] == "c#":
languages[i] = ("csharp")
if languages[i] == "c++":
languages[i] = ("cpp")
if languages[i] == "c":
languages[i] = ("cpp")
if languages[i] == "typescript":
languages[i] = ("javascript")
if languages[i] == "kotlin":
languages[i] = ("java")
intersection = list(set(languages) & set(codeql_languages))
return intersection
# return a list of objects from language list if they are not in the exclude list
def exclude_languages(language_list):
excluded = [x.strip() for x in exclude.split(',')]
output = list(set(language_list).difference(excluded))
print("languages={}".format(output))
return output
# Set the output of the action
def set_action_output(output_name, value) :
if "GITHUB_OUTPUT" in os.environ :
with open(os.environ["GITHUB_OUTPUT"], "a") as f :
print("{0}={1}".format(output_name, value), file=f)
def main():
languages = get_languages()
language_list = build_languages_list(languages)
output = exclude_languages(language_list)
set_action_output("languages", json.dumps(output))
if __name__ == '__main__':
main()