Ejemplo 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)
Ejemplo 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
Ejemplo n.º 3
0
 def test_previousItemsTableReminder(self):
     """Test that previous items table works correctly with reminders."""
     # create the reminder
     uuidstr = '00001111000011110000111100001111'
     id = str(uuid.UUID(uuidstr))
     reminder = WorkLogReminder(reminder_id=id, user=self.user, date=self.last_week)
     reminder.save()
     
     # create some work log entries
     job1 = Job.objects.get(name="Job_LastWeek")
     item1= WorkItem(user=self.user, date=self.last_week, hours=3, 
                     text='Should be visible in table.', job=job1)
     job2 = Job.objects.get(name="Job_Today")
     item2 = WorkItem(user=self.user, date=self.today, hours=5, 
                     text='Should not be visible in table.', job=job2)
     item1.save()
     item2.save()
     
     with self.scoped_login(username='******', password='******'):
         response = self.client.get('/worklog/add/reminder_{0}/'.format(id))
         
         self.assertEquals(response.context['reminder_id'],id)
         
         self.assertEquals(len(response.context['items']),1)
         items = response.context['items']
         
         # order of columns depends on configuration, so just check that they exist
         self.assertTrue(job1 in items[0])        
         self.assertTrue(self.user in items[0])  
         self.assertTrue(3 in items[0])   
Ejemplo n.º 4
0
 def test_previousItemsTable(self):
     job = Job.objects.filter(name="Job_Today")[0]
     item = WorkItem(user=self.user, date=self.today, hours=3, 
                     text='My work today.', job=job)
     item.save()
     
     with self.scoped_login('master', 'password'):
         response = self.client.get('/worklog/add/')
         self.assertEquals(response.context['reminder_id'],None)
         
         self.assertEquals(len(response.context['items']),1)
         items = response.context['items']
         
         # order of columns depends on configuration, so just check that they exist
         self.assertTrue(job in items[0])        
         self.assertTrue(self.user in items[0])  
         self.assertTrue(3 in items[0])        
Ejemplo n.º 5
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