jira-terminal
jira-terminal copied to clipboard
`update` field does not work on `option` fields
Hi there, small problem I've found here. Everything else seems to be working great!
# This works:
$ jira-terminal update -f priority -v 'High' TICKET
Successfully Updated
# This says it works, but it doesn't actually update the API
$ jira-terminal update -f customfield_xxx -v 'somevalue' TICKET
Successfully Updated
~~The api docs seem to indicate different handling for custom fields.~~
In particular I have been testing with a field with this schema:
"customfield_10768": {
"required": false,
"schema": {
"type": "option",
"custom": "com.atlassian.jira.plugin.system.customfieldtypes:select",
"customId": 10768
},
"name": "Risk Level",
"key": "customfield_10768",
"operations": [
"set"
],
"allowedValues": [
{
"self": "https://xxx.atlassian.net/rest/api/2/customFieldOption/10656",
"value": "N/A",
"id": "10656"
},
{
"self": "https://xxx.atlassian.net/rest/api/2/customFieldOption/10445",
"value": "Low",
"id": "10445"
},
{
"self": "https://xxx.atlassian.net/rest/api/2/customFieldOption/10446",
"value": "Medium",
"id": "10446"
},
{
"self": "https://xxx.atlassian.net/rest/api/2/customFieldOption/10447",
"value": "High",
"id": "10447"
}
]
},
which should come back like this from jira-terminal detail when it is set:
"customfield_10768": {
"self": "https://xxx.atlassian.net/rest/api/2/customFieldOption/10446",
"value": "Medium",
"id": "10446"
},
maybe update.rs needs to handle option type in https://github.com/amritghimire/jira-terminal/blob/main/src/jira/update.rs#L53-L74 ?
The following diff inside update.rs fixes the issue, would you be interested in a PR? EDIT: https://github.com/amritghimire/jira-terminal/pull/36
diff --git a/src/jira/update.rs b/src/jira/update.rs
index 9b7edff..e25a80b 100644
--- a/src/jira/update.rs
+++ b/src/jira/update.rs
@@ -54,6 +58,9 @@ pub fn update_jira_ticket(ticket: String, key: String, entry: String) {
if fields["schema"]["type"] == "array" {
let update_json_value = get_object_lists_from_value(&fields["allowedValues"], value);
update_json[update_key] = update_json_value.into();
+ } else if fields["schema"]["type"] == "option" {
+ let custom = json::object! {"value": value };
+ update_json[update_key] = custom.into();
} else {
let update_json_value = get_object_by_name(&fields["allowedValues"], value);
update_json[update_key] = update_json_value.into();
}