Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/lib/linear_cli/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,11 @@ defmodule LinearCli.CLI do
long: "--status",
help: "Workflow state name to use with --close or --cancel"
],
reason: [long: "--reason", help: "Reason for closing the issue. - open an editor"]
reason: [long: "--reason", help: "Reason for closing the issue. - open an editor"],
priority: [
long: "--priority",
help: "Set the issue priority: none, urgent, high, medium, low"
]
]
],
relation: [
Expand Down
30 changes: 29 additions & 1 deletion app/lib/linear_cli/cli/commands/issues/mutations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ defmodule LinearCli.CLI.Commands.Issues.Mutations do
with :ok <- validate_issue_ids(issue_ids),
:ok <- validate_body_file_exclusion(options, :description, "--description"),
{:ok, description} <- resolve_body_from_file(options, :description),
{:ok, priority} <- parse_priority(Map.get(options, :priority)),
{:ok, issues} <-
Linear.issues(%{ids: Enum.map(issue_ids, &Identifiers.expand_issue_id/1)}) do
update_opts = [
Expand All @@ -41,7 +42,8 @@ defmodule LinearCli.CLI.Commands.Issues.Mutations do
close: flags.close,
reason: options.reason,
status: Map.get(options, :status),
trash: flags.trash
trash: flags.trash,
priority: priority
]

Enum.reduce_while(issues, :ok, fn issue, :ok ->
Expand Down Expand Up @@ -353,4 +355,30 @@ defmodule LinearCli.CLI.Commands.Issues.Mutations do
ambiguous = Enum.map_join(matches, ", ", & &1.name)
{:error, {:smells_bad, "Ambiguous assignee #{inspect(name)}: matches #{ambiguous}"}}
end

defp parse_priority(nil), do: {:ok, nil}

defp parse_priority(value) do
case String.downcase(value) do
"none" ->
{:ok, 0}

"urgent" ->
{:ok, 1}

"high" ->
{:ok, 2}

"medium" ->
{:ok, 3}

"low" ->
{:ok, 4}

_ ->
{:error,
{:smells_bad,
"invalid --priority #{inspect(value)}: must be one of: none, urgent, high, medium, low"}}
end
end
end
25 changes: 23 additions & 2 deletions app/lib/linear_cli/cli/issue/actions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,25 @@ defmodule LinearCli.CLI.Issue.Actions do
end
end

@doc """
Sets `issue`'s priority to `priority_value` (0–4, already validated and
converted by the CLI parser).

0 = No priority, 1 = Urgent, 2 = High, 3 = Medium, 4 = Low.
"""
@spec set_priority(%Linear.Issue{}, non_neg_integer()) ::
{:ok, %Linear.Issue{}} | {:error, term()}
def set_priority(issue, priority_value) do
case Linear.set_issue_priority(issue, priority_value) do
{:ok, updated} ->
Prompt.ok("#{issue.identifier} priority updated")
{:ok, updated}

{:error, reason} ->
{:error, reason}
end
end

@doc """
Dispatches an issue update per whichever of `opts`' keys is set, in Ruby's
exact precedence order:
Expand All @@ -207,8 +226,9 @@ defmodule LinearCli.CLI.Issue.Actions do
4. `:pr` -> `LinearCli.CLI.Issue.PullRequest.issue_pr/2`
5. `:project` -> `attach_project/2`
6. `:description` -> `update_description/2`
7. otherwise, if only `:comment` was given, stop silently
8. otherwise, warn "No action taken" and report "not updated"
7. `:priority` -> `set_priority/2`
8. otherwise, if only `:comment` was given, stop silently
9. otherwise, warn "No action taken" and report "not updated"

Ported from `CLI::Issue#update_issue`. Unlike every other function in this
module, normalizes its result down to `:ok | {:error, reason}` (dropping
Expand Down Expand Up @@ -238,6 +258,7 @@ defmodule LinearCli.CLI.Issue.Actions do
opts[:pr] -> PullRequest.issue_pr(issue, opts)
opts[:project] -> normalize(attach_project(issue, opts[:project]))
opts[:description] -> normalize(update_description(issue, opts[:description]))
not is_nil(opts[:priority]) -> normalize(set_priority(issue, opts[:priority]))
opts[:comment] -> :ok
true -> no_action_taken()
end
Expand Down
1 change: 1 addition & 0 deletions app/lib/linear_cli/linear.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ defmodule LinearCli.Linear do
define :close_issue, action: :close, args: [:state_id]
define :set_issue_status, action: :set_status, args: [:state_id]
define :update_issue_description, action: :update_description, args: [:description]
define :set_issue_priority, action: :set_priority, args: [:priority]
end

resource LinearCli.Linear.Label do
Expand Down
18 changes: 18 additions & 0 deletions app/lib/linear_cli/linear/issue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ defmodule LinearCli.Linear.Issue do
argument :description, :string, allow_nil?: false
manual LinearCli.Linear.Issue.Update.UpdateDescription
end

update :set_priority do
argument :priority, :integer, allow_nil?: false
manual LinearCli.Linear.Issue.Update.SetPriority
end
end

attributes do
Expand Down Expand Up @@ -516,3 +521,16 @@ defmodule LinearCli.Linear.Issue.Update.UpdateDescription do
})
end
end

defmodule LinearCli.Linear.Issue.Update.SetPriority do
@moduledoc false
use Ash.Resource.ManualUpdate

alias LinearCli.Linear.Issue

def update(changeset, _opts, _context) do
Issue.Update.run(changeset.data.identifier, %{
"priority" => changeset.arguments.priority
})
end
end
Loading