Esempio n. 1
0
    def link_work_items(self, pull_request, raw, graph):
        """
        if a pull request has links, this will crawl the links and link the work items.
        If the work item does not exist a new one will be created and hopefully added.
        """
        real_url = raw.get("url")
        data = self.vsts.make_request(real_url)

        links = data.get("_links")
        if links is None:
            print("Could not find links")
            return
        work_items_url = links.get("workItems")
        if work_items_url is None:
            print("no work items")
            return
        href = work_items_url.get("href")
        if href is None:
            print("no href found for " + str(pull_request.Id))
        work_item_links = self.vsts.make_request(href)
        for wi_link in work_item_links.get("value"):
            work_item_id = wi_link.get("id")
            work_item = WorkItem.select(graph, work_item_id).first()
            if work_item is None:
                work_item = WorkItem()
                work_item.Id = work_item_id
                graph.create(work_item)
                print("new work item added " + str(work_item.Id))
            work_item.LinkedTo.add(pull_request)
            graph.push(work_item)
Esempio n. 2
0
 def make_work_item(self, raw):
     """
     create new
     """
     work_item = WorkItem()
     work_item.Id = raw.get("id")
     work_item.Url = raw.get("url")
     return work_item
Esempio n. 3
0
    def get_work_item(self, work_item_id, graph):
        """
        Updates workitem data regardless now
        :param string work_item_id:

        """
        if work_item_id is None:
            print("workitem id cannot be none")
            return
        work_item = WorkItem.select(graph, work_item_id).first()
        if work_item is None:
            work_item = WorkItem()
            work_item.Id = str(work_item_id)
            graph.merge(work_item)
        try:
            self.vsts_work_item_repo.fill_in_the_rest(work_item, graph)
        except:
            #Not sure why this happens could be old work items or possibly artifact links
            print("could not get work item from vsts: " + str(work_item.Id))

        graph.push(work_item)
        return work_item