Initial commit: Gitea MCP Server
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/gitea"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/log"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/to"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/tool"
|
||||
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
)
|
||||
|
||||
var Tool = tool.New()
|
||||
|
||||
const (
|
||||
GetGiteaMCPServerVersion = "get_gitea_mcp_server_version"
|
||||
CheckGiteaVersion = "check_gitea_version"
|
||||
)
|
||||
|
||||
var GetGiteaMCPServerVersionTool = mcp.NewTool(
|
||||
GetGiteaMCPServerVersion,
|
||||
mcp.WithDescription("Get Gitea MCP Server Version"),
|
||||
)
|
||||
|
||||
var CheckGiteaVersionTool = mcp.NewTool(
|
||||
CheckGiteaVersion,
|
||||
mcp.WithDescription("Check the Gitea server version and API capabilities. Returns version string, parsed components, and capability matrix indicating which APIs are available based on the detected version."),
|
||||
)
|
||||
|
||||
// VersionResponse represents the Gitea version API response
|
||||
type VersionResponse struct {
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
// VersionInfo represents the complete version information with capabilities
|
||||
type VersionInfo struct {
|
||||
Version string `json:"version"`
|
||||
Major int `json:"major"`
|
||||
Minor int `json:"minor"`
|
||||
Patch int `json:"patch"`
|
||||
Capabilities CapabilityMatrix `json:"capabilities"`
|
||||
}
|
||||
|
||||
// CapabilityMatrix indicates which APIs are available
|
||||
type CapabilityMatrix struct {
|
||||
ActionsAPI bool `json:"actions_api"`
|
||||
SecretsAPI bool `json:"secrets_api"`
|
||||
VariablesAPI bool `json:"variables_api"`
|
||||
RunnersAPI bool `json:"runners_api"`
|
||||
ArtifactsAPI bool `json:"artifacts_api"`
|
||||
CommitStatusAPI bool `json:"commit_status_api"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
Tool.RegisterRead(server.ServerTool{
|
||||
Tool: GetGiteaMCPServerVersionTool,
|
||||
Handler: GetGiteaMCPServerVersionFn,
|
||||
})
|
||||
Tool.RegisterRead(server.ServerTool{
|
||||
Tool: CheckGiteaVersionTool,
|
||||
Handler: CheckGiteaVersionFn,
|
||||
})
|
||||
}
|
||||
|
||||
func GetGiteaMCPServerVersionFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called GetGiteaMCPServerVersionFn")
|
||||
version := flag.Version
|
||||
if version == "" {
|
||||
version = "dev"
|
||||
}
|
||||
return to.TextResult(fmt.Sprintf("Gitea MCP Server version: %v", version))
|
||||
}
|
||||
|
||||
// CheckGiteaVersionFn retrieves Gitea server version and determines capabilities
|
||||
func CheckGiteaVersionFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called CheckGiteaVersionFn")
|
||||
|
||||
var versionResp VersionResponse
|
||||
status, err := gitea.DoJSON(ctx, "GET", "version", nil, nil, &versionResp)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get Gitea version: status=%d, err=%v", status, err)
|
||||
return to.TextResult(fmt.Sprintf("Error: Failed to get Gitea version (status %d): %v", status, err))
|
||||
}
|
||||
|
||||
major, minor, patch, err := parseVersion(versionResp.Version)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to parse version string '%s': %v", versionResp.Version, err)
|
||||
return to.TextResult(fmt.Sprintf("Error: Failed to parse version '%s': %v", versionResp.Version, err))
|
||||
}
|
||||
|
||||
capabilities := determineCapabilities(major, minor, patch)
|
||||
|
||||
info := VersionInfo{
|
||||
Version: versionResp.Version,
|
||||
Major: major,
|
||||
Minor: minor,
|
||||
Patch: patch,
|
||||
Capabilities: capabilities,
|
||||
}
|
||||
|
||||
jsonBytes, err := json.MarshalIndent(info, "", " ")
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal version info: %v", err)
|
||||
return to.TextResult(fmt.Sprintf("Error: Failed to format response: %v", err))
|
||||
}
|
||||
|
||||
return to.TextResult(string(jsonBytes))
|
||||
}
|
||||
|
||||
// parseVersion parses a version string like "1.22.5" into major, minor, patch
|
||||
func parseVersion(version string) (int, int, int, error) {
|
||||
version = strings.TrimPrefix(version, "v")
|
||||
version = strings.TrimPrefix(version, "V")
|
||||
|
||||
parts := strings.Split(version, ".")
|
||||
if len(parts) < 2 {
|
||||
return 0, 0, 0, fmt.Errorf("invalid version format: %s (expected major.minor.patch)", version)
|
||||
}
|
||||
|
||||
major, err := strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return 0, 0, 0, fmt.Errorf("invalid major version: %s", parts[0])
|
||||
}
|
||||
|
||||
minor, err := strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
return 0, 0, 0, fmt.Errorf("invalid minor version: %s", parts[1])
|
||||
}
|
||||
|
||||
patch := 0
|
||||
if len(parts) >= 3 {
|
||||
patch, err = strconv.Atoi(parts[2])
|
||||
if err != nil {
|
||||
return 0, 0, 0, fmt.Errorf("invalid patch version: %s", parts[2])
|
||||
}
|
||||
}
|
||||
|
||||
return major, minor, patch, nil
|
||||
}
|
||||
|
||||
// determineCapabilities determines which APIs are available based on version
|
||||
func determineCapabilities(major, minor, patch int) CapabilityMatrix {
|
||||
cm := CapabilityMatrix{}
|
||||
|
||||
// Commit Status API: Available in 1.12+
|
||||
if major > 1 || (major == 1 && minor >= 12) {
|
||||
cm.CommitStatusAPI = true
|
||||
}
|
||||
|
||||
// Secrets API: Available in 1.22.0+
|
||||
if major > 1 || (major == 1 && minor >= 22) {
|
||||
cm.SecretsAPI = true
|
||||
}
|
||||
|
||||
// Variables API: Available in 1.22.0+ (same as secrets)
|
||||
if major > 1 || (major == 1 && minor >= 22) {
|
||||
cm.VariablesAPI = true
|
||||
}
|
||||
|
||||
// Runners API: Available in 1.22.0+ with improvements in 1.23+
|
||||
if major > 1 || (major == 1 && minor >= 22) {
|
||||
cm.RunnersAPI = true
|
||||
}
|
||||
|
||||
// Actions API: Full support in 1.23+, limited in 1.22
|
||||
// Artifacts API: Full support in 1.23+
|
||||
if major > 1 || (major == 1 && minor >= 23) {
|
||||
cm.ActionsAPI = true
|
||||
cm.ArtifactsAPI = true
|
||||
// Runners API is more complete in 1.23+
|
||||
cm.RunnersAPI = true
|
||||
}
|
||||
|
||||
return cm
|
||||
}
|
||||
@@ -0,0 +1,488 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
)
|
||||
|
||||
func Test_checkGiteaVersionFn_success(t *testing.T) {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/version" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"version":"1.22.5"}`))
|
||||
})
|
||||
|
||||
server := httptest.NewServer(handler)
|
||||
defer server.Close()
|
||||
|
||||
origHost := flag.Host
|
||||
origToken := flag.Token
|
||||
origVersion := flag.Version
|
||||
flag.Host = server.URL
|
||||
flag.Token = ""
|
||||
flag.Version = "test"
|
||||
defer func() {
|
||||
flag.Host = origHost
|
||||
flag.Token = origToken
|
||||
flag.Version = origVersion
|
||||
}()
|
||||
|
||||
req := mcp.CallToolRequest{
|
||||
Params: mcp.CallToolParams{
|
||||
Arguments: map[string]any{},
|
||||
},
|
||||
}
|
||||
|
||||
result, err := CheckGiteaVersionFn(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatalf("CheckGiteaVersionFn() error = %v", err)
|
||||
}
|
||||
|
||||
if len(result.Content) == 0 {
|
||||
t.Fatalf("expected content in result")
|
||||
}
|
||||
|
||||
textContent, ok := mcp.AsTextContent(result.Content[0])
|
||||
if !ok {
|
||||
t.Fatalf("expected text content, got %T", result.Content[0])
|
||||
}
|
||||
|
||||
var parsed VersionInfo
|
||||
if err := json.Unmarshal([]byte(textContent.Text), &parsed); err != nil {
|
||||
t.Fatalf("unmarshal result: %v", err)
|
||||
}
|
||||
|
||||
if parsed.Version != "1.22.5" {
|
||||
t.Errorf("version = %q, want %q", parsed.Version, "1.22.5")
|
||||
}
|
||||
if parsed.Major != 1 {
|
||||
t.Errorf("major = %d, want 1", parsed.Major)
|
||||
}
|
||||
if parsed.Minor != 22 {
|
||||
t.Errorf("minor = %d, want 22", parsed.Minor)
|
||||
}
|
||||
if parsed.Patch != 5 {
|
||||
t.Errorf("patch = %d, want 5", parsed.Patch)
|
||||
}
|
||||
|
||||
// 1.22.5 should have secrets, variables, runners, commit_status but not actions/artifacts
|
||||
if !parsed.Capabilities.SecretsAPI {
|
||||
t.Error("expected secrets_api=true for 1.22.5")
|
||||
}
|
||||
if !parsed.Capabilities.VariablesAPI {
|
||||
t.Error("expected variables_api=true for 1.22.5")
|
||||
}
|
||||
if !parsed.Capabilities.RunnersAPI {
|
||||
t.Error("expected runners_api=true for 1.22.5")
|
||||
}
|
||||
if !parsed.Capabilities.CommitStatusAPI {
|
||||
t.Error("expected commit_status_api=true for 1.22.5")
|
||||
}
|
||||
if parsed.Capabilities.ActionsAPI {
|
||||
t.Error("expected actions_api=false for 1.22.5")
|
||||
}
|
||||
if parsed.Capabilities.ArtifactsAPI {
|
||||
t.Error("expected artifacts_api=false for 1.22.5")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_checkGiteaVersionFn_version123(t *testing.T) {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/version" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"version":"1.23.0"}`))
|
||||
})
|
||||
|
||||
server := httptest.NewServer(handler)
|
||||
defer server.Close()
|
||||
|
||||
origHost := flag.Host
|
||||
origToken := flag.Token
|
||||
origVersion := flag.Version
|
||||
flag.Host = server.URL
|
||||
flag.Token = ""
|
||||
flag.Version = "test"
|
||||
defer func() {
|
||||
flag.Host = origHost
|
||||
flag.Token = origToken
|
||||
flag.Version = origVersion
|
||||
}()
|
||||
|
||||
req := mcp.CallToolRequest{
|
||||
Params: mcp.CallToolParams{
|
||||
Arguments: map[string]any{},
|
||||
},
|
||||
}
|
||||
|
||||
result, err := CheckGiteaVersionFn(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatalf("CheckGiteaVersionFn() error = %v", err)
|
||||
}
|
||||
|
||||
textContent, ok := mcp.AsTextContent(result.Content[0])
|
||||
if !ok {
|
||||
t.Fatalf("expected text content, got %T", result.Content[0])
|
||||
}
|
||||
|
||||
var parsed VersionInfo
|
||||
if err := json.Unmarshal([]byte(textContent.Text), &parsed); err != nil {
|
||||
t.Fatalf("unmarshal result: %v", err)
|
||||
}
|
||||
|
||||
if parsed.Version != "1.23.0" {
|
||||
t.Errorf("version = %q, want %q", parsed.Version, "1.23.0")
|
||||
}
|
||||
|
||||
// 1.23.0 should have all capabilities
|
||||
if !parsed.Capabilities.ActionsAPI {
|
||||
t.Error("expected actions_api=true for 1.23.0")
|
||||
}
|
||||
if !parsed.Capabilities.ArtifactsAPI {
|
||||
t.Error("expected artifacts_api=true for 1.23.0")
|
||||
}
|
||||
if !parsed.Capabilities.SecretsAPI {
|
||||
t.Error("expected secrets_api=true for 1.23.0")
|
||||
}
|
||||
if !parsed.Capabilities.VariablesAPI {
|
||||
t.Error("expected variables_api=true for 1.23.0")
|
||||
}
|
||||
if !parsed.Capabilities.RunnersAPI {
|
||||
t.Error("expected runners_api=true for 1.23.0")
|
||||
}
|
||||
if !parsed.Capabilities.CommitStatusAPI {
|
||||
t.Error("expected commit_status_api=true for 1.23.0")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_checkGiteaVersionFn_version111(t *testing.T) {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/version" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"version":"1.11.0"}`))
|
||||
})
|
||||
|
||||
server := httptest.NewServer(handler)
|
||||
defer server.Close()
|
||||
|
||||
origHost := flag.Host
|
||||
origToken := flag.Token
|
||||
origVersion := flag.Version
|
||||
flag.Host = server.URL
|
||||
flag.Token = ""
|
||||
flag.Version = "test"
|
||||
defer func() {
|
||||
flag.Host = origHost
|
||||
flag.Token = origToken
|
||||
flag.Version = origVersion
|
||||
}()
|
||||
|
||||
req := mcp.CallToolRequest{
|
||||
Params: mcp.CallToolParams{
|
||||
Arguments: map[string]any{},
|
||||
},
|
||||
}
|
||||
|
||||
result, err := CheckGiteaVersionFn(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatalf("CheckGiteaVersionFn() error = %v", err)
|
||||
}
|
||||
|
||||
textContent, ok := mcp.AsTextContent(result.Content[0])
|
||||
if !ok {
|
||||
t.Fatalf("expected text content, got %T", result.Content[0])
|
||||
}
|
||||
|
||||
var parsed VersionInfo
|
||||
if err := json.Unmarshal([]byte(textContent.Text), &parsed); err != nil {
|
||||
t.Fatalf("unmarshal result: %v", err)
|
||||
}
|
||||
|
||||
// 1.11.0 should only have commit_status
|
||||
if !parsed.Capabilities.CommitStatusAPI {
|
||||
t.Error("expected commit_status_api=true for 1.11.0")
|
||||
}
|
||||
if parsed.Capabilities.SecretsAPI {
|
||||
t.Error("expected secrets_api=false for 1.11.0")
|
||||
}
|
||||
if parsed.Capabilities.VariablesAPI {
|
||||
t.Error("expected variables_api=false for 1.11.0")
|
||||
}
|
||||
if parsed.Capabilities.RunnersAPI {
|
||||
t.Error("expected runners_api=false for 1.11.0")
|
||||
}
|
||||
if parsed.Capabilities.ActionsAPI {
|
||||
t.Error("expected actions_api=false for 1.11.0")
|
||||
}
|
||||
if parsed.Capabilities.ArtifactsAPI {
|
||||
t.Error("expected artifacts_api=false for 1.11.0")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_checkGiteaVersionFn_withVPrefix(t *testing.T) {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/version" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"version":"v1.24.0"}`))
|
||||
})
|
||||
|
||||
server := httptest.NewServer(handler)
|
||||
defer server.Close()
|
||||
|
||||
origHost := flag.Host
|
||||
origToken := flag.Token
|
||||
origVersion := flag.Version
|
||||
flag.Host = server.URL
|
||||
flag.Token = ""
|
||||
flag.Version = "test"
|
||||
defer func() {
|
||||
flag.Host = origHost
|
||||
flag.Token = origToken
|
||||
flag.Version = origVersion
|
||||
}()
|
||||
|
||||
req := mcp.CallToolRequest{
|
||||
Params: mcp.CallToolParams{
|
||||
Arguments: map[string]any{},
|
||||
},
|
||||
}
|
||||
|
||||
result, err := CheckGiteaVersionFn(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatalf("CheckGiteaVersionFn() error = %v", err)
|
||||
}
|
||||
|
||||
textContent, ok := mcp.AsTextContent(result.Content[0])
|
||||
if !ok {
|
||||
t.Fatalf("expected text content, got %T", result.Content[0])
|
||||
}
|
||||
|
||||
var parsed VersionInfo
|
||||
if err := json.Unmarshal([]byte(textContent.Text), &parsed); err != nil {
|
||||
t.Fatalf("unmarshal result: %v", err)
|
||||
}
|
||||
|
||||
if parsed.Version != "v1.24.0" {
|
||||
t.Errorf("version = %q, want %q", parsed.Version, "v1.24.0")
|
||||
}
|
||||
if parsed.Major != 1 {
|
||||
t.Errorf("major = %d, want 1", parsed.Major)
|
||||
}
|
||||
if parsed.Minor != 24 {
|
||||
t.Errorf("minor = %d, want 24", parsed.Minor)
|
||||
}
|
||||
if parsed.Patch != 0 {
|
||||
t.Errorf("patch = %d, want 0", parsed.Patch)
|
||||
}
|
||||
|
||||
// 1.24 should have all capabilities
|
||||
if !parsed.Capabilities.ActionsAPI {
|
||||
t.Error("expected actions_api=true for 1.24.0")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_checkGiteaVersionFn_error(t *testing.T) {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, `{"message":"Internal Server Error"}`, http.StatusInternalServerError)
|
||||
})
|
||||
|
||||
server := httptest.NewServer(handler)
|
||||
defer server.Close()
|
||||
|
||||
origHost := flag.Host
|
||||
origToken := flag.Token
|
||||
origVersion := flag.Version
|
||||
flag.Host = server.URL
|
||||
flag.Token = ""
|
||||
flag.Version = "test"
|
||||
defer func() {
|
||||
flag.Host = origHost
|
||||
flag.Token = origToken
|
||||
flag.Version = origVersion
|
||||
}()
|
||||
|
||||
req := mcp.CallToolRequest{
|
||||
Params: mcp.CallToolParams{
|
||||
Arguments: map[string]any{},
|
||||
},
|
||||
}
|
||||
|
||||
result, err := CheckGiteaVersionFn(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatalf("CheckGiteaVersionFn() error = %v", err)
|
||||
}
|
||||
|
||||
textContent, ok := mcp.AsTextContent(result.Content[0])
|
||||
if !ok {
|
||||
t.Fatalf("expected text content, got %T", result.Content[0])
|
||||
}
|
||||
|
||||
// Should return error message in text result
|
||||
if textContent.Text == "" {
|
||||
t.Error("expected error message in result")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_parseVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
version string
|
||||
wantMajor int
|
||||
wantMinor int
|
||||
wantPatch int
|
||||
wantErr bool
|
||||
}{
|
||||
{"1.22.5", 1, 22, 5, false},
|
||||
{"1.23.0", 1, 23, 0, false},
|
||||
{"1.24.1", 1, 24, 1, false},
|
||||
{"v1.22.5", 1, 22, 5, false},
|
||||
{"V1.22.5", 1, 22, 5, false},
|
||||
{"1.22", 1, 22, 0, false},
|
||||
{"1", 0, 0, 0, true},
|
||||
{"", 0, 0, 0, true},
|
||||
{"abc", 0, 0, 0, true},
|
||||
{"1.x.5", 0, 0, 0, true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.version, func(t *testing.T) {
|
||||
major, minor, patch, err := parseVersion(tt.version)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("parseVersion(%q) error = %v, wantErr %v", tt.version, err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !tt.wantErr {
|
||||
if major != tt.wantMajor {
|
||||
t.Errorf("parseVersion(%q) major = %d, want %d", tt.version, major, tt.wantMajor)
|
||||
}
|
||||
if minor != tt.wantMinor {
|
||||
t.Errorf("parseVersion(%q) minor = %d, want %d", tt.version, minor, tt.wantMinor)
|
||||
}
|
||||
if patch != tt.wantPatch {
|
||||
t.Errorf("parseVersion(%q) patch = %d, want %d", tt.version, patch, tt.wantPatch)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_determineCapabilities(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
major int
|
||||
minor int
|
||||
patch int
|
||||
expected CapabilityMatrix
|
||||
}{
|
||||
{
|
||||
name: "1.11.0",
|
||||
major: 1, minor: 11, patch: 0,
|
||||
expected: CapabilityMatrix{
|
||||
ActionsAPI: false,
|
||||
SecretsAPI: false,
|
||||
VariablesAPI: false,
|
||||
RunnersAPI: false,
|
||||
ArtifactsAPI: false,
|
||||
CommitStatusAPI: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "1.12.0",
|
||||
major: 1, minor: 12, patch: 0,
|
||||
expected: CapabilityMatrix{
|
||||
ActionsAPI: false,
|
||||
SecretsAPI: false,
|
||||
VariablesAPI: false,
|
||||
RunnersAPI: false,
|
||||
ArtifactsAPI: false,
|
||||
CommitStatusAPI: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "1.22.0",
|
||||
major: 1, minor: 22, patch: 0,
|
||||
expected: CapabilityMatrix{
|
||||
ActionsAPI: false,
|
||||
SecretsAPI: true,
|
||||
VariablesAPI: true,
|
||||
RunnersAPI: true,
|
||||
ArtifactsAPI: false,
|
||||
CommitStatusAPI: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "1.22.5",
|
||||
major: 1, minor: 22, patch: 5,
|
||||
expected: CapabilityMatrix{
|
||||
ActionsAPI: false,
|
||||
SecretsAPI: true,
|
||||
VariablesAPI: true,
|
||||
RunnersAPI: true,
|
||||
ArtifactsAPI: false,
|
||||
CommitStatusAPI: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "1.23.0",
|
||||
major: 1, minor: 23, patch: 0,
|
||||
expected: CapabilityMatrix{
|
||||
ActionsAPI: true,
|
||||
SecretsAPI: true,
|
||||
VariablesAPI: true,
|
||||
RunnersAPI: true,
|
||||
ArtifactsAPI: true,
|
||||
CommitStatusAPI: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "1.24.0",
|
||||
major: 1, minor: 24, patch: 0,
|
||||
expected: CapabilityMatrix{
|
||||
ActionsAPI: true,
|
||||
SecretsAPI: true,
|
||||
VariablesAPI: true,
|
||||
RunnersAPI: true,
|
||||
ArtifactsAPI: true,
|
||||
CommitStatusAPI: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "2.0.0",
|
||||
major: 2, minor: 0, patch: 0,
|
||||
expected: CapabilityMatrix{
|
||||
ActionsAPI: true,
|
||||
SecretsAPI: true,
|
||||
VariablesAPI: true,
|
||||
RunnersAPI: true,
|
||||
ArtifactsAPI: true,
|
||||
CommitStatusAPI: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := determineCapabilities(tt.major, tt.minor, tt.patch)
|
||||
if got != tt.expected {
|
||||
t.Errorf("determineCapabilities(%d, %d, %d) = %+v, want %+v",
|
||||
tt.major, tt.minor, tt.patch, got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user