Skip to content

Commit 31e57f1

Browse files
committed
style: resolve all credo issues from v0.3.0 additions
11 credo issues fixed across 5 files: * lib/ado_cli/cli/test_coverage.ex - Extracted print_coverage_stats/1 to reduce nesting (5->3) and cyclomatic complexity (10->5) - Collapsed two identical empty-coverage clauses into show_no_coverage/1 * lib/ado_cli/cli/test_results.ex - Extracted print_run_row/1 from list_runs (cyclomatic 10->4, ABC 48->25) - Removed identity case in create_test_run (redirect passthrough) * lib/ado_cli/cli/pull_requests.ex - Extracted do_complete_patch/4 from complete_pr/1 (nesting 5->3, cyclomatic 10->5) - Replaced obvious comment in resolve_reviewer_id with inline docs * lib/ado_cli/cli/wikis.ex - Rephrased obvious comment (Fetch page -> Why ETag matters) * test/ado_cli/cli/test_results_test.exs - Reordered aliases alphabetically (TestCoverage before TestResults) Verified: 819 mods/funs, 0 issues, 325 tests pass, compile clean.
1 parent 5d6c3dd commit 31e57f1

5 files changed

Lines changed: 65 additions & 74 deletions

File tree

lib/ado_cli/cli/pull_requests.ex

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -443,22 +443,7 @@ defmodule AdoCli.CLI.PullRequests do
443443
last_commit_id ->
444444
body = build_complete_body(parsed, last_commit_id)
445445

446-
case Client.patch(path, body) do
447-
{:ok, pr} ->
448-
success("Pull request ##{pr["pullRequestId"]} completed (merged).\n")
449-
halt_success("")
450-
451-
{:error, %{status: 404}} ->
452-
halt_error("Pull request ##{pr_id} not found")
453-
454-
{:error, %{status: status, body: body}} ->
455-
halt_error(
456-
"Cannot complete PR ##{pr_id}: #{inspect(body["message"] || "HTTP #{status}")}"
457-
)
458-
459-
error ->
460-
Helpers.handle_api_result(error, parsed, fn _ -> :ok end)
461-
end
446+
do_complete_patch(path, body, pr_id, parsed)
462447
end
463448

464449
error ->
@@ -476,6 +461,26 @@ defmodule AdoCli.CLI.PullRequests do
476461
put_if_key(merge_strategy(Map.get(parsed.options, :merge_strategy)), body, "mergeStrategy")
477462
end
478463

464+
# Extracted from complete_pr/1 to reduce nesting depth.
465+
defp do_complete_patch(path, body, pr_id, parsed) do
466+
case Client.patch(path, body) do
467+
{:ok, pr} ->
468+
success("Pull request ##{pr["pullRequestId"]} completed (merged).\n")
469+
halt_success("")
470+
471+
{:error, %{status: 404}} ->
472+
halt_error("Pull request ##{pr_id} not found")
473+
474+
{:error, %{status: status, body: body}} ->
475+
halt_error(
476+
"Cannot complete PR ##{pr_id}: #{inspect(body["message"] || "HTTP #{status}")}"
477+
)
478+
479+
error ->
480+
Helpers.handle_api_result(error, parsed, fn _ -> :ok end)
481+
end
482+
end
483+
479484
@doc """
480485
Approves a pull request (vote = +10).
481486
"""
@@ -887,10 +892,6 @@ defmodule AdoCli.CLI.PullRequests do
887892
end
888893

889894
defp resolve_reviewer_id(project, repo_id, pr_id) do
890-
# Fetch the authenticated user's identity GUID from the
891-
# Azure DevOps connection data (cached on first call).
892-
# Then scan the PR reviewer list for a reviewer whose
893-
# `identity.id` matches that GUID. Only the user's own
894895
# reviewer slot can be voted on — trying to PUT a vote
895896
# to a different reviewer's slot returns:
896897
# "You cannot record a vote for someone else."

lib/ado_cli/cli/test_coverage.ex

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,47 +57,40 @@ defmodule AdoCli.CLI.TestCoverage do
5757
writeln("")
5858
writeln("Code Coverage for Build ##{build_id}")
5959
writeln(String.duplicate("─", 70))
60-
61-
Enum.each(covers, fn cov ->
62-
config = cov["coverageStats"] || []
63-
64-
Enum.each(config, fn s ->
65-
label = String.pad_trailing(s["label"] || "?", 20)
66-
total = s["total"] || 0
67-
covered = s["covered"] || 0
68-
69-
pct =
70-
if total > 0,
71-
do: Float.round(covered / total * 100, 1),
72-
else: 0.0
73-
74-
bar = coverage_bar(pct)
75-
writeln(" #{label} #{String.pad_leading("#{pct}%", 8)} #{bar}")
76-
end)
77-
end)
78-
60+
Enum.each(covers, &print_coverage_stats/1)
7961
writeln("")
8062
end)
8163

8264
halt_success("Done.")
8365

84-
{:ok, %{"value" => []}} ->
85-
writeln("")
86-
writeln("No coverage data for build ##{build_id}.")
87-
writeln("")
88-
halt_success("Done.")
89-
90-
{:ok, _empty} ->
91-
writeln("")
92-
writeln("No coverage data for build ##{build_id}.")
93-
writeln("")
94-
halt_success("Done.")
66+
{:ok, _empty_or_no_data} ->
67+
show_no_coverage(build_id)
9568

9669
error ->
9770
Helpers.handle_api_result(error, parsed, fn _ -> :ok end)
9871
end
9972
end
10073

74+
defp show_no_coverage(build_id) do
75+
writeln("")
76+
writeln("No coverage data for build ##{build_id}.")
77+
writeln("")
78+
halt_success("Done.")
79+
end
80+
81+
defp print_coverage_stats(cov) do
82+
config = cov["coverageStats"] || []
83+
84+
Enum.each(config, fn s ->
85+
label = String.pad_trailing(s["label"] || "?", 20)
86+
total = s["total"] || 0
87+
covered = s["covered"] || 0
88+
pct = if total > 0, do: Float.round(covered / total * 100, 1), else: 0.0
89+
bar = coverage_bar(pct)
90+
writeln(" #{label} #{String.pad_leading("#{pct}%", 8)} #{bar}")
91+
end)
92+
end
93+
10194
defp coverage_bar(pct) do
10295
filled = round(pct / 5)
10396
empty = 20 - filled

lib/ado_cli/cli/test_results.ex

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,7 @@ defmodule AdoCli.CLI.TestResults do
101101

102102
writeln(String.duplicate("─", 90))
103103

104-
Enum.each(runs, fn run ->
105-
id = to_string(run["id"] || "")
106-
name = String.slice(run["name"] || "", 0, 39)
107-
state = run["state"] || "?"
108-
109-
stats = run["runStatistics"] || []
110-
total = find_stat(stats, "TotalTests") || "?"
111-
passed = find_stat(stats, "Passed") || "0"
112-
failed = find_stat(stats, "Failed") || "0"
113-
114-
writeln(
115-
"#{String.pad_trailing(id, 8)} #{String.pad_trailing(name, 40)} " <>
116-
"#{String.pad_trailing(state, 12)} #{total} / #{passed} / #{failed}"
117-
)
118-
end)
104+
Enum.each(runs, &print_run_row/1)
119105

120106
writeln("")
121107
end)
@@ -159,6 +145,22 @@ defmodule AdoCli.CLI.TestResults do
159145
stat && stat["count"]
160146
end
161147

148+
defp print_run_row(run) do
149+
id = to_string(run["id"] || "")
150+
name = String.slice(run["name"] || "", 0, 39)
151+
state = run["state"] || "?"
152+
153+
stats = run["runStatistics"] || []
154+
total = find_stat(stats, "TotalTests") || "?"
155+
passed = find_stat(stats, "Passed") || "0"
156+
failed = find_stat(stats, "Failed") || "0"
157+
158+
writeln(
159+
"#{String.pad_trailing(id, 8)} #{String.pad_trailing(name, 40)} " <>
160+
"#{String.pad_trailing(state, 12)} #{total} / #{passed} / #{failed}"
161+
)
162+
end
163+
162164
# ── show ────────────────────────────────────────────────────────────
163165

164166
def show_run(parsed) do
@@ -259,11 +261,7 @@ defmodule AdoCli.CLI.TestResults do
259261
end
260262

261263
path = "/#{project}/_apis/test/runs"
262-
263-
case Client.post(path, body) do
264-
{:ok, run} -> {:ok, run}
265-
{:error, reason} -> {:error, reason}
266-
end
264+
Client.post(path, body)
267265
end
268266

269267
defp attach_file(project, run_id, file_path, _content) do

lib/ado_cli/cli/wikis.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ defmodule AdoCli.CLI.Wikis do
187187
path = Map.fetch!(parsed.options, :path)
188188
content = Map.fetch!(parsed.options, :content)
189189

190-
# Fetch the existing page to get its ETag for optimistic
191-
# concurrency. The If-Match header prevents overwriting
192-
# changes made by another user between our read and write.
190+
# The If-Match header (ETag) prevents overwriting changes
191+
# made by another user between our read and write.
193192
case Client.get("/#{URI.encode(project)}/_apis/wiki/wikis/#{URI.encode(wiki_id)}/pages", %{
194193
"path" => path,
195194
"includeContent" => "true"

test/ado_cli/cli/test_results_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule AdoCli.CLI.TestResultsTest do
22
use AdoCli.CLI.TestHelper
3-
alias AdoCli.CLI.TestResults
43
alias AdoCli.CLI.TestCoverage
4+
alias AdoCli.CLI.TestResults
55

66
describe "test-results list" do
77
test "halts 0 on success with runs", %{server: server} do

0 commit comments

Comments
 (0)