From 2e8b6d30a77defeba35337e9a9ac6e6aa38af378 Mon Sep 17 00:00:00 2001 From: dweill Date: Tue, 27 Aug 2024 16:16:22 -0500 Subject: [PATCH 1/2] add org clause to project_repos query --- lib/slax/github.ex | 9 ++++----- lib/slax/poker.ex | 2 +- lib/slax/projects/project_repos.ex | 4 ++-- test/slax/github_test.exs | 14 +++++++------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/slax/github.ex b/lib/slax/github.ex index 0c36de7b..aa9bd3a8 100644 --- a/lib/slax/github.ex +++ b/lib/slax/github.ex @@ -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 @@ -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} @@ -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} @@ -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(repo, org) do %{token: token} when not is_nil(token) -> {token, ""} diff --git a/lib/slax/poker.ex b/lib/slax/poker.ex index daae323e..ec9a673b 100644 --- a/lib/slax/poker.ex +++ b/lib/slax/poker.ex @@ -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(repo, org) do %{token: token} when not is_nil(token) -> Tentacat.Client.new(%{access_token: token}) diff --git a/lib/slax/projects/project_repos.ex b/lib/slax/projects/project_repos.ex index 4e7e9fb2..8e684679 100644 --- a/lib/slax/projects/project_repos.ex +++ b/lib/slax/projects/project_repos.ex @@ -72,8 +72,8 @@ 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(repo_name, org_name) do + Repo.get_by(ProjectRepo, repo_name: repo_name, org_name: org_name) end def list_needs_reminder_message() do diff --git a/test/slax/github_test.exs b/test/slax/github_test.exs index 3431579f..d8da7aef 100644 --- a/test/slax/github_test.exs +++ b/test/slax/github_test.exs @@ -545,15 +545,15 @@ 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)} From ab71d2817565a786cfbefd10d7db1dac556550da Mon Sep 17 00:00:00 2001 From: dweill Date: Tue, 27 Aug 2024 16:48:10 -0500 Subject: [PATCH 2/2] format --- test/slax/github_test.exs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/slax/github_test.exs b/test/slax/github_test.exs index d8da7aef..2d1a4cd9 100644 --- a/test/slax/github_test.exs +++ b/test/slax/github_test.exs @@ -545,9 +545,27 @@ defmodule Slax.Github.Test do def load_issue_setup(context) do project = insert(:project) - 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") + + 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: "owner/success/1",