1+ # -*- mode:python; coding:utf-8 -*-
2+ # Copyright (c) 2020 IBM Corp. All rights reserved.
3+ #
4+ # Licensed under the Apache License, Version 2.0 (the "License");
5+ # you may not use this file except in compliance with the License.
6+ # You may obtain a copy of the License at
7+ #
8+ # http://www.apache.org/licenses/LICENSE-2.0
9+ #
10+ # Unless required by applicable law or agreed to in writing, software
11+ # distributed under the License is distributed on an "AS IS" BASIS,
12+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ # See the License for the specific language governing permissions and
14+ # limitations under the License.
15+
16+ import json
17+
18+ from compliance .check import ComplianceCheck
19+ from compliance .evidence import with_raw_evidences
20+
21+ class GitHubAPIVersionsCheck (ComplianceCheck ):
22+ """Perform analysis on GitHub supported versions API response evidence."""
23+
24+ @property
25+ def title (self ):
26+ """
27+ Return the title of the checks.
28+
29+ :returns: the title of the checks
30+ """
31+ return 'GitHub API Versions'
32+
33+ @with_raw_evidences ('github/api_versions.json' )
34+ def test_supported_versions (self , evidence ):
35+ """
36+ Check whether there are any supported versions.
37+
38+ Always warn about something, for demo purposes.
39+ """
40+ version_list = json .loads (evidence .content )
41+ versions_str = ', ' .join (version_list )
42+ if not version_list :
43+ self .add_failures (
44+ 'Supported GitHub API Versions Violation' ,
45+ f'No API versions were indicated as supported by GitHub.'
46+ )
47+ elif len (version_list ) == 1 :
48+ self .add_warnings (
49+ 'Supported GitHub API Versions Warning' ,
50+ f'There is only one supported version. Get with the program: { versions_str } '
51+ )
52+ elif len (version_list ) > 1 :
53+ self .add_warnings (
54+ 'Supported GitHub API Versions Warning' ,
55+ f'There are more than one supported versions. Check the docs for the latest changes: { versions_str } '
56+ )
57+
58+ def get_reports (self ):
59+ """
60+ Provide the check report name.
61+
62+ :returns: the report(s) generated for this check
63+ """
64+ return ['github/api_versions.md' ]
65+
66+ def msg_supported_versions (self ):
67+ """
68+ Supported GitHub API versions check notifier.
69+
70+ :returns: notification dictionary.
71+ """
72+ return {'subtitle' : 'Supported GitHub API Versions Violation' , 'body' : None }
0 commit comments