Skip to content

Commit 0bc313a

Browse files
Merge pull request #82 from abnamro/2033043-finding-column
add column start and column end to finding
2 parents 31723d9 + 09348d4 commit 0bc313a

35 files changed

+250
-44
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""empty message
2+
3+
Revision ID: 9c5fa6db20f1
4+
Revises: ar399258p714
5+
Create Date: 2023-03-06 13:56:47.958406
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '9c5fa6db20f1'
14+
down_revision = 'ar399258p714'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
op.add_column('finding', sa.Column('column_start', sa.Integer(), nullable=False, server_default=sa.text("0")))
21+
op.add_column('finding', sa.Column('column_end', sa.Integer(), nullable=False, server_default=sa.text("0")))
22+
op.drop_constraint('uc_finding_per_branch', 'finding', type_='unique')
23+
op.create_unique_constraint('uc_finding_per_branch', 'finding',
24+
['commit_id', 'branch_id', 'rule_name', 'file_path', 'line_number',
25+
'column_start', 'column_end'])
26+
27+
28+
def downgrade():
29+
op.drop_constraint('uc_finding_per_branch', 'finding', type_='unique')
30+
op.create_unique_constraint('uc_finding_per_branch', 'finding',
31+
['commit_id', 'branch_id', 'rule_name', 'file_path', 'line_number'])
32+
op.drop_column('finding', 'column_start')
33+
op.drop_column('finding', 'column_end')

components/resc-backend/setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[metadata]
22
name = resc_backend
33
description = Repository Scanner - Backend
4-
version = 1.0.3
4+
version = 1.1.0
55
author = ABN AMRO
66
author_email = resc@nl.abnamro.com
77
url = https://github.com/ABNAMRO/repository-scanner

components/resc-backend/src/resc_backend/db/model/finding.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class DBfinding(Base):
1818
rule_name = Column(String(400), nullable=False)
1919
file_path = Column(String(500), nullable=False)
2020
line_number = Column(Integer, nullable=False)
21+
column_start = Column(Integer, nullable=False, default=0)
22+
column_end = Column(Integer, nullable=False, default=0)
2123
commit_id = Column(String(120))
2224
commit_message = Column(Text)
2325
commit_timestamp = Column(DateTime, default=datetime.utcnow().isoformat())
@@ -29,10 +31,10 @@ class DBfinding(Base):
2931
event_sent_on = Column(DateTime, nullable=True)
3032

3133
__table_args__ = (UniqueConstraint("commit_id", "branch_id", "rule_name", "file_path", "line_number",
32-
name="uc_finding_per_branch"),)
34+
"column_start", "column_end", name="uc_finding_per_branch"),)
3335

3436
def __init__(self, rule_name, file_path, line_number, commit_id, commit_message, commit_timestamp, author,
35-
email, status, comment, event_sent_on, branch_id):
37+
email, status, comment, event_sent_on, branch_id, column_start, column_end):
3638
self.email = email
3739
self.author = author
3840
self.commit_timestamp = commit_timestamp
@@ -45,6 +47,8 @@ def __init__(self, rule_name, file_path, line_number, commit_id, commit_message,
4547
self.comment = comment
4648
self.event_sent_on = event_sent_on
4749
self.branch_id = branch_id
50+
self.column_start = column_start
51+
self.column_end = column_end
4852

4953
@staticmethod
5054
def create_from_finding(finding):
@@ -61,6 +65,8 @@ def create_from_finding(finding):
6165
status=finding.status,
6266
comment=sanitized_comment,
6367
event_sent_on=finding.event_sent_on,
64-
branch_id=finding.branch_id
68+
branch_id=finding.branch_id,
69+
column_start=finding.column_start,
70+
column_end=finding.column_end
6571
)
6672
return db_finding

components/resc-backend/src/resc_backend/resc_web_service/crud/detailed_finding.py

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def get_detailed_findings(db_connection: Session, findings_filter: FindingsFilte
4949
model.DBfinding.id_,
5050
model.DBfinding.file_path,
5151
model.DBfinding.line_number,
52+
model.DBfinding.column_start,
53+
model.DBfinding.column_end,
5254
model.DBfinding.commit_id,
5355
model.DBfinding.commit_message,
5456
model.DBfinding.commit_timestamp,
@@ -201,6 +203,8 @@ def get_detailed_finding(db_connection: Session, finding_id: int) -> detailed_fi
201203
model.DBfinding.id_,
202204
model.DBfinding.file_path,
203205
model.DBfinding.line_number,
206+
model.DBfinding.column_start,
207+
model.DBfinding.column_end,
204208
model.DBfinding.commit_id,
205209
model.DBfinding.commit_message,
206210
model.DBfinding.commit_timestamp,

components/resc-backend/src/resc_backend/resc_web_service/crud/finding.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def create_findings(db_connection: Session, findings: List[finding_schema.Findin
8686
if branch_finding.commit_id == finding.commit_id and \
8787
branch_finding.rule_name == finding.rule_name and \
8888
branch_finding.file_path == finding.file_path and \
89-
branch_finding.line_number == finding.line_number:
89+
branch_finding.line_number == finding.line_number and \
90+
branch_finding.column_start == finding.column_start and \
91+
branch_finding.column_end == finding.column_end:
9092
# Store the already known finding
9193
db_findings.append(branch_finding)
9294
# Remove from the db_branch_findings to increase performance for the next loop

components/resc-backend/src/resc_backend/resc_web_service/endpoints/scans.py

+2
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ def create_scan_findings(scan_id: int,
198198
- **scan_id**: Id of the scan for which findings need to be inserted
199199
- **file_path**: file path
200200
- **line_number**: Line number
201+
- **column_start**: Column start
202+
- **column_end**: Column end
201203
- **commit_id**: commit hash
202204
- **commit_message**: Commit message
203205
- **commit_timestamp**: Commit timestamp

components/resc-backend/src/resc_backend/resc_web_service/schema/detailed_finding.py

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
class DetailedFindingBase(BaseModel):
1717
file_path: str
1818
line_number: conint(gt=-1)
19+
column_start: conint(gt=-1)
20+
column_end: conint(gt=-1)
1921
commit_id: constr(max_length=120)
2022
commit_message: str
2123
commit_timestamp: datetime.datetime

components/resc-backend/src/resc_backend/resc_web_service/schema/finding.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
class FindingBase(BaseModel):
1616
file_path: constr(max_length=500)
1717
line_number: conint(gt=-1)
18+
column_start: conint(gt=-1)
19+
column_end: conint(gt=-1)
1820
commit_id: constr(max_length=120)
1921
commit_message: str
2022
commit_timestamp: datetime.datetime
@@ -60,6 +62,8 @@ def create_from_db_entities(cls, db_finding: DBfinding, scan_ids: List[int]):
6062
id_=db_finding.id_,
6163
file_path=db_finding.file_path,
6264
line_number=db_finding.line_number,
65+
column_start=db_finding.column_start,
66+
column_end=db_finding.column_end,
6367
commit_id=db_finding.commit_id,
6468
commit_message=db_finding.commit_message,
6569
commit_timestamp=db_finding.commit_timestamp,

components/resc-backend/test_data/database_dummy_data.sql

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ INSERT INTO scan (branch_id, [timestamp], scan_type, last_scanned_commit, increm
3131
(3, '2022-02-24 17:00:00.000', 'BASE', 'qwerty1', 0, '0.0.0'),
3232
(3, '2022-03-24 17:00:00.000', 'BASE', 'qwerty1', 0, '0.0.0');
3333

34-
INSERT INTO finding (branch_id, file_path, line_number, commit_id, commit_message, commit_timestamp, author, email, rule_name, status, comment) VALUES
35-
(1, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#1', 'NOT_ANALYZED', NULL),
36-
(1, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#2', 'NOT_ANALYZED', NULL),
37-
(2, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#1', 'NOT_ANALYZED', NULL),
38-
(2, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#2', 'NOT_ANALYZED', NULL),
39-
(3, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#1', 'NOT_ANALYZED', NULL),
40-
(3, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#2', 'NOT_ANALYZED', NULL),
41-
(3, '/path/to/file', 123, 'qwerty2', 'this is commit 2', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#1', 'NOT_ANALYZED', NULL);
34+
INSERT INTO finding (branch_id, file_path, line_number, commit_id, commit_message, commit_timestamp, author, email, rule_name, status, comment, column_start, column_end) VALUES
35+
(1, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#1', 'NOT_ANALYZED', NULL, 1, 100),
36+
(1, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#2', 'NOT_ANALYZED', NULL, 0, 0),
37+
(2, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#1', 'NOT_ANALYZED', NULL, 1, 50),
38+
(2, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#2', 'NOT_ANALYZED', NULL, 42, 43),
39+
(3, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#1', 'NOT_ANALYZED', NULL, 12, 34),
40+
(3, '/path/to/file', 123, 'qwerty1', 'this is commit 1', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#2', 'NOT_ANALYZED', NULL, 21, 34),
41+
(3, '/path/to/file', 123, 'qwerty2', 'this is commit 2', '2021-01-01 00:00:00.000', 'developer', 'developer@abn.com', 'rule#1', 'NOT_ANALYZED', NULL, 12, 34);
4242

4343
INSERT INTO scan_finding(scan_id, finding_id) VALUES
4444
(1, 1),

0 commit comments

Comments
 (0)