Skip to content
Snippets Groups Projects
Commit 2d007b7d authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Clean up + dealing with code block

parent d2f882b3
No related branches found
No related tags found
No related merge requests found
Pipeline #777 passed
......@@ -362,14 +362,13 @@ https://forge.etsi.org/rep/cdm/pipeline-scripts/-/blob/main/common/Dockerfile.st
logging.debug(f"Looking at changes in {patched_file.source_file}")
lines_added = 0
lines_removed = 0
previous_change_lines_added = 0
for change in patched_file:
logging.debug(f'Change from patch details: source_start: {change.source_start} - target_start: {change.target_start}')
while index_source < change.source_start:
if mdLines[index_source-1].startswith("#"):
spec_with_changes.append((mdLines[index_source-1]+"\n\n", False))
spec_with_changes.append((mdLines[index_source-1].strip()+"\n\n", False))
else:
spec_with_changes.append((mdLines[index_source - 1]+"\n", False))
spec_with_changes.append((mdLines[index_source-1].strip()+"\n", False))
index_source += 1
# Sanity check
......@@ -393,15 +392,22 @@ https://forge.etsi.org/rep/cdm/pipeline-scripts/-/blob/main/common/Dockerfile.st
change_lines_removed += 1
else:
if line.value.startswith("#"):
spec_with_changes.append((line.value+"\n\n", False))
spec_with_changes.append((line.value.strip()+"\n\n", False))
else:
spec_with_changes.append((line.value + "\n", False))
spec_with_changes.append((line.value.strip() + "\n", False))
#spec_with_changes.append((mdLines[index_source-1], False))
index_source += 1
lines_added += change_lines_added
lines_removed += change_lines_removed
while index_source < len(mdLines):
if mdLines[index_source - 1].startswith("#"):
spec_with_changes.append((mdLines[index_source - 1].strip() + "\n\n", False))
else:
spec_with_changes.append((mdLines[index_source - 1].strip() + "\n", False))
index_source += 1
logging.debug(f'Applied changes. Total added lines: {lines_added}.Total removed lines {lines_removed}')
return spec_with_changes
......@@ -458,9 +464,9 @@ def find_clauses_with_changes(progress: Progress, mdLines_changes: list[Tuple[st
_taskID = progress.add_task('[blue]Find clauses with changes', start=False, total=0)
clauseregex = re.compile('^#+\s(\d+(\.\d+)*|Annex \w(\.\d+)*|\w*(\.\d+)*).*')
removedclauseregex = re.compile('^\~\~#+\s(\d+(\.\d+)*|Annex \w(\.\d+)*|\w+\s\w*(\.\d+)*).*')
addedclauseregex = re.compile('^\<span\sclass\=\"underline\"\>#+\s(\d+(\.\d+)*|Annex \w(\.\d+)*|\w+\s\w*(\.\d+)*).*')
clauseregex = re.compile('^#+\s(\d+(\.\d+)*|Annex \w(\.\d+)*|\w+(\s\w*)*(\.\d+)*).*')
removedclauseregex = re.compile('^\~\~#+\s(\d+(\.\d+)*|Annex \w(\.\d+)*|\w+(\s\w*)*(\.\d+)*).*')
addedclauseregex = re.compile('^\<span\sclass\=\"underline\"\>#+\s(\d+(\.\d+)*|Annex \w(\.\d+)*|\w+(\s\w*)*(\.\d+)*).*')
clauses: list[Clause] = []
changed_clauses: list[Clause] = []
......@@ -479,6 +485,7 @@ def find_clauses_with_changes(progress: Progress, mdLines_changes: list[Tuple[st
def checkClause(_matches):
nonlocal clause
nonlocal changeInClause
nonlocal change
if index - 2 == clause.from_id: # It is a subclause
clause.from_id = index
......@@ -490,13 +497,18 @@ def find_clauses_with_changes(progress: Progress, mdLines_changes: list[Tuple[st
if changeInClause:
changed_clauses.append(clause)
clause = Clause(line, index, index, _matches[0][0])
changeInClause = False
changeInClause = change
index = 1
ignoreRemovedmatches = False
ignoreAddedmatches = False
inCode = False
for line, change in mdLines_changes:
if change:
changeInClause = True
if line.startswith('#') or line.startswith("~~#") or line.startswith("<span class=\"underline\">#"):
if line.startswith(("```", "<span class=\"underline\">```")):
inCode = not inCode
if line.startswith(('#', "~~#", "<span class=\"underline\">#"), 0) and not inCode:
matches = re.findall(clauseregex, line) # Match heading
removedmatches = re.findall(removedclauseregex, line) # Match removed heading
addedmatches = re.findall(addedclauseregex, line) # Match removed heading
......@@ -504,16 +516,24 @@ def find_clauses_with_changes(progress: Progress, mdLines_changes: list[Tuple[st
if matches: # It may be the end of the clause or the start of a subclause
checkClause(matches)
elif removedmatches:
if not ignoreRemovedmatches:
checkClause(removedmatches)
ignoreAddedmatches = True
else:
ignoreRemovedmatches = False
elif addedmatches:
if not ignoreAddedmatches:
checkClause(addedmatches)
ignoreRemovedmatches = True
else:
ignoreAddedmatches = False
else: # it is last clause
print("Unknown heading")
index = index + 1
# Append last clause (usually History)
clause.to_id = index - 1
clause.to_id = len(mdLines_changes) - 1
clauses.append(clause)
if changeInClause:
changed_clauses.append(clause)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment