(org Organization, detailed bool)
| 140 | } |
| 141 | |
| 142 | func (s *sqlDatabase) sqlToCommonOrganization(org Organization, detailed bool) (params.Organization, error) { |
| 143 | if len(org.WebhookSecret) == 0 { |
| 144 | return params.Organization{}, errors.New("missing secret") |
| 145 | } |
| 146 | secret, err := util.Unseal(org.WebhookSecret, []byte(s.cfg.Passphrase)) |
| 147 | if err != nil { |
| 148 | return params.Organization{}, fmt.Errorf("error decrypting secret: %w", err) |
| 149 | } |
| 150 | |
| 151 | endpoint, err := s.sqlToCommonGithubEndpoint(org.Endpoint) |
| 152 | if err != nil { |
| 153 | return params.Organization{}, fmt.Errorf("error converting endpoint: %w", err) |
| 154 | } |
| 155 | |
| 156 | // Determine credentials name based on which credentials are set |
| 157 | var credsName string |
| 158 | if org.CredentialsID != nil { |
| 159 | credsName = org.Credentials.Name |
| 160 | } else if org.GiteaCredentialsID != nil { |
| 161 | credsName = org.GiteaCredentials.Name |
| 162 | } |
| 163 | |
| 164 | ret := params.Organization{ |
| 165 | ID: org.ID.String(), |
| 166 | Name: org.Name, |
| 167 | CredentialsName: credsName, |
| 168 | Pools: make([]params.Pool, len(org.Pools)), |
| 169 | WebhookSecret: string(secret), |
| 170 | PoolBalancerType: org.PoolBalancerType, |
| 171 | Endpoint: endpoint, |
| 172 | CreatedAt: org.CreatedAt, |
| 173 | UpdatedAt: org.UpdatedAt, |
| 174 | AgentMode: org.AgentMode, |
| 175 | PoolManagerStatus: params.PoolManagerStatus{ |
| 176 | IsRunning: org.PoolManagerRunning, |
| 177 | FailureReason: org.PoolManagerFailureReason, |
| 178 | }, |
| 179 | } |
| 180 | |
| 181 | var forgeCreds params.ForgeCredentials |
| 182 | if org.CredentialsID != nil { |
| 183 | ret.CredentialsID = *org.CredentialsID |
| 184 | forgeCreds, err = s.sqlToCommonForgeCredentials(org.Credentials) |
| 185 | } |
| 186 | |
| 187 | if org.GiteaCredentialsID != nil { |
| 188 | ret.CredentialsID = *org.GiteaCredentialsID |
| 189 | forgeCreds, err = s.sqlGiteaToCommonForgeCredentials(org.GiteaCredentials) |
| 190 | } |
| 191 | |
| 192 | if err != nil { |
| 193 | return params.Organization{}, fmt.Errorf("error converting credentials: %w", err) |
| 194 | } |
| 195 | |
| 196 | if len(org.Events) > 0 { |
| 197 | ret.Events = make([]params.EntityEvent, len(org.Events)) |
| 198 | for idx, event := range org.Events { |
| 199 | ret.Events[idx] = params.EntityEvent{ |
no test coverage detected