Skip to content

Commit

Permalink
Merge pull request #453 from revelrylabs/bug/450
Browse files Browse the repository at this point in the history
make repo and org query case insensitive
  • Loading branch information
dweill authored Aug 30, 2024
2 parents 9f64d40 + 8a64a31 commit 988f85e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/slax/github.ex
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ defmodule Slax.Github do
end

defp retrieve_token(repo, org) do
case ProjectRepos.get_by_repo(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, org) 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, org_name) do
Repo.get_by(ProjectRepo, repo_name: repo_name, org_name: org_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
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 988f85e

Please sign in to comment.