Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use :version field from Livebook Teams event #2633

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 3 additions & 7 deletions lib/livebook/hubs/team.ex
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,11 @@ defimpl Livebook.Hubs.Provider, for: Livebook.Hubs.Team do
def deployment_groups(team), do: TeamClient.get_deployment_groups(team.id)

def get_app_specs(team) do
app_deployments = TeamClient.get_agent_app_deployments(team.id)

for app_deployment <- app_deployments do
{seconds, _} = NaiveDateTime.to_gregorian_seconds(app_deployment.deployed_at)

for app_deployment <- TeamClient.get_agent_app_deployments(team.id) do
%Livebook.Apps.TeamsAppSpec{
slug: app_deployment.slug,
version: "#{app_deployment.id}-#{seconds}-#{app_deployment.sha}",
hub_id: team.id,
version: app_deployment.version,
hub_id: app_deployment.hub_id,
app_deployment_id: app_deployment.id
}
end
Expand Down
1 change: 1 addition & 0 deletions lib/livebook/hubs/team_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ defmodule Livebook.Hubs.TeamClient do
%Teams.AppDeployment{
id: app_deployment.id,
slug: app_deployment.slug,
version: app_deployment.version,
sha: app_deployment.sha,
title: app_deployment.title,
multi_session: app_deployment.multi_session,
Expand Down
2 changes: 2 additions & 0 deletions lib/livebook/teams/app_deployment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Livebook.Teams.AppDeployment do
@type t :: %__MODULE__{
id: String.t() | nil,
slug: String.t() | nil,
version: String.t() | nil,
sha: String.t() | nil,
title: String.t() | nil,
multi_session: boolean(),
Expand All @@ -23,6 +24,7 @@ defmodule Livebook.Teams.AppDeployment do
@primary_key {:id, :string, autogenerate: false}
embedded_schema do
field :slug, :string
field :version, :string
field :sha, :string
field :title, :string
field :multi_session, :boolean
Expand Down
6 changes: 6 additions & 0 deletions test/livebook_teams/hubs/team_client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ defmodule Livebook.Hubs.TeamClientTest do
%LivebookProto.AppDeployment{
id: app_deployment.id,
title: app_deployment.title,
version: app_deployment.version,
slug: app_deployment.slug,
sha: app_deployment.sha,
deployed_by: app_deployment.deployed_by,
Expand Down Expand Up @@ -656,9 +657,13 @@ defmodule Livebook.Hubs.TeamClientTest do
# Since the app deployment struct generation is from Livebook side,
# we don't have yet the information about who deployed the app,
# so we need to add it ourselves.
{seconds, 0} = NaiveDateTime.to_gregorian_seconds(teams_app_deployment.updated_at)

app_deployment = %{
app_deployment
| id: to_string(teams_app_deployment.id),
version:
"#{teams_app_deployment.id}-#{teams_app_deployment.app_revision.sha}-#{seconds}",
aleDsz marked this conversation as resolved.
Show resolved Hide resolved
file: nil,
deployed_by: teams_app_deployment.app_revision.created_by.name,
deployed_at: teams_app_deployment.updated_at
Expand All @@ -670,6 +675,7 @@ defmodule Livebook.Hubs.TeamClientTest do
%LivebookProto.AppDeployment{
id: app_deployment.id,
title: app_deployment.title,
version: app_deployment.version,
slug: app_deployment.slug,
sha: app_deployment.sha,
deployed_by: app_deployment.deployed_by,
Expand Down
10 changes: 8 additions & 2 deletions test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,26 @@ defmodule Livebook.Factory do
content = :crypto.strong_rand_bytes(1024 * 1024)
md5_hash = :crypto.hash(:md5, content)
shasum = Base.encode16(md5_hash, case: :lower)
deployed_at = NaiveDateTime.utc_now()

deployed_at =
NaiveDateTime.utc_now()
|> NaiveDateTime.truncate(:second)

{seconds, 0} = NaiveDateTime.to_gregorian_seconds(deployed_at)

%Livebook.Teams.AppDeployment{
id: "1",
title: unique_value("MyNotebook-"),
sha: shasum,
version: "1-#{shasum}-#{seconds}",
slug: slug,
file: content,
multi_session: false,
access_type: :protected,
hub_id: Livebook.Hubs.Personal.id(),
deployment_group_id: "1",
deployed_by: "Ada Lovelace",
deployed_at: NaiveDateTime.truncate(deployed_at, :second)
deployed_at: deployed_at
}
end

Expand Down
Loading