neiam
/gitgud
Git Gud
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
1
Log in to mark this repository.
Credo: list shapes by pattern, Map.new, and glob rules stay in Elixir
fec4951 · Gabe Morell · 2026-11-04 21:22
Files changed
modified
lib/git_gud/branch_protections.ex
+2
−0
@@ -49,6 +49,8 @@ defmodule GitGud.BranchProtections do
| 49 | 49 | |
| 50 | 50 | @doc "Fetch the first matching rule for a branch (by glob)." |
| 51 | 51 | def rule_for_branch(%Repository{id: rid}, branch) when is_binary(branch) do |
| 52 | + # Patterns are globs, matched in Elixir; a repository has a handful of rules. | |
| 53 | + # credo:disable-for-lines:2 ExSlop.Check.Warning.RepoAllThenFilter | |
| 52 | 54 | Repo.all(from p in BranchProtection, where: p.repository_id == ^rid) |
| 53 | 55 | |> Enum.find(&matches_pattern?(&1, branch)) |
| 54 | 56 | end |
modified
lib/git_gud/packages/formats/raw.ex
+8
−5
@@ -174,15 +174,18 @@ defmodule GitGud.Packages.Formats.Raw do
| 174 | 174 | end |
| 175 | 175 | end |
| 176 | 176 | |
| 177 | − def store(_repo, %{path: path}, _body) when length(path) != 2, | |
| 178 | − do: {:error, {400, "publish to /<version>/<filename>"}} | |
| 179 | − | |
| 180 | 177 | # A multipart body arrives as a params map (Plug.Parsers decoded it |
| 181 | 178 | # before the controller saw it). Nothing publishing raw bytes has a |
| 182 | 179 | # reason to send one, and guessing which part is the artifact is how |
| 183 | 180 | # the wrong bytes get published. |
| 184 | − def store(_repo, _ctx, _body), | |
| 185 | − do: {:error, {400, "send the file as the request body, not as a form"}} | |
| 181 | + def store(_repo, %{path: [_version, _filename]}, _body), do: not_a_form() | |
| 182 | + | |
| 183 | + def store(_repo, %{path: path}, _body) when is_list(path), | |
| 184 | + do: {:error, {400, "publish to /<version>/<filename>"}} | |
| 185 | + | |
| 186 | + def store(_repo, _ctx, _body), do: not_a_form() | |
| 187 | + | |
| 188 | + defp not_a_form, do: {:error, {400, "send the file as the request body, not as a form"}} | |
| 186 | 189 | |
| 187 | 190 | defp publish(%Repository{} = repo, version, filename, body) do |
| 188 | 191 | attrs = %{ |
modified
lib/git_gud/packages/retention.ex
+1
−2
@@ -147,11 +147,10 @@ defmodule GitGud.Packages.Retention do
| 147 | 147 | defp normalize_attrs(attrs) do |
| 148 | 148 | attrs |
| 149 | 149 | |> Enum.map(fn {k, v} -> {to_atom(k), blank_to_nil(v)} end) |
| 150 | − |> Enum.map(fn | |
| 150 | + |> Map.new(fn | |
| 151 | 151 | {key, value} when key in [:retention_keep, :retention_bytes] -> {key, to_integer(value)} |
| 152 | 152 | pair -> pair |
| 153 | 153 | end) |
| 154 | − |> Enum.into(%{}) | |
| 155 | 154 | end |
| 156 | 155 | |
| 157 | 156 | defp to_integer(nil), do: nil |
modified
lib/git_gud_web/live/personal_access_token_live/index.ex
+2
−2
@@ -159,8 +159,8 @@ defmodule GitGudWeb.PersonalAccessTokenLive.Index do
| 159 | 159 | end |
| 160 | 160 | |
| 161 | 161 | # Name a small bundle's scopes outright; a long one just gets a count. |
| 162 | − defp ticks_label(scopes) when length(scopes) <= 3, do: "Ticks #{Enum.join(scopes, ", ")}." | |
| 163 | − defp ticks_label(scopes), do: "Ticks the #{length(scopes)} scopes below." | |
| 162 | + defp ticks_label([_, _, _, _ | _] = scopes), do: "Ticks the #{length(scopes)} scopes below." | |
| 163 | + defp ticks_label(scopes), do: "Ticks #{Enum.join(scopes, ", ")}." | |
| 164 | 164 | |
| 165 | 165 | defp toggle(set, value) do |
| 166 | 166 | if MapSet.member?(set, value), do: MapSet.delete(set, value), else: MapSet.put(set, value) |
Parents: 3f25757