Skip to content

Commit 5ea66e7

Browse files
feat(scanner): support github in scanner
1 parent de12ccf commit 5ea66e7

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-FileCopyrightText: © 2020 Siemens AG
2+
# SPDX-FileCopyrightText: © [email protected]
3+
# SPDX-FileCopyrightText: © [email protected]
4+
5+
# SPDX-License-Identifier: FSFAP
6+
7+
name: Check diff for license with Fossology
8+
9+
on:
10+
pull_request:
11+
12+
jobs:
13+
check-license:
14+
name: Check license
15+
runs-on: ubuntu-22.04
16+
steps:
17+
- uses: actions/checkout@v3
18+
- run: |
19+
docker run --rm --name "fossologyscanner" -w "/opt/repo" -v ${PWD}:/opt/repo \
20+
-e GITHUB_TOKEN=${{ github.token }} \
21+
-e GITHUB_PULL_REQUEST=${{ github.event.number }} \
22+
-e GITHUB_REPOSITORY=${{ github.repository }} \
23+
-e GITHUB_ACTIONS \
24+
fossology/fossology:scanner "/bin/fossologyscanner" nomos ojo
25+
26+
check-copyright:
27+
name: Check copyright
28+
runs-on: ubuntu-22.04
29+
steps:
30+
- uses: actions/checkout@v3
31+
- run: |
32+
docker run --rm --name "fossologyscanner" -w "/opt/repo" -v ${PWD}:/opt/repo \
33+
-e GITHUB_TOKEN=${{ github.token }} \
34+
-e GITHUB_PULL_REQUEST=${{ github.event.number }} \
35+
-e GITHUB_REPOSITORY=${{ github.repository }} \
36+
-e GITHUB_ACTIONS \
37+
fossology/fossology:scanner "/bin/fossologyscanner" copyright keyword

utils/automation/fossologyscanner.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
PROJECT_ID = None
2525
MR_IID = None
2626
API_TOKEN = None
27+
GITHUB_TOKEN = None
28+
GITHUB_REPOSITORY = None
29+
GITHUB_PULL_REQUEST = None
2730

2831

2932
def get_ci_name():
@@ -37,6 +40,9 @@ def get_ci_name():
3740
global PROJECT_ID
3841
global MR_IID
3942
global API_TOKEN
43+
global GITHUB_TOKEN
44+
global GITHUB_REPOSITORY
45+
global GITHUB_PULL_REQUEST
4046

4147
if 'GITLAB_CI' in os.environ:
4248
RUNNING_ON = 'GITLAB'
@@ -48,6 +54,11 @@ def get_ci_name():
4854
RUNNING_ON = 'TRAVIS'
4955
TRAVIS_REPO_SLUG = os.environ['TRAVIS_REPO_SLUG']
5056
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']
5162

5263
class CliOptions(object):
5364
'''
@@ -142,6 +153,16 @@ def get_diff_dir(self):
142153
headers = {'Private-Token': API_TOKEN}
143154
path_key = "new_path"
144155
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"
145166
else:
146167
api_req_url = f"https://api.github.com/repos/{TRAVIS_REPO_SLUG}" + \
147168
f"/pulls/{TRAVIS_PULL_REQUEST}/files"
@@ -170,7 +191,7 @@ def get_diff_dir(self):
170191
remove_diff_regex = re.compile(r"^([ +-])(.*)$", re.MULTILINE)
171192

172193
for change in changes:
173-
if change[path_key] is not None:
194+
if path_key in change and change_key in change:
174195
path_to_be_excluded = self.__is_excluded_path(change[path_key])
175196
if path_to_be_excluded == False:
176197
curr_file = os.path.join(self.temp_dir.name, change[path_key])

0 commit comments

Comments
 (0)