This is a follow-up from #2281551-14: Create input filter code for linking to git commits:
Furthermore, it would also be nice if we could turn the long URLs so they are displayed as the shorthand version as well (like GH does). So a comment that contains just the URL like: http://cgit.drupalcode.org/drupal/commit/?id=2da508579c6a30f8e51b1cbeaee...
Would be displayed as: drupal@2da50857
$body = preg_replace_callback( '/https?:\/\/cgit\.drupalcode\.org\/([^/]*)\/commit\/.*(?:\?|&)id=([a-z0-9]+)/g', function ($matches) { return '<a href="' . $matches[0] . '" target="_blank">' . $matches[1] . '@' . substr($matches[2], 0, 8) . '</a>'; }, $body );
This would however need to be changed to utilize the callback introduced in that issue:
/**
* Filter process callback for the Cgit absolute URL filter.
*/
function drupalorg_cgit_revision_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
$text = preg_replace_callback('/https?:\/\/cgit\.drupalcode\.org\/([^/]*)\/commit\/.*(?:\?|&)id=([a-z0-9]+)/g', 'versioncontrol_project_git_revision_process_callback', $text);
return $text;
}
Question
Would it be beneficial to add a filter for the previous gitweb URLs? I know that there are redirects already in place, however I think it would at least help to present the URLs in the shorthand version while at the same time also converting them into the proper/current URLs (if one decides to copy/paste the link).
Comment | File | Size | Author |
---|---|---|---|
#5 | drupalorg-create-input-filter-2338453-3.patch | 3.05 KB | markhalliwell |
Comments
Comment #1
markhalliwellChanging title to reflect that this issue doesn't have to be limited to the current Cgit URLs, if we indeed decide to also introduce the previous Gitweb URLs as well.
Comment #2
markhalliwellThe regex for old Gitweb URLs:
Comment #3
markhalliwellHere is the patch. It is really CNR, but I am postponing this issue until the related issue is committed, which this patch is dependent on.
Comment #4
markhalliwellComment #5
markhalliwellI forgot that preg_replace_callback could take an array. Here is an updated patch.
Comment #6
markhalliwellComment #7
drummThis looks like it would filter URLs already part of links, like
<a href="http://cgit.drupalcode.org/drupal/commit/?id=2da508579c6a30f8e51b1cbeaeea45f88cce4034">my commit</a>
. This part of the processing can likely be borrowed from core's URL filter.Comment #8
markhalliwellAh, good point. I'll update the patch when I can.
Comment #9
YesCT CreditAttribution: YesCT commented