progit-plugin-sdk 0.3.0

Plugin SDK for ProGit — sandboxed LuaJIT runtime with capability-based security. LSL-1.0 (file-level copyleft, proprietary plugins allowed via the commercial bridge).
Documentation
-- SPDX-License-Identifier: Apache-2.0
-- Copyright (c) 2025 Markus Maiwald

-- Example Lua Plugin: Jira Sync
-- This plugin demonstrates syncing ProGit issues to Jira

plugin = {
    name = "jira-sync",
    version = "1.0.0",
    author = "Markus Maiwald",
    description = "Sync ProGit issues to Jira",
    hooks = {
        on_issue_created = true,
        on_issue_updated = true,
        on_sync_push = true,
    }
}

-- Configuration (loaded from context.config)
local jira_url = ""
local jira_project = ""
local jira_api_token = ""

function init()
    -- Load configuration from context
    jira_url = context.config.jira_url or os.getenv("JIRA_URL") or ""
    jira_project = context.config.jira_project or os.getenv("JIRA_PROJECT") or ""
    jira_api_token = context.config.jira_api_token or os.getenv("JIRA_API_TOKEN") or ""
    
    if jira_url == "" then
        error("Jira URL not configured. Set JIRA_URL environment variable or config.jira_url")
    end
    
    print("Jira Sync plugin initialized")
    print("  URL: " .. jira_url)
    print("  Project: " .. jira_project)
end

function on_issue_created(issue)
    print("Creating Jira issue for: " .. issue.title)
    
    -- In a real plugin, you would make an HTTP request to Jira API
    -- For this example, we just log it
    local jira_issue = {
        fields = {
            project = { key = jira_project },
            summary = issue.title,
            description = issue.description,
            issuetype = { name = "Task" },
            labels = issue.tags,
        }
    }
    
    print("  Would POST to: " .. jira_url .. "/rest/api/2/issue")
    print("  Payload: " .. json_encode(jira_issue))
    
    -- Store the Jira issue key in metadata for future updates
    return {
        success = true,
        jira_key = "PROJ-123",  -- In reality, this would come from Jira response
    }
end

function on_issue_updated(issue)
    -- Check if issue has Jira key in metadata
    local jira_key = issue.metadata.jira_key
    if not jira_key then
        print("Issue not synced to Jira, skipping update")
        return { success = false, reason = "not_synced" }
    end
    
    print("Updating Jira issue " .. jira_key .. " for: " .. issue.title)
    
    -- In a real plugin, you would make an HTTP PUT request
    local update = {
        fields = {
            summary = issue.title,
            description = issue.description,
            labels = issue.tags,
        }
    }
    
    print("  Would PUT to: " .. jira_url .. "/rest/api/2/issue/" .. jira_key)
    
    return { success = true }
end

function on_sync_push(issues)
    print("Syncing " .. #issues .. " issues to Jira")
    
    local synced = 0
    for i, issue in ipairs(issues) do
        -- Only sync issues that don't have a Jira key yet
        if not issue.metadata.jira_key then
            on_issue_created(issue)
            synced = synced + 1
        end
    end
    
    print("Synced " .. synced .. " new issues to Jira")
    return { success = true, synced = synced }
end

-- Helper function to encode JSON (in real plugin, use a proper JSON library)
function json_encode(obj)
    -- Simplified JSON encoding for demo purposes
    local result = "{"
    for k, v in pairs(obj) do
        if type(v) == "table" then
            result = result .. '"' .. k .. '":' .. json_encode(v) .. ","
        elseif type(v) == "string" then
            result = result .. '"' .. k .. '":"' .. v .. '",'
        else
            result = result .. '"' .. k .. '":' .. tostring(v) .. ","
        end
    end
    result = result:sub(1, -2) .. "}"
    return result
end