/
TravisLintBear.py
55 lines (46 loc) · 1.74 KB
/
TravisLintBear.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
import requests
from coalib.bearlib.abstractions.Linter import linter
from dependency_management.requirements.GemRequirement import GemRequirement
@linter(executable='travis',
output_format='regex',
output_regex=r'\[x\]\s+(?P<message>.+)')
class TravisLintBear:
"""
A validator for your ``.travis.yml`` that attempts to reduce common build
errors such as:
- invalid YAML
- missing language key
- unsupported runtime versions of Ruby, PHP, OTP, etc.
- deprecated features or runtime aliases
"""
LANGUAGES = {'YAML'}
REQUIREMENTS = {GemRequirement('travis', '1.8.8')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'}
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Formatting', 'Syntax'}
SEE_MORE = 'https://docs.travis-ci.com/user/travis-lint'
CHECK_CONNECTION_URL = 'https://travis-ci.org/'
@classmethod
def check_prerequisites(cls): # pragma: no cover
url_status = cls.get_status_of_url(cls.CHECK_CONNECTION_URL)
base_check = super().check_prerequisites()
if base_check is not True:
return base_check
try:
if url_status is None:
return 'You are not connected to the internet.'
else:
url_status.raise_for_status()
return True
except requests.exceptions.HTTPError:
return 'Failed to establish a connection to the server.'
@staticmethod
def get_status_of_url(url):
try:
return requests.head(url, allow_redirects=False)
except requests.exceptions.RequestException:
return None
@staticmethod
def create_arguments(filename, file, config_file):
return 'lint', filename