Exemple #1
0
    def post(self):
        json_data = request.get_json(force=True)

        # check if the input exists
        if not json_data:
            return {'message': 'No input data provided'}, 400

        # get the input
        project_name = json_data['project_name']
        repository_name = json_data['repository_name']
        url = json_data['url']

        # check if the project already exists
        result = Repositories.get_repositories(project_name, repository_name)
        if len(result) > 1:
            return {'message': 'Repository name already exists'}, 400

        # check if the project's url already exists
        result = Repositories.get_repositories_by_url(repository_name, url)
        if len(result) > 1:
            return {'message': 'Repository url already exists'}, 400

        # create the repository
        Repositories.new_repository(project_name=project_name,
                                    repository_name=repository_name,
                                    url=url)

        # get the new project to confirm that everything is OK
        result = Repositories.get_repositories(project_name, repository_name)

        result = json.dumps(result, indent=4, sort_keys=True, default=str)

        # return the new project to the client
        return {"status": 'success', 'data': result}, 201
Exemple #2
0
    def delete(self):
        args = request.args

        # check if the input exists
        if not args:
            return {'message': 'No input data provided'}, 400

        # get the input
        project_name = args['project_name']
        repository_name = args['repository_name']
        feature_name = args['feature_name']

        # check if the project exists
        result = Repositories.get_repositories(project_name, repository_name)
        if not result:
            return {'message': 'Repository name not exists'}, 400

        # check if the feature exists in this project
        result = Features.get_features(project_name, repository_name,
                                       feature_name)
        if not result:
            return {'message': 'Feature name not exists'}, 400

        # delete the feature
        Features.delete_feature(project_name, repository_name, feature_name)

        result = json.dumps(result, indent=4, sort_keys=True, default=str)
        # return to the client the deleted feature
        return {"status": 'success', 'data': result}, 201
Exemple #3
0
 def get(self):
     args = request.args
     if not args:
         return {'message': 'No input data provided'}, 400
     project_name = args['project_name']
     result = Repositories.get_repositories(project_name)
     result = json.dumps(result, indent=4, sort_keys=True, default=str)
     return {"data": result}, 201
Exemple #4
0
    def post(self):
        json_data = request.get_json(force=True)

        # check if the input exists
        if not json_data:
            return {'message': 'No input data provided'}, 400

        # get the input
        project_name = json_data['project_name']
        repository_name = json_data['repository_name']
        feature_name = json_data['feature_name']
        file_path = json_data['file_path']

        # check if the project exists
        result = Repositories.get_repositories(project_name, repository_name)
        if len(result) < 1:
            return {'message': 'Repository name not exists'}, 400

        # check if the file_name exists in the project

        file_path = file_path.replace('\\\\', '\\')
        file_path = file_path.replace(' ', '')
        result = Files.get_files(project_name=project_name,
                                 repository_name=repository_name,
                                 file_path=file_path)
        if not result:
            return {'message': 'File path not exists'}, 400

        # check if the feature_name exists in the project
        result = Features.get_features(project_name, repository_name,
                                       feature_name)
        if not result:
            return {'message': 'Feature name not exists'}, 400

        # check if the feature_name exists in the project
        result = Associations.get_associations(project_name, repository_name,
                                               file_path, feature_name)
        if result:
            return {'message': 'Association name already exists'}, 400

        # create the association
        Associations.new_association(project_name, repository_name, file_path,
                                     feature_name)

        # update the numbe of features associated to the file
        Files.update_file(project_name, repository_name, file_path)

        # # update the number of files associated to the feature
        Features.update_feature_files_associated(project_name, repository_name,
                                                 feature_name)

        # get the new association to confirm that everything is OK
        result = Associations.get_associations(project_name, repository_name,
                                               file_path, feature_name)

        result = json.dumps(result, indent=4, sort_keys=True, default=str)
        # return the new association to the client
        return {"status": 'success', 'data': result}, 201
Exemple #5
0
    def put(self):
        json_data = request.get_json(force=True)

        # check if the input exists
        if not json_data:
            return {'message': 'No input data provided'}, 400

        # get the input
        project_name = json_data['project_name']
        repository_name_old = json_data['repository_name_old']
        repository_name_new = json_data['repository_name_new']
        url_new = json_data['url_new']

        result = Repositories.get_repositories(project_name,
                                               repository_name_old)
        if len(result) < 1:
            return {'message': 'Repository name not exists'}, 400

        Repositories.edit_repositories(project_name=project_name,
                                       repository_name_old=repository_name_old,
                                       repository_name_new=repository_name_new,
                                       url_new=url_new)

        return {"status": 'success'}, 201
Exemple #6
0
    def delete(self):
        args = request.args

        # check if the input exists
        if not args:
            return {'message': 'No input data provided'}, 400

        # get the input
        project_name = args['project_name']
        repository_name = args['repository_name']
        feature_name = args['feature_name']
        file_path = args['file_path']

        # check if the project exists
        result = Repositories.get_repositories(project_name, repository_name)
        if not result:
            return {'message': 'Repository name not exists'}, 400

        file_path = file_path.replace('\\\\', '\\')
        file_path = file_path.replace(' ', '')

        result = Files.get_files(project_name=project_name,
                                 repository_name=repository_name,
                                 file_path=file_path)
        if not result:
            return {'message': 'File path not exists'}, 400

        # check if the association exists in this repository
        result = Associations.get_associations(project_name, repository_name,
                                               file_path, feature_name)
        if not result:
            return {'message': 'Association not exists'}, 400

        # delete the association
        Associations.delete_association(project_name, repository_name,
                                        file_path, feature_name)

        # update the numbe of features associated to the file
        Files.update_file(project_name, repository_name, file_path)

        # # update the number of files associated to the feature
        Features.update_feature_files_associated(project_name, repository_name,
                                                 feature_name)

        result = json.dumps(result, indent=4, sort_keys=True, default=str)
        # return to the client the deleted association
        return {"status": 'success', 'data': result}, 201
Exemple #7
0
    def post(self):
        json_data = request.get_json(force=True)

        # check if the input exists
        if not json_data:
            return {'message': 'No input data provided'}, 400

        # get the input
        project_name = json_data['project_name']
        repository_name = json_data['repository_name']
        feature_name = json_data['feature_name']
        number_bugs_string = json_data['number_bugs']
        number_bugs = int(number_bugs_string)

        # check if the project exists
        result = Repositories.get_repositories(project_name, repository_name)
        if not result:
            return {'message': 'Repository name not exists'}, 400

        # check if the feature already exists
        result = Features.get_features(project_name, repository_name,
                                       feature_name)
        if len(result) > 1:
            return {'message': 'Feature name already exists'}, 400

        # create the new feature
        Features.new_feature(project_name, repository_name, feature_name,
                             number_bugs)

        # get the new feature to confirm that everything is OK
        result = Features.get_features(project_name, repository_name,
                                       feature_name)

        result = json.dumps(result, indent=4, sort_keys=True, default=str)

        return {"status": 'success', 'data': result}, 201
Exemple #8
0
    def update_commits(project_name, repository_name):
        print("Commits.update_commits(" + project_name+ ", " + repository_name + ")")
        
        
        try:
            from modelsFolder.model_Repositories import Repositories
        except ImportError:
            print("Repositories are already imported")


        mydb = client[project_name]
        mycol = mydb[repository_name + '_commits']
        mycol_commit = mydb[repository_name + '_files_by_commit']

        url = Repositories.get_url(project_name, repository_name)

        days_retrieval = ModelSettings.get_days_retrieval(project_name)

        date = datetime.datetime.today() - datetime.timedelta(days=days_retrieval) 

        for commit in RepositoryMining(url, since=date).traverse_commits():
            _hash = commit.hash
            author = commit.author.name
            date = commit.author_date
            number_files = len(commit.modifications)
            message = commit.msg
            number_lines = 0

            result = mycol.find({"hash" : _hash})
            if not result.count():
                # Insert a new line in the commits table (with the info of the commit)
                mycol.insert_one({ "hash": _hash, "message": message, "author": author, "date": date, "number_files": number_files, "number_lines": number_lines })
                
                # Iterate the files of the commit
                for mod in commit.modifications:

            
                    file_extensions = ModelSettingsFiles.get_file_extensions(project_name)

                    for e in file_extensions:
                            if mod.filename.endswith(e):
                                if mod.new_path != '_None_':
                                    # Add a new line linking the file with the commit
                                    mycol_commit.insert_one({ "file_name": mod.filename, "file_path" : mod.new_path, "hash": _hash, "number_lines": mod.added + mod.removed })
            

                    
                    # The number of files modifieds in this commit
                    number_lines = number_lines + mod.added + mod.removed
                    # Create the file in the table File (if already exists, the Files.new_file treats)
                    Files.new_file( 
                        project_name = project_name,
                        repository_name = repository_name, 
                        file_name = mod.filename, 
                        file_path = mod.new_path,
                        last_modification = date
                    )

                # Create the Author in the table author (if already exists, the Authors.new_author treats)
                Authors.new_author( 
                    project_name = project_name, 
                    repository_name = repository_name,
                    author_name = author, 
                    number_lines = number_lines,
                    last_modification = date
                    )