DeployProject implements localv1connect.LocalServiceHandler.
(ctx context.Context, r *connect.Request[localv1.DeployProjectRequest])
| 278 | |
| 279 | // DeployProject implements localv1connect.LocalServiceHandler. |
| 280 | func (s *Server) DeployProject(ctx context.Context, r *connect.Request[localv1.DeployProjectRequest]) (*connect.Response[localv1.DeployProjectResponse], error) { |
| 281 | // Get authenticated admin client |
| 282 | if !s.app.ch.IsAuthenticated() { |
| 283 | return nil, errors.New("must authenticate before performing this action") |
| 284 | } |
| 285 | c, err := s.app.ch.Client() |
| 286 | if err != nil { |
| 287 | return nil, err |
| 288 | } |
| 289 | |
| 290 | // check if rill org exists |
| 291 | _, err = c.GetOrganization(ctx, &adminv1.GetOrganizationRequest{ |
| 292 | Org: r.Msg.Org, |
| 293 | }) |
| 294 | if err != nil { |
| 295 | st, ok := status.FromError(err) |
| 296 | if ok && st.Code() == codes.NotFound { |
| 297 | // create org if not exists |
| 298 | _, err = c.CreateOrganization(ctx, &adminv1.CreateOrganizationRequest{ |
| 299 | Name: r.Msg.Org, |
| 300 | DisplayName: r.Msg.NewOrgDisplayName, |
| 301 | Description: "Auto created by Rill", |
| 302 | }) |
| 303 | if err != nil { |
| 304 | return nil, err |
| 305 | } |
| 306 | } else { |
| 307 | return nil, err |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | if s.app.ch.Org != r.Msg.Org { |
| 312 | // Switching to passed org |
| 313 | err = s.app.ch.SetOrg(r.Msg.Org) |
| 314 | if err != nil { |
| 315 | return nil, err |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | repo, release, err := s.app.Runtime.Repo(ctx, s.app.Instance.ID) |
| 320 | if err != nil { |
| 321 | return nil, err |
| 322 | } |
| 323 | defer release() |
| 324 | |
| 325 | // Ensure .gitignore exists and contains necessary entries |
| 326 | err = cmdutil.SetupGitIgnore(ctx, repo) |
| 327 | if err != nil { |
| 328 | return nil, fmt.Errorf("failed to set up .gitignore: %w", err) |
| 329 | } |
| 330 | |
| 331 | // Get the project's directory name |
| 332 | directoryName := "" |
| 333 | if s.app.ProjectPath != "" { |
| 334 | directoryName = filepath.Base(s.app.ProjectPath) |
| 335 | } |
| 336 | |
| 337 | var projRequest *adminv1.CreateProjectRequest |
nothing calls this directly
no test coverage detected