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
7 changes: 6 additions & 1 deletion app/lib/linear_cli/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,12 @@ defmodule LinearCli.CLI do
],
project: [short: "-p", long: "--project", help: "Project Identifier"],
team: [short: "-T", long: "--team", help: "Team Identifier"],
title: [short: "-t", long: "--title", help: "Issue Title"]
title: [short: "-t", long: "--title", help: "Issue Title"],
priority: [
long: "--priority",
help: "Issue priority: none, urgent, high, medium, low",
parser: &LinearCli.CLI.Priority.parse/1
]
],
flags: [
develop: [long: "--dev", help: "Start development after creating the issue"],
Expand Down
1 change: 1 addition & 0 deletions app/lib/linear_cli/cli/commands/issues/create.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defmodule LinearCli.CLI.Commands.Issues.Create do
description: description,
team: options.team,
labels: options.labels,
priority: Map.get(options, :priority),
project: options.project,
yes: flags.yes
],
Expand Down
16 changes: 14 additions & 2 deletions app/lib/linear_cli/cli/issue/creation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ defmodule LinearCli.CLI.Issue.Creation do
with {:ok, projects} <- Linear.projects_by_team(team.id, %{search: project_search}) do
project = Projects.project_for(projects, project_search)
label_ids = Enum.map(labels, & &1.id)
params = maybe_put_project_id(%{label_ids: label_ids}, project)

params =
%{label_ids: label_ids}
|> maybe_put_project_id(project)
|> maybe_put_priority(opts[:priority])

Linear.create_issue(title, description, team.id, params)
end
Expand All @@ -79,7 +83,12 @@ defmodule LinearCli.CLI.Issue.Creation do
else: nil

label_ids = Enum.map(labels, & &1.id)
params = maybe_put_project_id(%{label_ids: label_ids}, project)

params =
%{label_ids: label_ids}
|> maybe_put_project_id(project)
|> maybe_put_priority(opts[:priority])

Linear.create_issue(title, description, team.id, params)
end
end
Expand Down Expand Up @@ -115,4 +124,7 @@ defmodule LinearCli.CLI.Issue.Creation do

defp maybe_put_project_id(params, nil), do: params
defp maybe_put_project_id(params, project), do: Map.put(params, :project_id, project.id)

defp maybe_put_priority(params, nil), do: params
defp maybe_put_priority(params, priority), do: Map.put(params, :priority, priority)
end
37 changes: 37 additions & 0 deletions app/lib/linear_cli/cli/priority.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
defmodule LinearCli.CLI.Priority do
@moduledoc """
Shared priority name parser for `lc issue create` and `lc issue update`.

Maps the canonical, case-insensitive friendly names (`none`, `urgent`,
`high`, `medium`, `low`) to the integer values Linear's API expects
(0–4, matching `IssueCreateInput.priority` and `IssueUpdateInput.priority`).
"""

@priority_map %{
"none" => 0,
"urgent" => 1,
"high" => 2,
"medium" => 3,
"low" => 4
}

@valid_values Map.keys(@priority_map) |> Enum.sort()

@doc """
Parses a priority name string into a Linear priority integer.

Accepts `none`, `urgent`, `high`, `medium`, `low` (case-insensitive).
Returns `{:ok, integer}` on success or `{:error, message}` for unknown values.
"""
@spec parse(String.t()) :: {:ok, 0..4} | {:error, String.t()}
def parse(value) when is_binary(value) do
case Map.fetch(@priority_map, String.downcase(value)) do
{:ok, int} ->
{:ok, int}

:error ->
{:error,
"unknown priority #{inspect(value)}; must be one of: #{Enum.join(@valid_values, ", ")}"}
end
end
end
5 changes: 5 additions & 0 deletions app/lib/linear_cli/linear/issue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule LinearCli.Linear.Issue do
argument :team_id, :string, allow_nil?: false
argument :project_id, :string, allow_nil?: true
argument :label_ids, {:array, :string}, default: []
argument :priority, :integer, allow_nil?: true
manual LinearCli.Linear.Issue.Create
end

Expand Down Expand Up @@ -368,6 +369,7 @@ defmodule LinearCli.Linear.Issue.Create do
%{"title" => args.title, "description" => args.description, "teamId" => args.team_id}
|> maybe_put_label_ids(args.label_ids)
|> maybe_put_project_id(Map.get(args, :project_id))
|> maybe_put_priority(Map.get(args, :priority))

case Api.call(document(), %{"input" => input}) do
{:ok, %{"issueCreate" => %{"issue" => issue_map}}} when is_map(issue_map) ->
Expand All @@ -387,6 +389,9 @@ defmodule LinearCli.Linear.Issue.Create do
defp maybe_put_project_id(input, nil), do: input
defp maybe_put_project_id(input, project_id), do: Map.put(input, "projectId", project_id)

defp maybe_put_priority(input, nil), do: input
defp maybe_put_priority(input, priority), do: Map.put(input, "priority", priority)

# A function, not a module attribute: Issue.base_fields/0 reaches into
# User (another file), so it must be evaluated at call time - see house
# rule on cross-file compile-time module attribute evaluation order.
Expand Down
Loading