mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-22 22:06:43 +00:00
Added support for costume languages. Fix #104
This commit is contained in:
parent
b27611eed1
commit
c70aafa22a
10
action.yml
10
action.yml
@ -79,4 +79,12 @@ inputs:
|
|||||||
ESCAPE:
|
ESCAPE:
|
||||||
description: 'Escape all special Markdown characters'
|
description: 'Escape all special Markdown characters'
|
||||||
required: false
|
required: false
|
||||||
default: true
|
default: true
|
||||||
|
LANGUAGES:
|
||||||
|
description: 'A collection of comma-delimited URLs or local paths starting from the current working directory of the action for costume languages'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
NO_STANDARD:
|
||||||
|
description: 'Exclude loading the default ''syntax.json'' and ''language.yml'' files from the repository'
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
90
main.py
90
main.py
@ -297,7 +297,6 @@ class TodoParser(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Determine if the Issues should be escaped.
|
# Determine if the Issues should be escaped.
|
||||||
self.should_escape = os.getenv('INPUT_ESCAPE', 'true') == 'true'
|
self.should_escape = os.getenv('INPUT_ESCAPE', 'true') == 'true'
|
||||||
|
|
||||||
# Load any custom identifiers, otherwise use the default.
|
# Load any custom identifiers, otherwise use the default.
|
||||||
custom_identifiers = os.getenv('INPUT_IDENTIFIERS')
|
custom_identifiers = os.getenv('INPUT_IDENTIFIERS')
|
||||||
self.identifiers = ['TODO']
|
self.identifiers = ['TODO']
|
||||||
@ -315,23 +314,82 @@ class TodoParser(object):
|
|||||||
|
|
||||||
self.languages_dict = None
|
self.languages_dict = None
|
||||||
|
|
||||||
# Load the languages data for ascertaining file types.
|
# Check if the standard collections should be loaded
|
||||||
languages_url = 'https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml'
|
if os.getenv('INPUT_NO_STANDARD', 'false') != 'true':
|
||||||
languages_request = requests.get(url=languages_url)
|
# Load the languages data for ascertaining file types.
|
||||||
if languages_request.status_code == 200:
|
languages_url = 'https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml'
|
||||||
languages_data = languages_request.text
|
languages_request = requests.get(url=languages_url)
|
||||||
yaml = YAML(typ='safe')
|
if languages_request.status_code == 200:
|
||||||
self.languages_dict = yaml.load(languages_data)
|
languages_data = languages_request.text
|
||||||
else:
|
yaml = YAML(typ='safe')
|
||||||
raise Exception('Cannot retrieve languages data. Operation will abort.')
|
self.languages_dict = yaml.load(languages_data)
|
||||||
|
else:
|
||||||
|
raise Exception('Cannot retrieve languages data. Operation will abort.')
|
||||||
|
|
||||||
# Load the comment syntax data for identifying comments.
|
# Load the comment syntax data for identifying comments.
|
||||||
syntax_url = 'https://raw.githubusercontent.com/alstr/todo-to-issue-action/master/syntax.json'
|
syntax_url = 'https://raw.githubusercontent.com/alstr/todo-to-issue-action/master/syntax.json'
|
||||||
syntax_request = requests.get(url=syntax_url)
|
syntax_request = requests.get(url=syntax_url)
|
||||||
if syntax_request.status_code == 200:
|
if syntax_request.status_code == 200:
|
||||||
self.syntax_dict = syntax_request.json()
|
self.syntax_dict = syntax_request.json()
|
||||||
|
else:
|
||||||
|
raise Exception('Cannot retrieve syntax data. Operation will abort.')
|
||||||
else:
|
else:
|
||||||
raise Exception('Cannot retrieve syntax data. Operation will abort.')
|
self.syntax_dict = []
|
||||||
|
self.languages_dict = {}
|
||||||
|
|
||||||
|
costume_languages = os.getenv('INPUT_LANGUAGES', '')
|
||||||
|
if costume_languages != '':
|
||||||
|
# Load all costume languages
|
||||||
|
for path in costume_languages.split(','):
|
||||||
|
try:
|
||||||
|
# Decide if the path is a url or local file
|
||||||
|
if path.startswith('http'):
|
||||||
|
languages_request = requests.get(path)
|
||||||
|
if languages_request.status_code != 200:
|
||||||
|
print('Cannot retrieve costume language file. (\''+path+'\')')
|
||||||
|
continue
|
||||||
|
data = languages_request.json()
|
||||||
|
else:
|
||||||
|
path = os.path.join(os.getcwd(), path)
|
||||||
|
if not os.path.exists(path) or not os.path.isfile(path):
|
||||||
|
print('Cannot retrieve costume language file. (\''+path+'\')')
|
||||||
|
continue
|
||||||
|
f = open(path)
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
# Iterate through the definitions
|
||||||
|
for lang in data:
|
||||||
|
# Add/Replace the language definition
|
||||||
|
self.languages_dict[lang['language']] = {}
|
||||||
|
self.languages_dict[lang['language']]['type'] = ''
|
||||||
|
self.languages_dict[lang['language']]['color'] = ''
|
||||||
|
self.languages_dict[lang['language']]['extensions'] = lang['extensions']
|
||||||
|
self.languages_dict[lang['language']]['source'] = ''
|
||||||
|
self.languages_dict[lang['language']]['ace_mode'] = ''
|
||||||
|
self.languages_dict[lang['language']]['language_id'] = 0
|
||||||
|
|
||||||
|
# Check if a syntax with the language name already exists
|
||||||
|
counter = 0
|
||||||
|
exists = False
|
||||||
|
for syntax in self.syntax_dict:
|
||||||
|
if syntax['language'] == lang['language']:
|
||||||
|
exists = True
|
||||||
|
break
|
||||||
|
|
||||||
|
counter = counter + 1
|
||||||
|
|
||||||
|
if exists:
|
||||||
|
# When the syntax exists it will be popped out of the list
|
||||||
|
self.syntax_dict.pop(counter)
|
||||||
|
|
||||||
|
# And be replaced with the new syntax definition
|
||||||
|
self.syntax_dict.append({
|
||||||
|
'language': lang['language'],
|
||||||
|
'markers': lang['markers']
|
||||||
|
})
|
||||||
|
except:
|
||||||
|
print('An error occurred in the custom language file (\''+path+'\')')
|
||||||
|
print('Please check the file, or if it represents undefined behavior, create an issue at \'https://github.com/alstr/todo-to-issue-action/issues\'')
|
||||||
|
|
||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
def parse(self, diff_file):
|
def parse(self, diff_file):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user