neiam
/gitgud
Git Gud
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
Log in to mark this repository.
Credo: two-way conds become ifs
e737fcd · Gabe Morell · 2026-11-04 20:36
Files changed
modified
lib/git_gud/federation/workers/process_inbox.ex
+36
−42
| 234 | 234 | # Ticket and identifies the target repo via `target` or via the |
| 235 | 235 | # delivery's target_actor (which is what we already resolved). |
| 236 | 236 | defp handle_offer(object, doc, source_actor, target_actor) do |
| 237 | − cond do | |
| 238 | − not ticket_with_merge?(object) -> | |
| 239 | − :ok | |
| 240 | − | |
| 241 | − true -> | |
| 242 | − case repo_for_actor(target_actor) do | |
| 243 | − %GitGud.Repositories.Repository{} = repo -> | |
| 244 | − create_federated_pr_from_offer(repo, source_actor, object, doc) | |
| 237 | + if ticket_with_merge?(object) do | |
| 238 | + case repo_for_actor(target_actor) do | |
| 239 | + %GitGud.Repositories.Repository{} = repo -> | |
| 240 | + create_federated_pr_from_offer(repo, source_actor, object, doc) | |
| 245 | 241 | |
| 246 | − _ -> | |
| 247 | − :ok | |
| 248 | − end | |
| 242 | + _ -> | |
| 243 | + :ok | |
| 244 | + end | |
| 245 | + else | |
| 246 | + :ok | |
| 249 | 247 | end |
| 250 | 248 | end |
| 251 | 249 |
| 342 | 340 | # source actor + source clone URL + branch (some implementations |
| 343 | 341 | # re-use the Ticket id and don't echo the original Offer URL). |
| 344 | 342 | defp handle_update(object, source_actor) do |
| 345 | − cond do | |
| 346 | − ticket_with_merge?(object) -> | |
| 347 | − with {:ok, pr} <- find_federated_pr(object, source_actor) do | |
| 348 | − refresh_federated_pr(pr, object) | |
| 349 | − end | |
| 350 | − | |
| 351 | − true -> | |
| 352 | − :ok | |
| 343 | + if ticket_with_merge?(object) do | |
| 344 | + with {:ok, pr} <- find_federated_pr(object, source_actor) do | |
| 345 | + refresh_federated_pr(pr, object) | |
| 346 | + end | |
| 347 | + else | |
| 348 | + :ok | |
| 353 | 349 | end |
| 354 | 350 | end |
| 355 | 351 |
| 392 | 388 | ) |
| 393 | 389 | end |
| 394 | 390 | |
| 395 | − cond do | |
| 396 | − by_ticket -> | |
| 397 | − {:ok, by_ticket} | |
| 398 | − | |
| 399 | − true -> | |
| 400 | − # Fallback: source actor + source branch (best we can do when | |
| 401 | − # implementations don't echo the original activity URL). | |
| 402 | − case Map.get(object, "sourceBranch") do | |
| 403 | − ref when is_binary(ref) -> | |
| 404 | − Repo.one( | |
| 405 | − from p in GitGud.PullRequests.PullRequest, | |
| 406 | − where: p.source_actor_id == ^source_actor.id and p.source_ref == ^ref, | |
| 407 | − order_by: [desc: p.inserted_at], | |
| 408 | − limit: 1 | |
| 409 | − ) | |
| 410 | − |> case do | |
| 411 | − nil -> {:error, :no_match} | |
| 412 | − pr -> {:ok, pr} | |
| 413 | − end | |
| 414 | − | |
| 415 | − _ -> | |
| 416 | − {:error, :no_match} | |
| 417 | − end | |
| 391 | + if by_ticket do | |
| 392 | + {:ok, by_ticket} | |
| 393 | + else | |
| 394 | + # Fallback: source actor + source branch (best we can do when | |
| 395 | + # implementations don't echo the original activity URL). | |
| 396 | + case Map.get(object, "sourceBranch") do | |
| 397 | + ref when is_binary(ref) -> | |
| 398 | + Repo.one( | |
| 399 | + from p in GitGud.PullRequests.PullRequest, | |
| 400 | + where: p.source_actor_id == ^source_actor.id and p.source_ref == ^ref, | |
| 401 | + order_by: [desc: p.inserted_at], | |
| 402 | + limit: 1 | |
| 403 | + ) | |
| 404 | + |> case do | |
| 405 | + nil -> {:error, :no_match} | |
| 406 | + pr -> {:ok, pr} | |
| 407 | + end | |
| 408 | + | |
| 409 | + _ -> | |
| 410 | + {:error, :no_match} | |
| 411 | + end | |
| 418 | 412 | end |
| 419 | 413 | end |
| 420 | 414 |
modified
lib/git_gud/markdown.ex
+11
−15
| 45 | 45 | theme = opts |> Keyword.get(:theme) |> EditorTheme.resolve() |
| 46 | 46 | repo = Keyword.get(opts, :repo) |
| 47 | 47 | |
| 48 | − cond do | |
| 49 | − byte_size(body) > @max_bytes -> | |
| 50 | − body | |
| 51 | − |> Phoenix.HTML.html_escape() | |
| 52 | − |> Phoenix.HTML.safe_to_string() | |
| 53 | − |> wrap_pre() | |
| 54 | − | |
| 55 | − true -> | |
| 56 | − cache_get_or_compute(body, theme, repo) | |
| 48 | + if byte_size(body) > @max_bytes do | |
| 49 | + body | |
| 50 | + |> Phoenix.HTML.html_escape() | |
| 51 | + |> Phoenix.HTML.safe_to_string() | |
| 52 | + |> wrap_pre() | |
| 53 | + else | |
| 54 | + cache_get_or_compute(body, theme, repo) | |
| 57 | 55 | end |
| 58 | 56 | end |
| 59 | 57 |
| 152 | 150 | full |
| 153 | 151 | |
| 154 | 152 | number -> |
| 155 | − cond do | |
| 156 | − owner != "" and name != "" -> | |
| 157 | − cross_repo_link(owner, name, ref_str, number, full) | |
| 158 | − | |
| 159 | − true -> | |
| 160 | − local_link(repo, ref_str, number, full) | |
| 153 | + if owner != "" and name != "" do | |
| 154 | + cross_repo_link(owner, name, ref_str, number, full) | |
| 155 | + else | |
| 156 | + local_link(repo, ref_str, number, full) | |
| 161 | 157 | end |
| 162 | 158 | end |
| 163 | 159 | end) |
modified
lib/git_gud/outbound_url.ex
+6
−8
| 166 | 166 | "protocol.git.allow=always" |
| 167 | 167 | ] |
| 168 | 168 | |
| 169 | − cond do | |
| 170 | − local_path?(url) and config(:allow_local_paths, false) -> | |
| 171 | − {:ok, ["-c", "protocol.file.allow=always"]} | |
| 172 | − | |
| 173 | − true -> | |
| 174 | − with {:ok, target} <- check(url, purpose, schemes: @git_schemes) do | |
| 175 | − {:ok, base ++ resolve_pin(target)} | |
| 176 | − end | |
| 169 | + if local_path?(url) and config(:allow_local_paths, false) do | |
| 170 | + {:ok, ["-c", "protocol.file.allow=always"]} | |
| 171 | + else | |
| 172 | + with {:ok, target} <- check(url, purpose, schemes: @git_schemes) do | |
| 173 | + {:ok, base ++ resolve_pin(target)} | |
| 174 | + end | |
| 177 | 175 | end |
| 178 | 176 | end |
| 179 | 177 |
modified
lib/git_gud/packages/formats/fdroid/manifest.ex
+8
−10
| 76 | 76 | when header_size >= 8 do |
| 77 | 77 | # The declared size may be shorter than the file (trailing padding |
| 78 | 78 | # is legal); longer means the file is truncated. |
| 79 | − cond do | |
| 80 | − size > byte_size(data) -> | |
| 81 | − {:error, {422, "AndroidManifest.xml is truncated"}} | |
| 82 | − | |
| 83 | − true -> | |
| 84 | − body = binary_part(data, header_size, size - header_size) | |
| 79 | + if size > byte_size(data) do | |
| 80 | + {:error, {422, "AndroidManifest.xml is truncated"}} | |
| 81 | + else | |
| 82 | + body = binary_part(data, header_size, size - header_size) | |
| 85 | 83 | |
| 86 | − with {:ok, pool} <- find_string_pool(body), | |
| 87 | − {:ok, elements} <- collect_elements(body, pool) do | |
| 88 | − {:ok, assemble(elements)} | |
| 89 | − end | |
| 84 | + with {:ok, pool} <- find_string_pool(body), | |
| 85 | + {:ok, elements} <- collect_elements(body, pool) do | |
| 86 | + {:ok, assemble(elements)} | |
| 87 | + end | |
| 90 | 88 | end |
| 91 | 89 | end |
| 92 | 90 |
modified
lib/git_gud/profiles.ex
+11
−13
| 66 | 66 | defp do_pin(owner_key, owner_id, repo_id) do |
| 67 | 67 | existing = count(owner_key, owner_id) |
| 68 | 68 | |
| 69 | − cond do | |
| 70 | − existing >= @max_pins -> | |
| 71 | − {:error, :max_reached} | |
| 72 | − | |
| 73 | − true -> | |
| 74 | − attrs = | |
| 75 | − Map.new([ | |
| 76 | − {owner_key, owner_id}, | |
| 77 | − {:repository_id, repo_id}, | |
| 78 | − {:position, existing} | |
| 79 | − ]) | |
| 80 | − | |
| 81 | − %Pin{} |> Pin.changeset(attrs) |> Repo.insert() | |
| 69 | + if existing >= @max_pins do | |
| 70 | + {:error, :max_reached} | |
| 71 | + else | |
| 72 | + attrs = | |
| 73 | + Map.new([ | |
| 74 | + {owner_key, owner_id}, | |
| 75 | + {:repository_id, repo_id}, | |
| 76 | + {:position, existing} | |
| 77 | + ]) | |
| 78 | + | |
| 79 | + %Pin{} |> Pin.changeset(attrs) |> Repo.insert() | |
| 82 | 80 | end |
| 83 | 81 | end |
| 84 | 82 |
modified
lib/git_gud/repositories.ex
+27
−31
Click to load diff…
modified
lib/git_gud/secrets.ex
+10
−12
Click to load diff…
modified
lib/git_gud/ssh/server.ex
+6
−8
Click to load diff…
modified
lib/git_gud/syntax_highlight.ex
+6
−8
Click to load diff…
modified
lib/git_gud/workflows.ex
+11
−15
Click to load diff…
modified
lib/git_gud_web/controllers/actions_cache_controller.ex
+26
−28
Click to load diff…
modified
lib/git_gud_web/controllers/package_registry_controller.ex
+20
−22
Click to load diff…
modified
lib/git_gud_web/controllers/runner_controller.ex
+45
−49
Click to load diff…
modified
lib/git_gud_web/controllers/workflow_artifact_controller.ex
+10
−12
Click to load diff…
modified
lib/git_gud_web/live/moderation_actions.ex
+25
−27
Click to load diff…
modified
lib/git_gud_web/live/org_live/settings_runners.ex
+32
−35
Click to load diff…
modified
lib/git_gud_web/live/profile_components.ex
+5
−7
Click to load diff…
modified
lib/git_gud_web/live/repo_live/blob.ex
+4
−7
Click to load diff…
modified
lib/git_gud_web/live/repo_live/settings_runners.ex
+29
−32
Click to load diff…
modified
lib/git_gud_web/live/repo_live/show.ex
+4
−6
Click to load diff…
modified
lib/git_gud_web/live/workflow_live/show.ex
+52
−58
Click to load diff…
modified
lib/git_gud_web/user_auth.ex
+16
−18
Click to load diff…
Parents: 286fcb6