Skip to content

Commit

Permalink
gh-36888: Fix failure of doc preview changes when an html is removed
Browse files Browse the repository at this point in the history
    
Fixes #36887.

Tested with #36892 and #36885.

<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes #1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes #12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- #12345: short description why this is a dependency
- #34567: ...
-->

- #36871

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: #36888
Reported by: Kwankyu Lee
Reviewer(s):
  • Loading branch information
Release Manager committed Dec 17, 2023
2 parents 8ba4c46 + 778195a commit 7ef39dd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions .ci/create-changes-html.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ for block in diff_blocks:
match = re.search(r'^diff --git a/(.*) b/\1', block, flags=re.MULTILINE)
if match:
doc = match.group(1)
path = 'html/' + doc
file_path = os.path.join('$DOC_REPOSITORY', doc)
with open(file_path, 'r') as file:
content = file.readlines()
try:
with open(file_path, 'r') as file:
content = file.readlines()
except FileNotFoundError:
content = []
count = 0
for line in block.splitlines():
if line.startswith('@@ -'):
Expand All @@ -77,8 +79,10 @@ for block in diff_blocks:
count += 1
content[i] = f'<span id="hunk{count}" style="visibility: hidden;"></span>' + content[i]
break
with open(file_path, 'w') as file:
file.writelines(content)
if content:
with open(file_path, 'w') as file:
file.writelines(content)
path = 'html/' + doc
hunks = '&nbsp;'.join(f'<a href="{path}#hunk{i+1}" class="hunk" target="_blank">#{i + 1}</a>' for i in range(count))
out_blocks.append(f'<p class="diff"><a href="{path}">{doc}</a>&nbsp;' + hunks + '&emsp;</p>'
+ '\n<pre><code class="language-diff">'
Expand Down

0 comments on commit 7ef39dd

Please sign in to comment.