ankitpokhrel / jira-cli

🔥 Feature-rich interactive Jira command line.
MIT License
3.9k stars 197 forks source link

unable to set parent field #738

Closed electriquo closed 1 month ago

electriquo commented 5 months ago

Describe the bug

Creating an issue with parent field or parameter does not work.

$ cat "$file" | jira issue create --type ISSUE --parent $parent --assignee $user --custom parent=$parent --summary "$summary"
✓ Issue created
https://company.atlassian.net/browse/ISSUE-12346

Browsing the issue in the browser, I see that it does not have the parent field. So I tried to analyze the fields of the created issue using the API and as you can see, the parent field was not set.

$ curl -Ls --user "${user}:${token}" https://company.atlassian.net/rest/api/2/issue/ISSUE-12346 | jq -r '.fields.parent'
null

I repeat the analysis on an issue with the parent field set correctly

$ curl -Ls --user "${user}:${token}" https://company.atlassian.net/rest/api/2/issue/ISSUE-12344 | jq -r '.fields.parent'
{
  "id": "119126",
  "key": "ISSUE-12345",
  "self": "https://company.atlassian.net/rest/api/2/issue/119126",
  "fields": {
    "summary": "...",
    "status": {
      "self": "https://company.atlassian.net/rest/api/2/status/10003",
      "description": "...",
      "iconUrl": "https://company.atlassian.net/images/icons/subtask.gif",
      "name": "...",
      "id": "10003",
      "statusCategory": {
        "self": "https://company.atlassian.net/rest/api/2/statuscategory/2",
        "id": 2,
        "key": "new",
        "colorName": "...",
        "name": "To Do"
      }
    },
    "priority": {
      "self": "https://company.atlassian.net/rest/api/2/priority/4",
      "iconUrl": "https://company.atlassian.net/images/icons/priorities/minor.svg",
      "name": "...",
      "id": "1"
    },
    "issuetype": {
      "self": "https://company.atlassian.net/rest/api/2/issuetype/10000",
      "id": "10000",
      "description": "...",
      "iconUrl": "https://company.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10307?size=medium",
      "name": "Epic",
      "subtask": false,
      "avatarId": 10307,
      "hierarchyLevel": 1
    }
  }
}

Clearly, that in the browser I did not set all these values for the parent field. The parent field is a select box to pin an issue that is the parent (some call this an epic), such as selecting ISSUE-12345 (see the screenshot below).

Then I tried to look for the custom field in the CLI configuration

$ dasel -f "${HOME}/.config/.jira/.config.yml" '.issue.fields.custom' | grep -i parent -A 3
- name: Parent Link
  key: customfield_12700
  schema:
    datatype: any

So I tried setting this custom field by editing the issue, but got an error

$ jira issue edit ISSUE-12346 --custom parent-link=ISSUE-12345
? Summary Summary
? Description <Received>
? What's next? Submit

Error:
  - Given parent issue does not belong to appropriate hierarchy.

jira: Received unexpected response '400 Bad Request'.
Please check the parameters you supplied and try again.

Both the parent and the parent-link fields does not apply for the ticket even when the --parent option was used. How can I set the parent field to value such as ISSUE-12345 using the CLI? How do I find the parent field type (maybe it has to do something with the configuration, see Caveats at the Additional context below)

Please provide following details

  1. JiraCLI Version:
    (Version="1.5.1", GitCommit="0e0f82d52ef5a775d2cc662fbe38d9732b9b5c59", CommitDate="2024-01-20T10:48:06+00:00", GoVersion="go1.21.5", Compiler="gc", Platform="darwin/arm64")
  2. Are you using Jira cloud or on-premise jira server?

    SERVER INFO
    -----------
    
    Version:         1001.0.0-SNAPSHOT
    Build Number:    100252
    Deployment Type: Cloud
    Default Locale:  en_US
  3. What operating system are you using? Also mention version.
    ProductName:        macOS
    ProductVersion:     14.4.1
    BuildVersion:       23E224
  4. What terminal are you using? Also mention version.
    iTerm 2 Build 3.4.23

To Reproduce

See description.

Expected behavior

The parent field to be set and once set, it must be listed in jira epic list <parent issue number>.

Screenshots

This how the parent field look in the browser 2024-05-01_17-27

Additional context

SleepyBrett commented 3 months ago

I'm seeing a similar problem. Except when I try and set the parent I end up with an error - customfield_10014: Field 'customfield_10014' cannot be set. It is not on the appropriate screen, or unknown. which is the custom field for epic.link

epic:
    name: customfield_10011
    link: customfield_10014
electriquo commented 3 months ago

Maybe @ankitpokhrel has any lead

jcstorino commented 3 months ago

@electriquo @SleepyBrett
Try change Project/Type in config.yml to "next-gen", then the parent is send as field/key struct Instead of Epic custom Field.

electriquo commented 3 months ago

@jcstorino Although I tried, I couldn't understand what did you mean. Could you please share a concrete example?

jcstorino commented 3 months ago

@electriquo

Sure... When you configure jiracli with the init option, a file called config.yml is created in your user folder, to see exact location, type jiracli without parameters and look to -c Flags comment, ex

FLAGS
  -c, --config string    Config file (default is /Users/jcstorino/.config/.jira/.config.yml)

Open this file and look for the project key, below must exist another key with name "type", change its value to "next-gen" and test again the creation of an issue with the --parent option. It worked for me.

project:
    key: TDC
    type: next-gen
electriquo commented 3 months ago

@jcstorino Thanks. Change from

project:
    key: TDC
    type: classic

to

project:
    key: TDC
    type: next-gen

Will try it later on this week and let your know.

electriquo commented 2 months ago

@jcstorino Works like a charm :)

How did you know that this is what's need to be changed?

jcstorino commented 2 months ago

@electriquo I forked the repository and have been studying Go in my free time, I like and use this client a lot, so I started studying the sources and found this trick. Glad it worked !

electriquo commented 2 months ago

@jcstorino Many could benefit from your findings. I think you should contribute this to the documentation since the parent field became fundamental for managed projects.

I'll keep this issue open, if you decide to open a PR (so you could link between the two) that will close this issue. Otherwise, let me know and I will close the PR immediately.

electriquo commented 2 months ago

Hi @jcstorino, any update?

jcstorino commented 2 months ago

@electriquo Maybe change the default value in the client configuration? Since this is not asked in the tool config ... I'll try to do that

electriquo commented 1 month ago

Hi @jcstorino, any progress or should I close the issue?

jcstorino commented 1 month ago

@electriquo Yes, you can close it, I will contribute to the documentation later. Right now I have little time to prepare it.