checkoutConfigFromMap converts a raw map to a CheckoutConfig.
(m map[string]any)
| 78 | |
| 79 | // checkoutConfigFromMap converts a raw map to a CheckoutConfig. |
| 80 | func checkoutConfigFromMap(m map[string]any) (*CheckoutConfig, error) { |
| 81 | cfg := &CheckoutConfig{} |
| 82 | |
| 83 | if v, ok := m["repository"]; ok { |
| 84 | s, ok := v.(string) |
| 85 | if !ok { |
| 86 | return nil, errors.New("checkout.repository must be a string") |
| 87 | } |
| 88 | cfg.Repository = s |
| 89 | } |
| 90 | |
| 91 | if v, ok := m["ref"]; ok { |
| 92 | s, ok := v.(string) |
| 93 | if !ok { |
| 94 | return nil, errors.New("checkout.ref must be a string") |
| 95 | } |
| 96 | cfg.Ref = s |
| 97 | } |
| 98 | |
| 99 | if v, ok := m["path"]; ok { |
| 100 | s, ok := v.(string) |
| 101 | if !ok { |
| 102 | return nil, errors.New("checkout.path must be a string") |
| 103 | } |
| 104 | cfg.PathExplicit = true |
| 105 | // Normalize "." to empty string: both mean the workspace root and |
| 106 | // are treated identically by the checkout step generator. |
| 107 | if s == "." { |
| 108 | s = "" |
| 109 | } |
| 110 | cfg.Path = s |
| 111 | } |
| 112 | |
| 113 | // Support both "github-token" (preferred) and "token" (backward compat) |
| 114 | if v, ok := m["github-token"]; ok { |
| 115 | s, ok := v.(string) |
| 116 | if !ok { |
| 117 | return nil, errors.New("checkout.github-token must be a string") |
| 118 | } |
| 119 | cfg.GitHubToken = s |
| 120 | } else if v, ok := m["token"]; ok { |
| 121 | // Backward compatibility: "token" is accepted but "github-token" is preferred |
| 122 | s, ok := v.(string) |
| 123 | if !ok { |
| 124 | return nil, errors.New("checkout.token must be a string") |
| 125 | } |
| 126 | cfg.GitHubToken = s |
| 127 | } |
| 128 | |
| 129 | // Parse app configuration for GitHub App-based authentication |
| 130 | if v, ok := m["github-app"]; ok { |
| 131 | appMap, ok := v.(map[string]any) |
| 132 | if !ok { |
| 133 | return nil, errors.New("checkout.github-app must be an object") |
| 134 | } |
| 135 | cfg.GitHubApp = parseAppConfig(appMap) |
| 136 | if cfg.GitHubApp.AppID == "" || cfg.GitHubApp.PrivateKey == "" { |
| 137 | return nil, errors.New("checkout.github-app requires both client-id (or app-id) and private-key") |
no test coverage detected