Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/hex/ex_machina-2.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rgarfield11 authored Dec 2, 2024
2 parents 82fd490 + bae16d3 commit 2727765
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ name: Test
on: push

env:
OTP_VERSION_SPEC: "24.1"
ELIXIR_VERSION_SPEC: "1.12.3"
OTP_VERSION_SPEC: "26.2.4"
ELIXIR_VERSION_SPEC: "1.16.2"
MIX_ENV: test

jobs:
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 24.1.7
elixir 1.12.3-otp-24
erlang 26.2.4
elixir 1.16.2-otp-26
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set the Docker image you want to base your image off.
FROM hexpm/elixir:1.12.3-erlang-24.1.7-debian-buster-20210902 as builder
FROM hexpm/elixir:1.16.2-erlang-26.2.4-debian-bullseye-20240423-slim as builder

# Install other stable dependencies that don't change often
RUN apt-get update && \
Expand Down Expand Up @@ -27,7 +27,7 @@ RUN mix do compile, release
# END BUILDER
#

FROM debian:buster-slim
FROM debian:bullseye-slim

RUN apt-get -qq update
RUN apt-get -qq install -y locales locales-all openssl
Expand Down
9 changes: 4 additions & 5 deletions lib/slax/github.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ defmodule Slax.Github do
@moduledoc """
Functions for working with the Github API
"""

alias Slax.Http
alias Slax.Http.Error
alias Slax.ProjectRepos
Expand Down Expand Up @@ -507,7 +506,7 @@ defmodule Slax.Github do
"""
def load_issue(repo_and_issue) do
with {org, repo, issue} <- parse_repo_org_issue(repo_and_issue),
{token, warning_message} <- retrieve_token(repo),
{token, warning_message} <- retrieve_token(repo, org),
client <- Tentacat.Client.new(%{access_token: token}),
{200, issue, _http_response} <- Issues.find(client, org, repo, issue) do
{:ok, issue, warning_message}
Expand All @@ -531,7 +530,7 @@ defmodule Slax.Github do

def load_pr(repo_and_pr) do
with {org, repo, pr} <- parse_repo_org_issue(repo_and_pr),
{token, warning_message} <- retrieve_token(repo),
{token, warning_message} <- retrieve_token(repo, org),
client <- Tentacat.Client.new(%{access_token: token}),
{200, pr, _http_response} <- Prs.find(client, org, repo, pr) do
{:ok, pr, warning_message}
Expand Down Expand Up @@ -566,8 +565,8 @@ defmodule Slax.Github do
end)
end

defp retrieve_token(repo) do
case ProjectRepos.get_by_repo(repo) do
defp retrieve_token(repo, org) do
case ProjectRepos.get_by_repo_and_org(repo, org) do
%{token: token} when not is_nil(token) ->
{token, ""}

Expand Down
2 changes: 1 addition & 1 deletion lib/slax/poker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule Slax.Poker do
{org, repo, issue} = Github.parse_repo_org_issue(round.issue)

client =
case ProjectRepos.get_by_repo(repo) do
case ProjectRepos.get_by_repo_and_org(repo, org) do
%{token: token} when not is_nil(token) ->
Tentacat.Client.new(%{access_token: token})

Expand Down
15 changes: 13 additions & 2 deletions lib/slax/projects/project_repos.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,19 @@ defmodule Slax.ProjectRepos do
|> Repo.all()
end

def get_by_repo(repo_name) do
Repo.get_by(ProjectRepo, repo_name: repo_name)
def get_by_repo_and_org(repo_name, org_name) do
lower_repo_name = String.downcase(repo_name)
lower_org_name = String.downcase(org_name)

query =
from(
p in ProjectRepo,
where:
fragment("lower(?)", p.repo_name) == ^lower_repo_name and
fragment("lower(?)", p.org_name) == ^lower_org_name
)

Repo.one(query)
end

def list_needs_reminder_message() do
Expand Down
2 changes: 1 addition & 1 deletion lib/slax_web/websockets/issue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule SlaxWeb.Issue do
defp maybe_load_from_default_repo(default_repo, issue_number) do
case default_repo do
nil ->
"No default repo set for this channel"
"Use the format 'org/repo#{issue_number}' or set a default repo for this channel with '/slax'."

_ ->
org_name = default_repo.org_name
Expand Down
2 changes: 1 addition & 1 deletion lib/slax_web/websockets/poker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule SlaxWeb.Poker do
estimates =
round.estimates
|> Enum.sort_by(& &1.value)
|> Enum.map(&"#{&1.user} (#{&1.value})#{if &1.reason, do: ': #{&1.reason}'}")
|> Enum.map(&"#{&1.user} (#{&1.value})#{if &1.reason, do: ~c": #{&1.reason}"}")

message = "Estimates for round:\n---\n#{Enum.join(estimates, "\n")}"

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule Slax.Mixfile do
{:phoenix, "~> 1.7.14", override: true},
{:phoenix_pubsub, "~> 2.0"},
{:phoenix_ecto, "~> 4.0"},
{:ecto_sql, "~> 3.11.1"},
{:ecto_sql, "~> 3.12.1"},
{:postgrex, "~> 0.16"},
{:plug_cowboy, "~> 2.5"},
{:plug, "~> 1.15.3"},
Expand Down
21 changes: 11 additions & 10 deletions mix.lock

Large diffs are not rendered by default.

32 changes: 25 additions & 7 deletions test/slax/github_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,33 @@ defmodule Slax.Github.Test do

def load_issue_setup(context) do
project = insert(:project)
insert(:project_repo, project: project, token: "success", repo_name: "success")
insert(:project_repo, project: project, token: "failure", repo_name: "failure")
insert(:project_repo, project: project, token: nil, repo_name: "nil")

insert(:project_repo,
project: project,
token: "success",
repo_name: "success",
org_name: "owner"
)

insert(:project_repo,
project: project,
token: "failure",
repo_name: "failure",
org_name: "owner"
)

insert(:project_repo,
project: project,
token: nil,
repo_name: "nil",
org_name: "owner"
)

params = %{
repo_and_issue_success: "success/1",
repo_and_issue_failure: "failure/1",
repo_and_issue_nil: "nil/1",
repo_and_issue_na: "na/1"
repo_and_issue_success: "owner/success/1",
repo_and_issue_failure: "owner/failure/1",
repo_and_issue_nil: "owner/nil/1",
repo_and_issue_na: "owner/na/1"
}

{:ok, context |> Map.put(:params, params)}
Expand Down
8 changes: 8 additions & 0 deletions test/slax/project_repos_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ defmodule Slax.ProjectRepos.Test do
assert length(repos_with_token) == 1
end
end

describe "get one by repo_name and org_name" do
test "get_by_repo_and_org/2" do
repo = ProjectRepos.get_by_repo_and_org("girl u know its TRUE", "miLIVAnili")
assert repo.org_name == "milivanili"
assert repo.repo_name == "girl u know its true"
end
end
end

0 comments on commit 2727765

Please sign in to comment.