Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions admin/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ type DB interface {
FindDeploymentsForProject(ctx context.Context, projectID, environment, branch string) ([]*Deployment, error)
FindDeployment(ctx context.Context, id string) (*Deployment, error)
FindDeploymentByInstanceID(ctx context.Context, instanceID string) (*Deployment, error)
// HasActiveOrPendingDeploymentForProjects returns true if any of the given projects has an active or pending deployment
HasActiveOrPendingDeploymentForProjects(ctx context.Context, projectIDs []string) (bool, error)
InsertDeployment(ctx context.Context, opts *InsertDeploymentOptions) (*Deployment, error)
DeleteDeployment(ctx context.Context, id string) error
UpdateDeploymentStatus(ctx context.Context, id string, status DeploymentStatus, msg string) (*Deployment, error)
Expand Down
10 changes: 10 additions & 0 deletions admin/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,16 @@ func (c *connection) FindDeploymentByInstanceID(ctx context.Context, instanceID
return res, nil
}

func (c *connection) HasActiveOrPendingDeploymentForProjects(ctx context.Context, projectIDs []string) (bool, error) {
var exists bool
query := "SELECT EXISTS (SELECT 1 FROM deployments WHERE project_id = ANY($1) AND status IN ($2, $3, $4))"
err := c.getDB(ctx).QueryRowxContext(ctx, query, projectIDs, database.DeploymentStatusRunning, database.DeploymentStatusUpdating, database.DeploymentStatusPending).Scan(&exists)
if err != nil {
return false, parseErr("deployments", err)
}
return exists, nil
}

func (c *connection) InsertDeployment(ctx context.Context, opts *database.InsertDeploymentOptions) (*database.Deployment, error) {
if err := database.Validate(opts); err != nil {
return nil, err
Expand Down
18 changes: 16 additions & 2 deletions admin/server/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ func (s *Server) ListProjectsForOrganization(ctx context.Context, req *adminv1.L
return nil, status.Error(codes.PermissionDenied, "does not have permission to read projects")
}

// Check if any of the projects has an active or pending deployment
var hasActiveOrPendingDeployment bool
if len(projs) > 0 {
ids := make([]string, len(projs))
for i, p := range projs {
ids[i] = p.ID
}
hasActiveOrPendingDeployment, err = s.admin.DB.HasActiveOrPendingDeploymentForProjects(ctx, ids)
if err != nil {
return nil, err
}
}

nextToken := ""
if len(projs) >= pageSize {
nextToken = marshalPageToken(projs[len(projs)-1].Name)
Expand All @@ -87,8 +100,9 @@ func (s *Server) ListProjectsForOrganization(ctx context.Context, req *adminv1.L
}

return &adminv1.ListProjectsForOrganizationResponse{
Projects: dtos,
NextPageToken: nextToken,
Projects: dtos,
NextPageToken: nextToken,
PageHasActiveOrPendingDeployment: hasActiveOrPendingDeployment,
}, nil
}

Expand Down
5 changes: 5 additions & 0 deletions proto/gen/rill/admin/v1/admin.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5592,6 +5592,11 @@ definitions:
$ref: '#/definitions/v1Project'
nextPageToken:
type: string
pageHasActiveOrPendingDeployment:
type: boolean
title: |-
Indicates whether any of the projects in the returned list has an active or pending deployment across any environment
Note: this is for the returned list of projects, not the entire organization
v1ListProjectsForUserByNameResponse:
type: object
properties:
Expand Down
9,497 changes: 4,756 additions & 4,741 deletions proto/gen/rill/admin/v1/api.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions proto/gen/rill/admin/v1/api.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions proto/gen/rill/admin/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,11 @@ components:
properties:
nextPageToken:
type: string
pageHasActiveOrPendingDeployment:
title: |-
Indicates whether any of the projects in the returned list has an active or pending deployment across any environment
Note: this is for the returned list of projects, not the entire organization
type: boolean
projects:
items:
$ref: '#/components/schemas/v1Project'
Expand Down
5 changes: 5 additions & 0 deletions proto/gen/rill/admin/v1/public.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,11 @@ components:
properties:
nextPageToken:
type: string
pageHasActiveOrPendingDeployment:
title: |-
Indicates whether any of the projects in the returned list has an active or pending deployment across any environment
Note: this is for the returned list of projects, not the entire organization
type: boolean
projects:
items:
$ref: '#/components/schemas/v1Project'
Expand Down
3 changes: 3 additions & 0 deletions proto/rill/admin/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,9 @@ message DeleteDeploymentResponse {
message ListProjectsForOrganizationResponse {
repeated Project projects = 1;
string next_page_token = 2;
// Indicates whether any of the projects in the returned list has an active or pending deployment across any environment
// Note: this is for the returned list of projects, not the entire organization
bool page_has_active_or_pending_deployment = 3;
}

message ListProjectsForOrganizationAndUserRequest {
Expand Down
1 change: 1 addition & 0 deletions web-admin/src/client/gen/index.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ export interface V1ListProjectsForOrganizationAndUserResponse {
export interface V1ListProjectsForOrganizationResponse {
projects?: V1Project[];
nextPageToken?: string;
pageHasActiveOrPendingDeployment?: boolean;
}

export interface V1ListProjectsForUserByNameResponse {
Expand Down
9 changes: 9 additions & 0 deletions web-common/src/proto/gen/rill/admin/v1/api_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,14 @@ export class ListProjectsForOrganizationResponse extends Message<ListProjectsFor
*/
nextPageToken = "";

/**
* Indicates whether any of the projects in the returned list has an active or pending deployment across any environment
* Note: this is for the returned list of projects, not the entire organization
*
* @generated from field: bool page_has_active_or_pending_deployment = 3;
*/
pageHasActiveOrPendingDeployment = false;

constructor(data?: PartialMessage<ListProjectsForOrganizationResponse>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -1481,6 +1489,7 @@ export class ListProjectsForOrganizationResponse extends Message<ListProjectsFor
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "projects", kind: "message", T: Project, repeated: true },
{ no: 2, name: "next_page_token", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "page_has_active_or_pending_deployment", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ListProjectsForOrganizationResponse {
Expand Down
Loading