-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Resolve semantic identifiers in wiki reverse-link parser #23201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4b26a27
5591548
5938265
2650b65
9448d5c
8e01a24
22c70f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,16 +32,31 @@ module Wikis::Concerns | |
| module UpdateReverseInlineWikiPageLinks | ||
| extend ActiveSupport::Concern | ||
|
|
||
| # Mirrors the prefix character class of the inline-text macro matcher. | ||
| # The trailing `(?!\w)` on the semantic branch keeps `#PROJ-1abc` from | ||
| # matching `#PROJ-1`; the numeric branch deliberately has no trailing | ||
| # boundary to preserve historic behaviour for inputs like `#13-blubb`. | ||
| # rubocop:disable Style/RedundantRegexpEscape | ||
| WP_REF_RE = / | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
| (?:[[:space:],~>\#\(\[\-]|^)\# | ||
| (?: | ||
| (\d+) | ||
| | | ||
| (#{WorkPackage::SemanticIdentifier::SEMANTIC_ID_PATTERN.source})(?!\w) | ||
| ) | ||
| /x | ||
| # rubocop:enable Style/RedundantRegexpEscape | ||
|
|
||
| def update_reverse_inline_wiki_page_links(wiki_page) | ||
| provider = Wikis::InternalProvider.enabled.first | ||
| return if provider.nil? | ||
|
|
||
| Wikis::ReverseInlinePageLink.where(provider:, identifier: wiki_page.id).delete_all | ||
|
|
||
| find_wp_links(wiki_page.text).uniq.each do |wp_id| | ||
| wp = WorkPackage.find_by(id: wp_id) | ||
| next if wp.nil? | ||
| identifiers = find_wp_links(wiki_page.text).uniq | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Should we also somehow
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch, I suppose we can take care of that at the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 TDD'd this — the failing test went green on first run, so no production change. Added 22c70f9 as regression coverage: a body with The reason it already works: |
||
| return if identifiers.empty? | ||
|
|
||
| WorkPackage.where_display_id_in(identifiers).find_each do |wp| | ||
| Wikis::ReverseInlinePageLink.create!(linkable: wp, provider:, identifier: wiki_page.id) | ||
| end | ||
| end | ||
|
|
@@ -51,9 +66,7 @@ def update_reverse_inline_wiki_page_links(wiki_page) | |
| def find_wp_links(text) | ||
| return [] if text.blank? | ||
|
|
||
| # extracted prefix from lib/open_project/text_formatting/matchers/resource_links_matcher.rb | ||
| # adding # as additional prefix | ||
| text.scan(/(?:[[:space:],~>#\(\[\-]|^)#([0-9]+)/) # rubocop:disable Style/RedundantRegexpEscape | ||
| text.scan(WP_REF_RE).map { |numeric, semantic| numeric || semantic } | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lack of boundary for numeric IDs is interesting and worth a separate non-blocking discussion. Do we actually want to retain that behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether we should retain it, but I'm hesitant to disrupt it in this swing. This test shows how it can be used in classic mode i.e.
"Trailing: #1234abc"