Module:Code review entry

From MediaWiki.org
Jump to navigation Jump to search
Module documentation
local Gerrit = require( 'Module:Gerrit' )

local description = function ( desc, done )
	local isdone = ( done == 'done' )
	local entry = ''

	if isdone then
		entry = entry .. '<s>'
	end

	entry = entry .. desc

	if isdone then
		entry = entry .. '</s>'
	end

	return entry
end

local linkhead = function ( link, done )
	local isdone = ( done == 'done' )
	local entry = ''

	if isdone then
		entry = entry .. '<s>'
	end

	entry = entry .. link

	if isdone then
		entry = entry .. '</s>'
	end

	return entry
end

local dl = function ( link, desc, done )
	local entry = '; '

	origurl = link
	matches = string.match( origurl, 'https?%:%/%/gerrit%.wikimedia%.org%/r%/(%d+)' )
	constraintmatches = string.match( origurl, 'https?%:%/%/gerrit%.wikimedia%.org%/r%/%#%/q%/(.*),n,z' )

	if matches ~= nil then
		link = Gerrit._link_to_gerrit_number( matches )
	elseif constraintmatches ~= nil then
		local ownermatch = string.match( constraintmatches, 'owner%:([^%+ ]*)' )
		local projectmatch = string.match( constraintmatches, 'project%:([^%+ ]*)' )
		local statusmatch = string.match( constraintmatches, 'status%:([^%+ ]*)' )
		local constraints = {}

		if ownermatch ~= nil then
			constraints.owner = ownermatch
		end

		if projectmatch ~= nil then
			constraints.project = projectmatch
		end

		if statusmatch ~= nil then
			constraints.status = statusmatch
		end

		link = Gerrit._link_to_gerrit_constraints( constraints )
	end

	return '; ' .. linkhead( link, done ) .. ' : ' .. description( desc, done )
end

return {
	_dl = dl,

	dl = function ( d )
		link = d.args[1]
		desc = d.args[2]
		done = d.args[3]

		return dl( d.args[1], d.args[2], d.args[3] )
	end
}