Module:Gerrit

From Wikitech
Jump to navigation Jump to search

Usage examples

Without any parameter

Wikitext: {{Gerrit}}

Render:

example

Link to a change

Wikitext: {{Gerrit|4203}}

Render a link to change number 4203:

4203

With deploy commands

Wikitext: {{Gerrit|688200|bacc=y}}

Render:

688200 (deploy commands)

On the deployment calendar bacc is enabled by default.

Link to Gerrit change id

Wikitext: {{Gerrit|I2d7d6eeef07552b796a68963ccd4f89f4c5939d7}}

Render:

I2d7d6e

Link to Git commit hash

Wikitext: {{Git|3b85ab0624afe5a53bb60c558f0bef4d6dfb43cd}}

Render:

3b85ab0

Wikitext: {{Git|3b85ab0}}

Render:

3b85ab0

Parameters description

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
        local bacc_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 .. '/'
        	if frame.args.bacc or mw.title.equals(mw.title.getCurrentTitle(), mw.title.new('Deployments')) then
        		bacc_url = ' <small>([https://deploy-commands.toolforge.org/bacc/' .. hash .. ' deploy commands])</small>'
        	else
        		bacc_url = ''
    		end
        end
        	
        return '<span class=plainlinks style="font-family: Consolas, Liberation Mono, Courier, monospace; text-decoration: none;">[' .. url .. ' ' .. text .. ']' .. bacc_url .. '</span>'
        
    end
}
return gerrit