Module:Issue council

--                             Module:Issue council                          -- --                                                                           -- -- This module produces issue council links based on issue ID alone. -- -- It implements the template. --

local libraryUtil = require('libraryUtil') local checkType = libraryUtil.checkType local mArguments -- lazily initialise Module:Arguments local mError -- lazily initialise Module:Error

local p = {}

local function getArgs(frame) -- Fetches the arguments from the parent frame. Whitespace is trimmed and -- blanks are removed. mArguments = require('Module:Arguments') return mArguments.getArgs(frame, {parentOnly = true}) end

--- Helper function to throw error -- -- @param msg string - Error message -- -- @return string - Formatted error message in wikitext local function makeWikitextError(msg) mError = require('Module:Error') return mError.error{message = 'Error: ' .. msg .. '.'	} end

--- Helper function checking if a substring is in a string -- -- @param needle string - Value to search for -- @param haystack string - String to search in -- -- @return bool - True if found local function stringContains( needle, haystack ) return string.find( mw.ustring.lower( haystack ), needle, 1, true ) end

--- Determine the issue council project -- -- @param id string - Issue Council ID -- -- @return string - project or nil if unknown local function getProject( id ) local project

if stringContains( 'starc-', id ) then project = 'STAR-CITIZEN' elseif stringContains( 'ic-', id ) then project = 'ISSUE-COUNCIL' else project = nil end

return project end

function p.main(frame) local args = getArgs(frame) local issueId = args[1] if not issueId then return makeWikitextError('no issue ID specified') end return p._main(issueId) end

function p._main(issueId) checkType('_main', 1, issueId, 'string') local project = getProject(issueId) local url if project == nil then return makeWikitextError('issue ID is invalid (no project match)') end

url = mw.ustring.format(		'https://issue-council.robertsspaceindustries.com/projects/%s/issues/%s',		project,		issueId	) return mw.ustring.format(		'[%s %s]',		url,		issueId	) end

return p