简体   繁体   English

遍历图(查找链接的所有问题)

[英]python - traverse a graph (find all issues linked)

I'm bit stuck trying to solve a simple task of getting all linked issues. 我有点想解决一个简单的任务,即获取所有链接的问题。 This is basically a graph task I guess - I take a jira issue, find all its links and then go to linked issues for their links until I've processed all issues. 我猜这基本上是一个图形任务-我处理一个jira问题,找到其所有链接,然后转到链接的问题以获取其链接,直到我处理完所有问题为止。

The layout of jira isues I'm testing this with is as on the picture below: 我正在测试的jira isues的布局如下图所示: 在此处输入图片说明

But the result is this: 但是结果是这样的:

PMO-100 -> SA-300
SA-100 -> SA-300
SA-100 -> SA-200

It is missing one link but it would miss a whole lot more because it only processes the first link from all found ones: 它丢失了一个链接,但是会丢失更多,因为它仅处理所有找到的链接中的第一个链接:

__init__       6996   Starting...
_new_conn      6996   Starting new HTTP connection (1): 10.48.34.174
collect_links  6996   Looking for links for issue PMO-100
collect_links  6996   Found 2 links: 27846, 27843
collect_links  6996   processing link 27846
put_link       6996   Appending link 27846 to link register
collect_links  6996   Looking for links for issue SA-300
collect_links  6996   Found 2 links: 27845, 27846
collect_links  6996   processing link 27845
put_link       6996   Appending link 27845 to link register
collect_links  6996   Looking for links for issue SA-100
collect_links  6996   Found 3 links: 27844, 27845, 27843
collect_links  6996   processing link 27844
put_link       6996   Appending link 27844 to link register
collect_links  6996   Looking for links for issue SA-200
collect_links  6996   Found 1 links: 27844
collect_links  6996   processing link 27844
put_link       6996   Link 27844 already exists in link register
collect_links  6996   issue SA-100 is already in tracked issues

This is happening because of the for ... each loop inside the collect_links method - whenever it's called it will override the for ... each collection: 发生这种情况的原因是collect_links方法内的for ... each循环-每当调用它时,它将覆盖for ... each集合:

def collect_links(self, key):
        logging.info('Looking for links for issue %s' % key)
        self.tracked.append(key)
        links = self.jac.issue(key).fields.issuelinks
        logging.info('Found %s links: %s' % (len(links), ', '.join(i.id for i in links)))
        for link in links:
            logging.info('processing link %s' % link.id)
            self.put_link(link)
            rel = None
            if hasattr(link, 'outwardIssue'):
                rel = link.outwardIssue.key
            else:
                rel = link.inwardIssue.key
            linked_issue = self.jac.issue(rel)
            if linked_issue.key not in self.tracked:
                return self.collect_links(linked_issue.key)
            else:
                logging.info('issue %s is already in tracked issues' % linked_issue.key)

It looks like when you call self.method from within the method itself, it will not create a new chunk of data for it but rather override the data you've already created inside the method - how do I overcome that? 看起来当您从方法本身内部调用self.method时,它不会为其创建新的数据块,而是覆盖您已经在方法内部创建的数据-我该如何克服呢?

What happens is: 发生的是:

for link in links: #links contains the links linked to current issue
    if linked_issue.key not in self.tracked:
        return self.collect_links(linked_issue.key) #links changes

on the last line I would expect it keeps my links collection untouched but it changes it to be a links collection for linked_issue.key 在最后一行,我希望它使我的链接集合保持不变,但是它将其更改为linked_issue.key的链接集合

I've pasted the whole code on pastebin . 我已将整个代码粘贴到pastebin上

Uh, unsure I understand your problem, but in case I do: un,不确定我能理解您的问题,但万一我做到了:

for link in links: #links contains the links linked to current issue
    if linked_issue.key not in self.tracked:
        return self.collect_links(linked_issue.key) #links changes

This will of course stop the for loop at the first untracked link. 当然,这将在第一个未跟踪的链接处停止for循环。 If you want to continue iterating through the remaining elements of links , you must not use a return statement here. 如果要继续遍历links的其余元素,则不能在此处使用return语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM