Example #1
0
    def test_clone(self):
        with tempfile.TemporaryDirectory() as directory:
            # Arrange
            owner = 'andymeneely'
            name = 'squib'
            date = '2015-03-31 19:24:28'

            repository_root = directory
            repository_home = os.path.join(repository_root, '10868464')
            os.mkdir(repository_home)
            expected = {
                'sha': '784a0dcb90e798859ab24b69d4b8c12c200ed85d',
                'repository_path': os.path.join(repository_home, 'squib')
            }

            # Act
            actual = dict()
            actual['repository_path'] = utilities.clone(
                owner, name, repository_home, date)

            # Assert
            self.assertTrue(len(os.listdir(directory)) > 0)
            process = subprocess.Popen('git log -1 --pretty="format:%H"',
                                       cwd=actual['repository_path'],
                                       shell=True,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
            (out, err) = [i.decode() for i in process.communicate()]
            actual['sha'] = out
            self.assertEqual(expected, actual)
Example #2
0
    def test_clone(self):
        with tempfile.TemporaryDirectory() as directory:
            # Arrange
            owner = 'andymeneely'
            name = 'squib'
            date = '2015-03-31 19:24:28'

            repository_root = directory
            repository_home = os.path.join(repository_root, '10868464')
            os.mkdir(repository_home)
            expected = {
                'sha': '784a0dcb90e798859ab24b69d4b8c12c200ed85d',
                'repository_path': os.path.join(repository_home, 'squib')
                }

            # Act
            actual = dict()
            actual['repository_path'] = utilities.clone(
                owner, name, repository_home, date
            )

            # Assert
            self.assertTrue(len(os.listdir(directory)) > 0)
            process = subprocess.Popen(
                'git log -1 --pretty="format:%H"',
                cwd=actual['repository_path'], shell=True,
                stdout=subprocess.PIPE, stderr=subprocess.PIPE
            )
            (out, err) = [i.decode() for i in process.communicate()]
            actual['sha'] = out
            self.assertEqual(expected, actual)
Example #3
0
    def _init_repository(self, project_id, repository_home):
        repository_path = repository_home  # Default

        if not os.path.exists(repository_path):
            os.mkdir(repository_path)

        items = os.listdir(repository_path)
        if items:
            for item in os.listdir(repository_path):
                itempath = os.path.join(repository_path, item)
                if os.path.isdir(itempath):
                    repository_path = itempath
                    break
        else:
            fp = open('u' + str(project_id), 'r')
            for x in fp:
                url = x.replace("\n",
                                "").replace("https://api.github.com/repos/",
                                            "").split("/")
                break
            fp.close()
            (repo_owner, repo_name) = (url[0], url[1])
            if not (repo_owner or repo_name):
                raise ValueError('Invalid project ID {0}.'.format(project_id))

            last_commit_date = getLastCommitDate(project_id)
            if last_commit_date is None:
                last_commit_date = self.today

            repository_path = utilities.clone(repo_owner, repo_name,
                                              repository_path,
                                              last_commit_date)

        return repository_path
    def _init_repository(self, project_id, repository_home):
        repository_path = repository_home  # Default

        if not os.path.exists(repository_path):
            os.mkdir(repository_path)

        items = os.listdir(repository_path)
        if items:
            for item in os.listdir(repository_path):
                itempath = os.path.join(repository_path, item)
                if os.path.isdir(itempath):
                    repository_path = itempath
                    break
        else:
            url = self.database.get('''
                    SELECT url FROM projects WHERE id={0}
                '''.format(project_id)).replace(
                "https://api.github.com/repos/", "").split("/")
            (repo_owner, repo_name) = (url[0], url[1])
            if not (repo_owner or repo_name):
                raise ValueError('Invalid project ID {0}.'.format(project_id))
            get_url = self.database.get('''
                    SELECT url FROM projects WHERE id={0}
                '''.format(project_id)) + "/commits"
            try:
                print(self.tokens)
            except:
                print('')
            token_avail = False
            for token in self.tokens:
                if (token_avail == True):
                    break
                else:
                    try:
                        last_commit_date = utilities.url_to_json(
                            get_url,
                            [self.tokens[token], token
                             ])[0]["commit"]["committer"]["date"].split("T")[0]
                        token_avail = True
                    except:
                        continue
            if (token_avail == False):
                try:
                    print(
                        "[Reg: Last_Commit_Date]Couldn't fetch data from API! Trying out without token.."
                    )
                    last_commit_date = utilities.url_to_json(get_url)[0][
                        "commit"]["committer"]["date"].split("T")[0]
                    print('Fetch Successful')
                except Exception as ex:
                    print(ex)
                    last_commit_date = None
            if last_commit_date is None:
                last_commit_date = self.today
            repository_path = utilities.clone(repo_owner, repo_name,
                                              repository_path,
                                              last_commit_date)

        return repository_path
Example #5
0
    def _init_repository(self, project_id, repository_home):
        repository_path = repository_home  # Default

        if not os.path.exists(repository_path):
            os.mkdir(repository_path)

        items = os.listdir(repository_path)
        if items:
            for item in os.listdir(repository_path):
                itempath = os.path.join(repository_path, item)
                if os.path.isdir(itempath):
                    repository_path = itempath
                    break
        else:
            cursor = ghtorrentDb.cursor()
            cursor.execute(
                "SELECT url FROM projects WHERE id={0}".format(project_id))
            url = cursor.fetchone()[0].replace("https://api.github.com/repos/",
                                               "").split("/")
            (repo_owner, repo_name) = (url[0], url[1])
            # self.database.get(
            #     '''
            #         SELECT u.login, p.name
            #         FROM projects p
            #             JOIN users u ON u.id = p.owner_id
            #         WHERE p.id = {0}
            #     '''.format(project_id)
            # )
            if not (repo_owner or repo_name):
                raise ValueError('Invalid project ID {0}.'.format(project_id))

            last_commit_date = getLastCommitDate(project_id)
            # last_commit_date = self.database.get(
            #     '''
            #         SELECT DATE(c.created_at)
            #         FROM project_commits pc
            #             JOIN commits c ON c.id = pc.commit_id
            #         WHERE pc.project_id = {0}
            #         ORDER BY c.created_at DESC
            #         LIMIT 1
            #     '''.format(project_id)
            # )

            if last_commit_date is None:
                last_commit_date = self.today

            repository_path = utilities.clone(repo_owner, repo_name,
                                              repository_path,
                                              last_commit_date)

        return repository_path
Example #6
0
    def _init_repository(self, project_id, repository_home):
        repository_path = repository_home  # Default

        if not os.path.exists(repository_path):
            os.mkdir(repository_path)

        items = os.listdir(repository_path)
        if items:
            for item in os.listdir(repository_path):
                itempath = os.path.join(repository_path, item)
                if os.path.isdir(itempath):
                    repository_path = itempath
                    break
        else:
            (repo_owner, repo_name) = self.database.get(
                '''
                    SELECT u.login, p.name
                    FROM projects p
                        JOIN users u ON u.id = p.owner_id
                    WHERE p.id = {0}
                '''.format(project_id)
            )
            if not (repo_owner or repo_name):
                raise ValueError('Invalid project ID {0}.'.format(project_id))

            last_commit_date = self.database.get(
                '''
                    SELECT DATE(c.created_at)
                    FROM project_commits pc
                        JOIN commits c ON c.id = pc.commit_id
                    WHERE pc.project_id = {0}
                    ORDER BY c.created_at DESC
                    LIMIT 1
                '''.format(project_id)
            )

            if last_commit_date is None:
                last_commit_date = self.today

            repository_path = utilities.clone(
                repo_owner, repo_name, repository_path, last_commit_date
            )

        return repository_path
Example #7
0
    def _init_repository(self, project_id, repository_home):
        repository_path = repository_home  # Default

        if not os.path.exists(repository_path):
            os.mkdir(repository_path)

        items = os.listdir(repository_path)
        if items:
            for item in os.listdir(repository_path):
                itempath = os.path.join(repository_path, item)
                if os.path.isdir(itempath):
                    repository_path = itempath
                    break
        else:
            (repo_owner, repo_name) = self.database.get(
                '''
                    SELECT u.login, p.name
                    FROM projects p
                        JOIN users u ON u.id = p.owner_id
                    WHERE p.id = {0}
                '''.format(project_id)
            )
            if not (repo_owner or repo_name):
                raise ValueError('Invalid project ID {0}.'.format(project_id))

            last_commit_date = self.database.get(
                '''
                    SELECT DATE(c.created_at)
                    FROM project_commits pc
                        JOIN commits c ON c.id = pc.commit_id
                    WHERE pc.project_id = {0}
                    ORDER BY c.created_at DESC
                    LIMIT 1
                '''.format(project_id)
            )

            if last_commit_date is None:
                last_commit_date = self.today

            repository_path = utilities.clone(
                repo_owner, repo_name, repository_path, last_commit_date
            )

        return repository_path