githubRepoIDForProject returns the github repo id for a project stored in the database. For older projects this may be nil since the github repo id was not stored. This function fetches the ID from github API and stores it in the database. It assumes that the project is connected to github and neces
(ctx context.Context, p *database.Project)
| 2249 | // This function fetches the ID from github API and stores it in the database. |
| 2250 | // It assumes that the project is connected to github and necessary checks have been done by the caller. |
| 2251 | func (s *Server) githubRepoIDForProject(ctx context.Context, p *database.Project) (int64, error) { |
| 2252 | if p.GithubRepoID != nil { |
| 2253 | return *p.GithubRepoID, nil |
| 2254 | } |
| 2255 | |
| 2256 | if p.GithubInstallationID == nil { |
| 2257 | return 0, fmt.Errorf("project %q is not connected to github", p.Name) |
| 2258 | } |
| 2259 | |
| 2260 | client := s.admin.Github.InstallationClient(*p.GithubInstallationID, nil) |
| 2261 | account, repo, ok := gitutil.SplitGithubRemote(*p.GitRemote) |
| 2262 | if !ok { |
| 2263 | return 0, status.Errorf(codes.Internal, "invalid github url %q stored for project", *p.GitRemote) |
| 2264 | } |
| 2265 | |
| 2266 | ghRepo, _, err := client.Repositories.Get(ctx, account, repo) |
| 2267 | if err != nil { |
| 2268 | return 0, fmt.Errorf("failed to get github repo: %w", err) |
| 2269 | } |
| 2270 | id := ghRepo.GetID() |
| 2271 | _, err = s.admin.DB.UpdateProject(ctx, p.ID, &database.UpdateProjectOptions{ |
| 2272 | Name: p.Name, |
| 2273 | Description: p.Description, |
| 2274 | Public: p.Public, |
| 2275 | DirectoryName: p.DirectoryName, |
| 2276 | ArchiveAssetID: p.ArchiveAssetID, |
| 2277 | GitRemote: p.GitRemote, |
| 2278 | GithubInstallationID: p.GithubInstallationID, |
| 2279 | GithubRepoID: &id, |
| 2280 | ManagedGitRepoID: p.ManagedGitRepoID, |
| 2281 | ProdVersion: p.ProdVersion, |
| 2282 | PrimaryBranch: p.PrimaryBranch, |
| 2283 | Subpath: p.Subpath, |
| 2284 | PrimaryDeploymentID: p.PrimaryDeploymentID, |
| 2285 | ProdSlots: p.ProdSlots, |
| 2286 | ProdTTLSeconds: p.ProdTTLSeconds, |
| 2287 | DevSlots: p.DevSlots, |
| 2288 | DevTTLSeconds: p.DevTTLSeconds, |
| 2289 | OverrideDiskGB: p.OverrideDiskGB, |
| 2290 | Provisioner: p.Provisioner, |
| 2291 | Annotations: p.Annotations, |
| 2292 | }) |
| 2293 | if err != nil { |
| 2294 | return 0, fmt.Errorf("failed to update project with github repo id: %w", err) |
| 2295 | } |
| 2296 | return id, nil |
| 2297 | } |
| 2298 | |
| 2299 | func deploymentToDTO(d *database.Deployment) *adminv1.Deployment { |
| 2300 | var s adminv1.DeploymentStatus |
no test coverage detected