Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort issues hierarchically #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
60 changes: 51 additions & 9 deletions jipdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,37 @@ def write_last_jira_comment(f, jira, issue):
except UnicodeEncodeError:
vprint("Can't encode character")

def write_one_issue(jira_issues, f, issue):
global g_args
last_comment = g_args.l

if issue not in jira_issues:
# Add parent as a comment
f.write("#[%s] is parent of next issue\n" % issue)
f.write("#parent of next issues\n" % issue)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is wrong and gives Python errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, a last minute changes with a wrong copy/paste to try to make comment more readable.
Will fix it

return

if "done" in jira_issues[issue]:
return

if "parent" in jira_issues[issue]:
write_one_issue(jira_issues, f, jira_issues[issue]["parent"])

if "done" in jira_issues[issue]:
return

# Write issue comments
f.write("%s" % jira_issues[issue]["comments"])
f.write(get_extra_comments())
if last_comment:
write_last_jira_comment(f, jira, issue)
f.write("\n")

jira_issues[issue]["done"] = "done"

for child_issue in jira_issues:
if "parent" in jira_issues[child_issue] and issue == jira_issues[child_issue]["parent"]:
write_one_issue(jira_issues, f, child_issue)

def get_jira_issues(jira, username):
"""
Expand All @@ -192,7 +223,6 @@ def get_jira_issues(jira, username):
all_status = g_args.all
filename = g_args.file
user = g_args.user
last_comment = g_args.l

issue_types = ["Epic"]
if not epics_only:
Expand Down Expand Up @@ -229,16 +259,28 @@ def get_jira_issues(jira, username):

f.write(msg)
vprint("Found issue:")

unsorted_issues={}
for issue in my_issues:
issue_id = "%s" % issue
this_issue = {}

this_issue["comments"] = ""
vprint("%s : %s" % (issue, issue.fields.summary))
f.write("[%s]\n" % issue)
f.write("# Header: %s\n" % issue.fields.summary)
f.write("# Type: %s\n" % issue.fields.issuetype)
f.write("# Status: %s\n" % issue.fields.status)
f.write(get_extra_comments())
if last_comment:
write_last_jira_comment(f, jira, issue)
f.write("\n")
this_issue["comments"] += "[%s]\n" % issue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep all the writes here as done previously and then follow the same pattern as I did withwrite_last_jira_comment, but instead of an argument, add it as a configuration option in the yaml file? I.e, in the yaml-file:

show_parent: True

And then here (just after line 237, # Status ...) add:

    try:                                                                                      
        if g_yml_config['show_parent']:
             f.write(write_parent(jira, issue))
    except:                                                                                   
        vprint("Parent not found in config")

That means that the parent link also would need to go below the issue ID itself (and not before as in your patch), for example:

[SWG-3]
# Header: Generic TrustZone device driver for Linux kernel (upstream)
# Type: Epic
# Status: In Progress
# Parent: SWG-1
# No updates since last week.

I think that would make it a bit cleaner and will give people the option to enable/disable parent links at will. Seems like people have lots of different opinions on what should be there by default and how that should look like. In that case it it probably best to make it configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My goal was to keep a kind of hierarchy
[parent1]
[child11]
[child12]
[parent2]
[child21]
[child22]

But when a parent (parent2) is not in the list of issues to update we have
[parent1]
[child11]
[child12]
[child21]
[child22]

Which can be a bit confusing so my goal was to add a comment when we change the parent
[parent1]
[child11]
[child12]
#[parent2]
[child21]
[child22]

Furthermore, this can be easily used to add a summary of childs activities into the parent by uncommenting the issue id

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that's a bit different to how I first understood that it was supposed to be used. I was thinking it was just going to add a parent link to each issue. Let me think a bit more about this.

Copy link
Collaborator

@jbech-linaro jbech-linaro May 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I've looked into this, currently you are checking for parents and then parse issues one by one and then mark them as done etc. How about instead adding all issues to a dictionary where the key is simply the parent. By doing so you can easily sort on the key (parent) if you want to and as a inner loop you print each issue belonging to that key/parent. That would give what you are asking for, but I think it's a bit easier to implement and read. If you want I can make a patch for it.

Btw,

#[parent2]
[child21]
[child22]

How do you figure out that it should be "parent2" if there is no parent? Or are you just grabbing a name?

Copy link
Collaborator

@jbech-linaro jbech-linaro May 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, some more thinking about this, it can be pretty complicated. What you want to achieve I guess is:

[Initiative1]
  [Epic1]
  [Epic2]

or

[Epic1]
  [Story1]
  [Story2]

or

[Initiative1]
  [Epic1]
    [Story1]
    [Story2]
  [Epic2]
    Story3]
    [Story4]

I.e, you want to show the tree. However, there are no limitations to how many parents you can have. One Epic can implement several Initiatives, likewise a Story can implement many Epics (this is not the normal case, but it can happen). So let's say an Epic implements two Initiatives, how should that be represented in text format?

[Initiative1, Initiative2]
  [Epic1]
    [Story1]
    [Story2]

[Initiative1]
  [Epic2]
    [Story3]
    [Story4]

Take it one more level, let's say Story1 implements Epic1 and Epic2, then things are becoming pretty complicated when it comes to how to represent it :)

Just putting Stories in a group linking to a single Epic is easy, so is grouping Epics pointing to a single Initiative. But that will not cover the corner cases.

this_issue["comments"] += "# Header: %s\n" % issue.fields.summary
this_issue["comments"] += "# Type: %s\n" % issue.fields.issuetype
this_issue["comments"] += "# Status: %s\n" % issue.fields.status

for link in issue.fields.issuelinks:
if "outwardIssue" in link.raw:
parent = link.outwardIssue.key
this_issue["parent"] = link.outwardIssue.key

unsorted_issues[issue_id] = this_issue

for issue in unsorted_issues:
write_one_issue(unsorted_issues, f, issue)

f.close()
return filename
Expand Down