Skip to content

Commit

Permalink
Bump credo from 1.7.5 to 1.7.7 (#427)
Browse files Browse the repository at this point in the history
* Bump credo from 1.7.5 to 1.7.7

Bumps [credo](https://github.com/rrrene/credo) from 1.7.5 to 1.7.7.
- [Release notes](https://github.com/rrrene/credo/releases)
- [Changelog](https://github.com/rrrene/credo/blob/master/CHANGELOG.md)
- [Commits](rrrene/credo@v1.7.5...v1.7.7)

---
updated-dependencies:
- dependency-name: credo
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* clear credo warnings

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ross Garfield <[email protected]>
  • Loading branch information
dependabot[bot] and rgarfield11 authored Jun 21, 2024
1 parent 2fc8abe commit f735599
Show file tree
Hide file tree
Showing 39 changed files with 245 additions and 173 deletions.
1 change: 1 addition & 0 deletions lib/slax.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Slax do
@moduledoc false
use Application

# See http://elixir-lang.org/docs/stable/elixir/Application.html
Expand Down
1 change: 1 addition & 0 deletions lib/slax/channels/channel.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Slax.Channel do
@moduledoc false
use Slax.Schema

@type t :: %__MODULE__{}
Expand Down
23 changes: 15 additions & 8 deletions lib/slax/channels/channels.ex
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
defmodule Slax.Channels do
@moduledoc false
use Slax.Context

alias Slax.Channel

def create_or_update_channel(channel_id, %{name: name} = attrs) do
case Repo.get_by(Channel, %{channel_id: channel_id, name: name}) do
nil -> %Channel{channel_id: channel_id, name: name}
channel -> channel
end
channel =
case Repo.get_by(Channel, %{channel_id: channel_id, name: name}) do
nil -> %Channel{channel_id: channel_id, name: name}
channel -> channel
end

channel
|> Channel.changeset(attrs)
|> Repo.insert_or_update()
end
Expand Down Expand Up @@ -37,10 +41,13 @@ defmodule Slax.Channels do
end

def set_default_repo(%{"id" => channel_id, "name" => channel_name}, attrs) do
case get_by_channel_id(channel_id) do
nil -> %Channel{channel_id: channel_id, name: channel_name}
channel -> channel
end
channel =
case get_by_channel_id(channel_id) do
nil -> %Channel{channel_id: channel_id, name: channel_name}
channel -> channel
end

channel
|> Channel.changeset(attrs)
|> Repo.insert_or_update()
end
Expand Down
1 change: 1 addition & 0 deletions lib/slax/commands/context.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Slax.Commands.Context do
@moduledoc false
defstruct user: nil
@type t :: %__MODULE__{}
end
63 changes: 36 additions & 27 deletions lib/slax/commands/github_commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ defmodule Slax.Commands.GithubCommands do
def parse_project_name(results, text) do
case Regex.run(~r/^[a-zA-Z0-9\-_]{3,21}$/, text) do
[project_name] ->
Map.put(results, :project_name, project_name)
results
|> Map.put(:project_name, project_name)
|> Map.update(:success, %{}, fn x -> Map.put(x, :project_name, "Project Name Parsed") end)

_ ->
Expand All @@ -36,7 +37,7 @@ defmodule Slax.Commands.GithubCommands do

@doc """
Pulls all issue templates from a story repo that are included in `story_paths`.
It then uses these templates to create issues in a newly created github repository,
It then uses these templates to create issues in a newly created github repository,
If there is no github repository the function will exit early. The sleep avoids github rate limit abuse err.
"""
def create_reusable_stories(
Expand All @@ -60,26 +61,9 @@ defmodule Slax.Commands.GithubCommands do

errors = tree_errors ++ parse_errors ++ github_errors

results =
if length(errors) > 0 do
errors =
Enum.map(errors, fn {:error, path, message} -> "#{path}: #{message}" end)
|> Enum.join("\n")

Map.update(results, :errors, %{}, fn x -> Map.put(x, :reusable_stories, errors) end)
else
results
end

results =
if length(issue_ids) > 0 do
Map.put(results, :reusable_stories, true)
|> Map.update(:success, %{}, fn x ->
Map.put(x, :reusable_stories, "Reuseable Stories Created")
end)
else
results
end
results = update_results_with_errors(errors, results)

results = update_results_with_issues(issue_ids, results)

results

Expand All @@ -90,10 +74,36 @@ defmodule Slax.Commands.GithubCommands do

def create_reusable_stories(results, _, _, _, _), do: results

defp update_results_with_errors(errors, results) do
if length(errors) > 0 do
errors =
Enum.map_join(errors, "\n", fn {:error, path, message} -> "#{path}: #{message}" end)

Map.update(results, :errors, %{}, fn x -> Map.put(x, :reusable_stories, errors) end)
else
results
end
end

defp update_results_with_issues(issue_ids, results) do
if length(issue_ids) > 0 do
results
|> Map.put(:reusable_stories, true)
|> Map.update(:success, %{}, fn x ->
Map.put(x, :reusable_stories, "Reuseable Stories Created")
end)
else
results
end
end

defp process_tree(data, story_repo, story_paths, github_access_token) do
Map.get(data, "tree", [])
|> Enum.filter(fn x -> x["type"] == "blob" && String.ends_with?(x["path"], ".md") end)
|> Enum.filter(fn x -> String.starts_with?(x["path"], Keyword.values(story_paths)) end)
data
|> Map.get("tree", [])
|> Enum.filter(fn x ->
x["type"] == "blob" && String.ends_with?(x["path"], ".md") &&
String.starts_with?(x["path"], Keyword.values(story_paths))
end)
|> Enum.map(fn x ->
case Github.fetch_blob(%{
access_token: github_access_token,
Expand Down Expand Up @@ -164,8 +174,7 @@ defmodule Slax.Commands.GithubCommands do
@spec format_results(map) :: binary
def format_results(results) do
@steps
|> Enum.map(&format_result(results, &1))
|> Enum.join("\n")
|> Enum.map_join("\n", &format_result(results, &1))
end

defp format_result(results, key) do
Expand Down
1 change: 1 addition & 0 deletions lib/slax/commands/github_commands/behaviour.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Slax.Commands.GithubCommands.Behaviour do
@moduledoc false
@typep results :: map()
@typep github_access_token :: String.t()
@typep org_name :: String.t()
Expand Down
57 changes: 31 additions & 26 deletions lib/slax/commands/latency.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ defmodule Slax.Commands.Latency do
status_labels = ["in progress", "in review", "qa", "uat", "up next"]

issue_events
|> Enum.filter(&Enum.member?(["labeled", "unlabeled"], &1["action"]))
|> Enum.filter(fn event ->
label_name =
event["label"]["name"]
|> String.downcase()
|> String.trim()

Enum.member?(status_labels, label_name)
end)
|> Enum.filter(
&(Enum.member?(["labeled", "unlabeled"], &1["action"]) &&
fn event ->
label_name =
event["label"]["name"]
|> String.downcase()
|> String.trim()

Enum.member?(status_labels, label_name)
end)
)
end

defp add_events_to_issues(issues, issues_events) do
Expand All @@ -62,8 +64,7 @@ defmodule Slax.Commands.Latency do
formatted_list =
results
|> Enum.filter(&issue_is_latent/1)
|> Enum.map(&format_issue(&1))
|> Enum.join("")
|> Enum.map_join("", &format_issue(&1))

date = DateTime.utc_now()

Expand Down Expand Up @@ -129,23 +130,27 @@ defmodule Slax.Commands.Latency do
|> Map.get("created_at")
end

update_status_from_new_event = fn event, status ->
case event["action"] do
"labeled" ->
[event["label"]["name"], event["created_at"]]

"unlabeled" ->
[old_status, _] = status

if old_status == event["label"]["name"] do
[nil, event["created_at"]]
else
status
end
end
status = fn event, status ->
maybe_update_status_from_new_event(event, status)
end

events
|> Enum.reduce([nil, first_timestamp], update_status_from_new_event)
|> Enum.reduce([nil, first_timestamp], status)
end

defp maybe_update_status_from_new_event(event, status) do
case event["action"] do
"labeled" ->
[event["label"]["name"], event["created_at"]]

"unlabeled" ->
[old_status, _] = status

if old_status == event["label"]["name"] do
[nil, event["created_at"]]
else
status
end
end
end
end
15 changes: 9 additions & 6 deletions lib/slax/commands/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ defmodule Slax.Commands.NewProject do
org_name: org_name
}) do
{:ok, repo_url} ->
Map.put(results, :github_repo, repo_url)
results
|> Map.put(:github_repo, repo_url)
|> Map.update(:success, %{}, fn x ->
Map.put(x, :github_repo, "Github Repo Found or Created: <#{repo_url}>")
end)
Expand All @@ -86,7 +87,8 @@ defmodule Slax.Commands.NewProject do
channel_id = channel["id"]
formatted_channel_name = "<##{channel_id}|#{channel_name}>"

Map.put(results, :slack_channel, channel_name)
results
|> Map.put(:slack_channel, channel_name)
|> Map.update(:success, %{}, fn x ->
Map.put(x, :slack_channel, "Channel Created: #{formatted_channel_name}")
end)
Expand All @@ -113,8 +115,7 @@ defmodule Slax.Commands.NewProject do
results =
if length(errors) > 0 do
errors =
Enum.map(errors, fn {:error, team, message} -> "#{team}: #{message}" end)
|> Enum.join("\n")
Enum.map_join(errors, "\n", fn {:error, team, message} -> "#{team}: #{message}" end)

Map.update(results, :errors, %{}, fn x -> Map.put(x, :github_org_teams, errors) end)
else
Expand All @@ -123,7 +124,8 @@ defmodule Slax.Commands.NewProject do

results =
if length(team_ids) > 0 do
Map.put(results, :github_org_teams, true)
results
|> Map.put(:github_org_teams, true)
|> Map.update(:success, %{}, fn x ->
Map.put(x, :github_org_teams, "Github Teams Added")
end)
Expand Down Expand Up @@ -164,7 +166,8 @@ defmodule Slax.Commands.NewProject do
) do
case Github.create_webhook(params) do
{:ok, _} ->
Map.put(results, webhook_key, true)
results
|> Map.put(webhook_key, true)
|> Map.update(:success, %{}, fn x -> Map.put(x, webhook_key, success_message) end)

{:error, message} ->
Expand Down
1 change: 1 addition & 0 deletions lib/slax/context.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Slax.Context do
@moduledoc false
defmacro __using__(_) do
quote do
import Ecto.Query, warn: false
Expand Down
3 changes: 1 addition & 2 deletions lib/slax/event_sink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ defmodule Slax.EventSink do
def fetch_issues_events(params, issues) when is_list(issues) do
issue_ids =
issues
|> Enum.map(& &1["number"])
|> Enum.join(",")
|> Enum.map_join(",", & &1["number"])

signature =
:crypto.hash(
Expand Down
25 changes: 14 additions & 11 deletions lib/slax/github.ex
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,7 @@ defmodule Slax.Github do
end)

{:error, %{status_code: 301, body: _body, headers: headers}} ->
location =
headers
|> Enum.find_value(fn {header, value} ->
case header do
"Location" ->
value

_ ->
false
end
end)
location = find_header_value(headers)

fetch_issues_from_url(location, params)

Expand Down Expand Up @@ -563,6 +553,19 @@ defmodule Slax.Github do
end
end

defp find_header_value(headers) do
headers
|> Enum.find_value(fn {header, value} ->
case header do
"Location" ->
value

_ ->
false
end
end)
end

defp retrieve_token(repo) do
case ProjectRepos.get_by_repo(repo) do
%{token: token} when not is_nil(token) ->
Expand Down
2 changes: 1 addition & 1 deletion lib/slax/helpers/text.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Slax.Helpers.Text do
@doc """
@moduledoc """
Takes in a list and joins the elements by comma and the word and
## Examples
Expand Down
6 changes: 3 additions & 3 deletions lib/slax/http.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Slax.Http do
@moduledoc false
def post(url, body, headers \\ [], options \\ []) do
url
|> http_adapter().post(body, headers, options)
Expand Down Expand Up @@ -66,9 +67,8 @@ defmodule Slax.Http do
do: {:error, reason}

defp parse_body(body) do
with {:ok, body} <- Jason.decode(body) do
body
else
case Jason.decode(body) do
{:ok, decoded_body} -> decoded_body
_ -> body
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/slax/http/behaviour.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Slax.Http.Behaviour do
@moduledoc false
@typep url :: binary()
@typep body :: {:form, [{atom(), any()}]}
@typep headers :: [{atom, binary}] | [{binary, binary}] | %{binary => binary}
Expand Down
Loading

0 comments on commit f735599

Please sign in to comment.