Skip to content

Instantly share code, notes, and snippets.

@vanhoof
Last active July 14, 2025 18:44
Show Gist options
  • Save vanhoof/5bf3e6f209f79d850cfbd493d3ac41a4 to your computer and use it in GitHub Desktop.
Save vanhoof/5bf3e6f209f79d850cfbd493d3ac41a4 to your computer and use it in GitHub Desktop.
set-field on issue create testing
diff --git a/jcli/connector.py b/jcli/connector.py
index 2898b87..3d7e9b5 100644
--- a/jcli/connector.py
+++ b/jcli/connector.py
@@ -687,10 +687,15 @@ class JiraConnector(object):
def _convert_to_field_type(self, field_id, field_value):
"""Convert the field value to the appropriate type."""
+ # Handle built-in fields first
+ if field_id == "priority":
+ # Priority field needs to be an object with name property
+ return {"name": field_value}
+
field_type = self._fetch_field_type_mapping().get(field_id)
if field_type is None:
raise ValueError(f"Field type for field with ID '{field_id}' not found.")
-
+
if field_type == "string":
return field_value
elif field_type == "user":
diff --git a/jcli/issues.py b/jcli/issues.py
index b36f693..05756e3 100644
--- a/jcli/issues.py
+++ b/jcli/issues.py
@@ -908,11 +908,13 @@ def create_issue_cmd(ctx, summary, description, project, issue_type, set_field,
f = '"' + f + '"'
fields[f] = "value"
- for f in set_field:
- field = f[0]
- if not field.startswith('"'):
- field = '"' + f[0] + '"'
- special_lines += f"# set-field: {field} {f[1]}\n"
+ # Only add command line fields to template if not filled_all (i.e., using editor)
+ if not filled_all:
+ for f in set_field:
+ field = f[0]
+ if not field.startswith('"'):
+ field = '"' + f[0] + '"'
+ special_lines += f"# set-field: {field} {f[1]}\n"
for k, v in fields.items():
special_lines += f"## set-field: {k} {v}\n"
@@ -934,9 +936,19 @@ def create_issue_cmd(ctx, summary, description, project, issue_type, set_field,
issue["summary"], issue["description"], comments = issue_extract_blocks(issue_patch)
+ # First process command line --set-field arguments
+ for f in set_field:
+ field_name = f[0]
+ field_value = f[1]
+ field_name = jobj._try_fieldname(field_name)
+ field_value = jobj.convert_to_field_type(field_name, field_value)
+ issue[field_name] = field_value
+
+ # Then process template directives
for c in comments:
if c.startswith("# set-field:"):
- m = re.match(r'# set-field:\s*(--forced\s+)"(.*)" (.*)', c)
+ # Handle both --forced and regular syntax
+ m = re.match(r'# set-field:\s*(--forced\s+)?"(.*?)"\s+(\S+)', c)
if m:
forced, f, v = m.groups()
f = jobj._try_fieldname(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment