Passed
Push — develop ( 06f5de...753768 )
by Jace
05:09 queued 13s
created

.req_sha_item_validator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 21
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A item_validator() 0 19 5
1
# SPDX-License-Identifier: LGPL-3.0-only
2
from doorstop import DoorstopInfo, DoorstopWarning, DoorstopError
3
from subprocess import check_output
4
from copy import copy
5
from random import random
6
7
8
def item_validator(item):
9
    if getattr(item, "references") == None:
10
        return []
11
12
    for ref in item.references:
13
        if ref['sha'] != item._hash_reference(ref['path']):
14
            yield DoorstopWarning("Hash has changed and it was not reviewed properly")
15
16
        if 'modified' in ref['path']:
17
            temp_item = copy(item)
18
            current_value = item.is_reviewed()
19
            check_output(
20
                "echo '1111' > $(git rev-parse --show-toplevel)/reqs/ext/test-modified.file", shell=True)
21
            temp_item.review()
22
            next_value = item.is_reviewed()
23
            check_output(
24
                "echo '0000' > $(git rev-parse --show-toplevel)/reqs/ext/test-modified.file", shell=True)
25
26
            yield DoorstopWarning(f"""This is a demonstration of a validator per folder identifying a external ref modified
27
                      without a proper review current SHA {current_value} modified SHA {next_value }.
28
                      Result: { next_value == current_value} """)
29