Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge changes in the development branch #53

Merged
merged 55 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
1c12a73
[werror-unused-result-fix] checking return values for fscanf in Cemrg…
alonsoJASL Apr 27, 2021
d568a11
[werror-unused-result-fix] fixed type in MITK_INFOs in lines 839 and 857
alonsoJASL Apr 27, 2021
441970b
[CICD/bugfixes] Compilation warnings/errors fixed.
alonsoJASL Apr 29, 2021
d000247
Merge branch 'development' of https://github.com/CemrgDevelopers/Cemr…
alonsoJASL Apr 29, 2021
ba381c3
[feature] added CemrgCommonUtils: SetSegmentationEdgesToZero, FillHoles
alonsoJASL May 5, 2021
8c319e4
[feature][cmdapp] ScarProjection Options created
alonsoJASL May 7, 2021
93bf4e5
[bugfix] SetSegmentationEdgesToZero fix
alonsoJASL May 7, 2021
dfbe98c
Merge branch 'development' into feature/cmd-scarmap-projection-opts
alonsoJASL May 7, 2021
8c496fe
Fix compilation errors
onurulgen May 10, 2021
f70bf2b
MitkCemrgScarProjectionOptions - finished
alonsoJASL May 10, 2021
ffefeb9
Merge branch 'development' into feature/cmd-scarmap-projection-opts
alonsoJASL May 11, 2021
1a31150
Ditch GetDirectorySeparator calls since Windows recognises slashes
onurulgen May 19, 2021
13e93ec
Fix MLib and M3DLib paths for macOS
onurulgen May 19, 2021
36c0918
[minor] remove call to mitk::IOUtil::GetDirectorySeparator in cmdapp
alonsoJASL May 19, 2021
8f28d8c
Add automatic building and deploying of CemrgApp by using Github Actions
onurulgen May 20, 2021
abcaedb
Fix branch for Build & Deploy
onurulgen May 20, 2021
0ed5467
[feature] Splash screen with functionality to read cermgapp version f…
alonsoJASL May 21, 2021
c6e358b
[feature] nicer splashscreen with functionality and disclaimers
alonsoJASL May 24, 2021
863db4d
[feature] Splashscreen v1 - finished
alonsoJASL May 24, 2021
73234ee
Reduce clutter by adding Points and Point types to CemrgMeasure
onurulgen Jun 3, 2021
1a679db
Ditch docker for the sake of MIRTK libraries
onurulgen Jun 3, 2021
28e594c
Setup tests and add test for CemrgMeasure
onurulgen Jun 8, 2021
5af1890
Fix compilation errors in the test of CemrgMeasure
onurulgen Jun 11, 2021
c15c3d7
Fix build errors of tests
onurulgen Jun 15, 2021
fb7a1fd
Fix Build & Deploy Github Action to run if a release is published
onurulgen Jun 24, 2021
36d6657
Add Github Action for static code analysis
onurulgen Jun 24, 2021
29ea63b
Add Github Actions for Tests and Code Coverage
onurulgen Jun 24, 2021
c0f6f67
Small fixes for test template
onurulgen Jun 29, 2021
b6f753f
Add a common class for facilitating sharing among tests
onurulgen Jun 29, 2021
3853645
Modify CemrgMeasureTest to enable using of the common class
onurulgen Jun 29, 2021
ea69b08
Add surface data for tests
onurulgen Jun 29, 2021
d451c29
Add test and data for CemrgStrains
onurulgen Jul 19, 2021
6ac433d
Fix a bug in CemrgCommandLine::ExecuteSimpleTranslation
onurulgen Jul 14, 2021
97808a6
Fix a bug preventing image transformation for some images (CemrgComma…
onurulgen Jul 14, 2021
844872c
Fix the Github Action for Tests and Code Coverage
onurulgen Jul 27, 2021
b7127cd
Disable tests for CppMicroServices in the Github Action for Tests and…
onurulgen Jul 29, 2021
929d102
Reduce compilation time of CemrgApp Tests and Code Coverage
onurulgen Aug 3, 2021
c5904e8
Upgrade Code Analysis
onurulgen Aug 3, 2021
3e0e7d0
Update the app version in CemrgApp Build & Deploy
onurulgen Aug 3, 2021
cbe852a
Update the display of the version
onurulgen Aug 3, 2021
64b76a7
Add test and data for CemrgCommandLine
onurulgen Aug 4, 2021
14b03a6
Show badges for Build, Tests, Code Analysis, and Code Coverage in REA…
onurulgen Aug 4, 2021
0c61e33
Fix resource leaks
onurulgen Aug 5, 2021
954c4a0
Merge pull request #52 from CemrgDevelopers/feature/tests
onurulgen Aug 5, 2021
a4d61d6
[style-fix] fixed `if(verbose) MITK_INFO` statements.
alonsoJASL Aug 5, 2021
db1f4e4
[style-fix] CemrgCommandLine added debug variable and style changes
alonsoJASL Aug 6, 2021
e038511
[style-fix] CermgCommonUtils variables out of scope fixed
alonsoJASL Aug 6, 2021
d3a9766
Fix static code analysis errors
onurulgen Aug 13, 2021
89cc398
[style-fixes] ShadowDeclarations, knownunReadVariables, knownConditio…
alonsoJASL Oct 18, 2021
aeb009f
[style-fix] Added constructors for plugins.
alonsoJASL Oct 18, 2021
c92eb03
[style-fix] constructors, knownConditionsTrueFalse, unUsedVariables
alonsoJASL Oct 18, 2021
5703688
[style-fix] YZSegView shadowed declarations
alonsoJASL Oct 18, 2021
100fd84
[style-fix] Removed kcl.cemrgapp.renderwindow - no longer needed
alonsoJASL Oct 18, 2021
3e72b14
[doc] Added comprehensive description of commented placeholder variables
alonsoJASL Oct 20, 2021
2b050da
[style-fix] minor - CemrgAtriaClipper binary ball radius set to 1
alonsoJASL Oct 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions .github/code_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import argparse
from github import Github
import os

# Input variables from Github action
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
PR_NUM = int(os.getenv('PR_NUMBER'))
WORK_DIR = os.getenv('GITHUB_WORKSPACE')
REPO_NAME = os.getenv('GITHUB_REPOSITORY')
SHA = os.getenv('GITHUB_SHA')
COMMENT_TITLE = os.getenv('COMMENT_TITLE')
ONLY_PR_CHANGES = os.getenv('REPORT_PR_CHANGES_ONLY')

# Max characters per comment - 65536
# Make some room for HTML tags and error message
MAX_CHAR_COUNT_REACHED = '!Maximum character count per GitHub comment has been reached! Not all warnings/errors has been parsed!'
COMMENT_MAX_SIZE = 65000
current_comment_length = 0

def is_part_of_pr_changes(file_path, issue_file_line, files_changed_in_pr):
if ONLY_PR_CHANGES == "false":
return True

file_name = file_path[file_path.rfind('/')+1:]
print(f"Looking for issue found in file={file_name} ...")
for file, (status, lines_changed_for_file) in files_changed_in_pr.items():
print(f"Changed file by this PR {file} with status {status} and changed lines {lines_changed_for_file}")
if file == file_name:
if status == "added":
return True

for (start, end) in lines_changed_for_file:
if issue_file_line >= start and issue_file_line <= end:
return True

return False

def get_lines_changed_from_patch(patch):
lines_changed = []
lines = patch.split('\n')

for line in lines:
# Example line @@ -43,6 +48,8 @@
# ------------ ^
if line.startswith("@@"):
# Example line @@ -43,6 +48,8 @@
# ----------------------^
idx_beg = line.index("+")

# Example line @@ -43,6 +48,8 @@
# ^--^
idx_end = line[idx_beg:].index(",")
line_begin = int(line[idx_beg + 1 : idx_beg + idx_end])

idx_beg = idx_beg + idx_end
idx_end = line[idx_beg + 1 : ].index("@@")

num_lines = int(line[idx_beg + 1 : idx_beg + idx_end])

lines_changed.append((line_begin, line_begin + num_lines))

return lines_changed

def setup_changed_files():
files_changed = dict()

g = Github(GITHUB_TOKEN)
repo = g.get_repo(REPO_NAME)
pull_request = repo.get_pull(PR_NUM)
num_changed_files = pull_request.changed_files
print(f"Changed files {num_changed_files}")
files = pull_request.get_files()
for file in files:
# additions # blob_url # changes # contents_url # deletions # filename
# patch # previous_filename # raw_url # sha # status
# print(f"File: additions={file.additions} blob_url={file.blob_url} changes={file.changes} contents_url={file.contents_url}"\
# f"deletions={file.deletions} filename={file.filename} patch={file.patch} previous_filename={file.previous_filename}"\
# f"raw_url={file.raw_url} sha={file.sha} status={file.status} ")

if file.patch is not None:
lines_changed_for_file = get_lines_changed_from_patch(file.patch)
files_changed[file.filename] = (file.status, lines_changed_for_file)

return files_changed

def check_for_char_limit(incoming_line):
global current_comment_length
return (current_comment_length + len(incoming_line)) <= COMMENT_MAX_SIZE

def get_file_line_end(file, file_line_start):
num_lines = sum(1 for line in open(WORK_DIR + file))
return min(file_line_start + 5, num_lines)

def create_comment_for_output(tool_output, prefix, files_changed_in_pr):
issues_found = 0
global current_comment_length
output_string = ''
for line in tool_output:
if line.startswith(prefix):
line = line.replace(prefix, "")
file_path_end_idx = line.index(':')
file_path = line[:file_path_end_idx]
line = line[file_path_end_idx+1:]
file_line_start = int(line[:line.index(':')])
file_line_end = get_file_line_end(file_path, file_line_start)
description = f"\n```diff\n!Line: {file_line_start} - {line[line.index(' ')+1:]}``` \n"

new_line = f'\n\nhttps://github.com/{REPO_NAME}/blob/{SHA}{file_path}#L{file_line_start}-L{file_line_end} {description} <br>\n'

if is_part_of_pr_changes(file_path, file_line_start, files_changed_in_pr):
if check_for_char_limit(new_line):
output_string += new_line
current_comment_length += len(new_line)
issues_found += 1
else:
current_comment_length = COMMENT_MAX_SIZE
return output_string, issues_found

return output_string, issues_found

def read_files_and_parse_results(files_changed_in_pr):
parser = argparse.ArgumentParser()
parser.add_argument('-cc', '--cppcheck', help='Output file name for cppcheck', required=True)
cppcheck_file_name = parser.parse_args().cppcheck

cppcheck_content = ''
with open(cppcheck_file_name, 'r') as file:
cppcheck_content = file.readlines()

line_prefix = f'{WORK_DIR}'

cppcheck_comment, cppcheck_issues_found = create_comment_for_output(cppcheck_content, line_prefix, files_changed_in_pr)

return cppcheck_comment, cppcheck_issues_found

def prepare_comment_body(cppcheck_comment, cppcheck_issues_found):

if cppcheck_issues_found == 0:
full_comment_body = f'## <p align="center"><b> :white_check_mark: {COMMENT_TITLE} - no issues found! :white_check_mark: </b></p>'
else:
full_comment_body = f'## <p align="center"><b> :zap: {COMMENT_TITLE} :zap: </b></p> \n\n'

if len(cppcheck_comment) > 0:
full_comment_body +=f'<details> <summary> <b> :red_circle: Cppcheck found'\
f' {cppcheck_issues_found} {"issues" if cppcheck_issues_found > 1 else "issue"}! Click here to see details. </b> </summary> <br>'\
f'{cppcheck_comment} </details><br>\n'

if current_comment_length == COMMENT_MAX_SIZE:
full_comment_body += f'\n```diff\n{MAX_CHAR_COUNT_REACHED}\n```'

print(f'Repo={REPO_NAME} pr_num={PR_NUM} comment_title={COMMENT_TITLE}')

return full_comment_body

def create_or_edit_comment(comment_body):
g = Github(GITHUB_TOKEN)
repo = g.get_repo(REPO_NAME)
pr = repo.get_pull(PR_NUM)

comments = pr.get_issue_comments()
found_id = -1
comment_to_edit = None
for comment in comments:
if (comment.user.login == 'github-actions[bot]') and (COMMENT_TITLE in comment.body):
found_id = comment.id
comment_to_edit = comment
break

if found_id != -1:
comment_to_edit.edit(body = comment_body)
else:
pr.create_issue_comment(body = comment_body)


if __name__ == "__main__":
files_changed_in_pr = setup_changed_files()
cppcheck_comment, cppcheck_issues_found = read_files_and_parse_results(files_changed_in_pr)
comment_body = prepare_comment_body(cppcheck_comment, cppcheck_issues_found)
create_or_edit_comment(comment_body)
3 changes: 3 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage:
ignore:
- "CemrgApp/Modules/CemrgAppModule/test"
32 changes: 32 additions & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CemrgApp Code Analysis

on: [pull_request]

jobs:
Code-Analysis:
runs-on: ubuntu-20.04
steps:
- name: Install missing packages
run: |
sudo apt update
sudo apt install cppcheck -y
pip3 install --upgrade setuptools
pip3 install pygithub

- name: Install Qt
run: |
sudo pip3 install aqtinstall
sudo aqt install --outputdir /Qt 5.12.10 linux desktop -m qtcharts qtnetworkauth qtpurchasing qtdatavis3d qtscript qtvirtualkeyboard qtwebengine qtwebglplugin

- name: Clone CemrgApp
uses: actions/checkout@v2

- name: Code Analysis
env:
COMMENT_TITLE: Code Analysis Results
PR_NUMBER: ${{ github.event.pull_request.number }}
REPORT_PR_CHANGES_ONLY: false
GITHUB_TOKEN: ${{ github.token }}
run: |
cppcheck --enable=warning,style,performance,portability --std=c++14 --language=c++ --force --quiet ${{ github.workspace }}/CemrgApp -I /Qt/5.12.10/gcc_64/include --output-file=analysis.txt
python3 ${{ github.workspace }}/.github/code_analysis.py -cc analysis.txt
Loading