Module:Gerrit

local UrlEncoding = require( 'Module:UrlEncoding' )

local link_to_gerrit = function ( target, text ) if text == nil then text = target end

return  .. text ..  end

local link_to_gerrit_number = function ( number ) return link_to_gerrit( number, 'Gerrit change ' .. number ) end

local link_to_gerrit_id = function ( id ) return link_to_gerrit( '#q,' .. id .. ',n,z', 'Gerrit #' .. string.sub( id, 0, 7 ) ) end

local link_to_gerrit_search = function ( search ) return link_to_gerrit( '#q,' .. UrlEncoding._encode( search ) .. ',n,z', 'Search Gerrit for ' .. search ) end

return { _link_to_gerrit = link_to_gerrit, _link_to_gerrit_number = link_to_gerrit_number, _link_to_gerrit_search = link_to_gerrit_search,

link_automatic = function ( frame ) local suspect, changenum_match, changeid_match, retval suspect = frame.args[1] changenum_match = string.match( suspect, '%d+' ) changeid_match = string.match( suspect, 'I%x+' )

if changeid_match ~= nil then return link_to_gerrit_id( changeid_match ) elseif changenum_match ~= nil then return link_to_gerrit_number( changenum_match ) else return link_to_gerrit_search( suspect ) end end }