Module:Gerrit

From Wikitech
Jump to navigation Jump to search

Examples

Testing main template

{{Gerrit}}

example

Testing Gerrit change number

{{Gerrit|4203}}

4203

Testing Gerrit change id

{{Gerrit|I2d7d6eeef07552b796a68963ccd4f89f4c5939d7}}

I2d7d6e

Testing Git commit hash

{{Git|3b85ab0624afe5a53bb60c558f0bef4d6dfb43cd}}

3b85ab0

{{Git|3b85ab0}}

3b85ab0

Usage

No description.

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Identifier1

The git commit hash, gerrit change number, or gerrit Change-Id

Stringrequired

local gerrit = {
    link = function (frame)
        local hash = frame.args[1]
        local length = string.len(hash)
        
        if not string.match(hash, '^I?%x+$' ) then
            return hash
        end
        
        local text
        if length > 14 then
            text = string.format("%.7s", hash)
        else
            text = hash
        end
        
        local url
        if length > 6 then
        	-- query
        	url = 'https://gerrit.wikimedia.org/r/q/' .. mw.uri.encode(hash)
        else
        	-- probably a change
        	url = 'https://gerrit.wikimedia.org/r/c/' .. hash .. '/'
        end
        	
        return '<span class=plainlinks style="font-family: Consolas, Liberation Mono, Courier, monospace; text-decoration: none;">[' .. url .. ' ' .. text .. ']</span>'
        
    end
}
return gerrit