24
24
PROJECT_ID = None
25
25
MR_IID = None
26
26
API_TOKEN = None
27
+ GITHUB_TOKEN = None
28
+ GITHUB_REPOSITORY = None
29
+ GITHUB_PULL_REQUEST = None
27
30
28
31
29
32
def get_ci_name ():
@@ -37,6 +40,9 @@ def get_ci_name():
37
40
global PROJECT_ID
38
41
global MR_IID
39
42
global API_TOKEN
43
+ global GITHUB_TOKEN
44
+ global GITHUB_REPOSITORY
45
+ global GITHUB_PULL_REQUEST
40
46
41
47
if 'GITLAB_CI' in os .environ :
42
48
RUNNING_ON = 'GITLAB'
@@ -48,6 +54,11 @@ def get_ci_name():
48
54
RUNNING_ON = 'TRAVIS'
49
55
TRAVIS_REPO_SLUG = os .environ ['TRAVIS_REPO_SLUG' ]
50
56
TRAVIS_PULL_REQUEST = os .environ ['TRAVIS_PULL_REQUEST' ]
57
+ elif 'GITHUB_ACTIONS' in os .environ and os .environ ['GITHUB_ACTIONS' ] == 'true' :
58
+ RUNNING_ON = 'GITHUB'
59
+ GITHUB_TOKEN = os .environ ['GITHUB_TOKEN' ]
60
+ GITHUB_REPOSITORY = os .environ ['GITHUB_REPOSITORY' ]
61
+ GITHUB_PULL_REQUEST = os .environ ['GITHUB_PULL_REQUEST' ]
51
62
52
63
class CliOptions (object ):
53
64
'''
@@ -142,6 +153,16 @@ def get_diff_dir(self):
142
153
headers = {'Private-Token' : API_TOKEN }
143
154
path_key = "new_path"
144
155
change_key = "diff"
156
+ elif RUNNING_ON == "GITHUB" :
157
+ api_req_url = f"https://api.github.com/repos/{ GITHUB_REPOSITORY } " + \
158
+ f"/pulls/{ GITHUB_PULL_REQUEST } /files"
159
+ headers = {
160
+ "Authorization" : f"Bearer { GITHUB_TOKEN } " ,
161
+ "X-GitHub-Api-Version" : "2022-11-28" ,
162
+ "Accept" : "application/vnd.github+json"
163
+ }
164
+ path_key = "filename"
165
+ change_key = "patch"
145
166
else :
146
167
api_req_url = f"https://api.github.com/repos/{ TRAVIS_REPO_SLUG } " + \
147
168
f"/pulls/{ TRAVIS_PULL_REQUEST } /files"
@@ -170,7 +191,7 @@ def get_diff_dir(self):
170
191
remove_diff_regex = re .compile (r"^([ +-])(.*)$" , re .MULTILINE )
171
192
172
193
for change in changes :
173
- if change [ path_key ] is not None :
194
+ if path_key in change and change_key in change :
174
195
path_to_be_excluded = self .__is_excluded_path (change [path_key ])
175
196
if path_to_be_excluded == False :
176
197
curr_file = os .path .join (self .temp_dir .name , change [path_key ])
0 commit comments