Skip to content

Commit

Permalink
Insert an example using custom validator and sha
Browse files Browse the repository at this point in the history
  • Loading branch information
lbiaggi committed Mar 21, 2024
1 parent fcf747b commit 23309dd
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
9 changes: 9 additions & 0 deletions reqs/ext/.doorstop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
settings:
digits: 3
itemformat: yaml
parent: REQ
prefix: EXT
sep: ""
extensions:
item_validator: .req_sha_item_validator.py
item_sha_required: true
28 changes: 28 additions & 0 deletions reqs/ext/.req_sha_item_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: LGPL-3.0-only
from doorstop import DoorstopInfo, DoorstopWarning, DoorstopError
from subprocess import check_output
from copy import copy
from random import random


def item_validator(item):
if getattr(item, "references") == None:
return []

for ref in item.references:
if ref['sha'] != item._hash_reference(ref['path']):
yield DoorstopWarning("Hash has changed and it was not reviewed properly")

if 'modified' in ref['path']:
temp_item = copy(item)
current_value = item.is_reviewed()
check_output(
"echo '1111' > $(git rev-parse --show-toplevel)/reqs/ext/test-modified.file", shell=True)
temp_item.review()
next_value = item.is_reviewed()
check_output(
"echo '0000' > $(git rev-parse --show-toplevel)/reqs/ext/test-modified.file", shell=True)

yield DoorstopWarning(f"""This is a demonstration of a validator per folder identifying a external ref modified
without a proper review current SHA {current_value} modified SHA {next_value }.
Result: { next_value == current_value} """)
14 changes: 14 additions & 0 deletions reqs/ext/EXT001.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
active: true
derived: false
header: ''
level: 1.0
links: []
normative: true
ref: ''
references:
- path: reqs/ext/test.file
sha: 24d9b35c727e6c78676c2ad378a8c3c47cfb539f3583d3cd9e1eafee51d5679d
type: file
reviewed: n0xxAj0z-SqNcebKEu8p9HDE8jAs5I8Vz4kX-5ZieA4=
text: |
Test where we calculate the SHA
14 changes: 14 additions & 0 deletions reqs/ext/EXT002.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
active: true
derived: false
header: ''
level: 2.0
links: []
normative: true
ref: ''
references:
- path: reqs/ext/test-modified.file
sha: 49ca5d81054fdd20572294b9350b605d05e0df91da09a46fb8bde7fd6c1c172d
type: file
reviewed: arLWz1tqET94t2j7FG0ncvKpwGe5twDi-jPbBnikxho=
text: |
Test where we calculate the SHA, file modified during evaluation
1 change: 1 addition & 0 deletions reqs/ext/test-modified.file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000
1 change: 1 addition & 0 deletions reqs/ext/test.file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0001

0 comments on commit 23309dd

Please sign in to comment.