예제 #1
0
 def map_and_save_project(self, raw_data, graph):
     """
     :param json raw_data:
         raw vsts project data
     :param Graph graph:
         py2neo graph
     """
     if raw_data["name"] in self.project_whitelist:
         proj = Project()
         proj.Id = raw_data.get("id")
         proj.Name = raw_data.get("name")
         #proj.Description = item["description"]
         proj.Revision = raw_data.get("revision")
         print("Adding Project")
         graph.create(proj)
         return proj
예제 #2
0
    def crawl(self, project_name):
        """
        Gets Repositories for a given project
        """
        url = (
            "%s/DefaultCollection/%s/_apis/git/repositories?api-version=%s" %
            (self.instance, project_name, self.api_version))
        data = self.vsts.make_request(url)

        for r in data["value"]:
            graph = GraphBuilder().GetNewGraph()
            #print(r["id"])
            repo = Repository()
            repo.Id = r.get("id")
            repo.Name = r.get("name")
            repo.Url = r.get("url")

            raw_proj = r.get("project")
            proj = Project()
            proj.Id = raw_proj.get("id")
            proj.Name = raw_proj.get("name")
            proj.Url = raw_proj.get("url")

            repo_proj = Project.select(graph, proj.Id)
            '''todo: may not need to do this.'''
            if repo_proj is not None:
                proj_tx = graph.begin()
                proj_tx.create(proj)
                proj_tx.commit()

            repo.BelongsTo.add(proj)
            print("Adding Repo: ")
            print(repo.Name)
            transaction = graph.begin()
            transaction.merge(repo)
            transaction.graph.push(repo)
        print("Finished mapping repos")