コード例 #1
0
    def test_setup_cmd_parser(self):
        """Test if it parser object is correctly initialized"""

        parser = GitCommand.setup_cmd_parser()
        self.assertIsInstance(parser, BackendCommandArgumentParser)

        args = ['http://example.com/',
                '--git-log', 'data/git/git_log.txt',
                '--tag', 'test',
                '--from-date', '1970-01-01']

        parsed_args = parser.parse(*args)
        self.assertEqual(parsed_args.uri, 'http://example.com/')
        self.assertEqual(parsed_args.git_log, 'data/git/git_log.txt')
        self.assertEqual(parsed_args.tag, 'test')
        self.assertEqual(parsed_args.from_date, DEFAULT_DATETIME)
        self.assertEqual(parsed_args.branches, None)

        args = ['http://example.com/',
                '--git-path', '/tmp/gitpath',
                '--branches', 'master', 'testing']

        parsed_args = parser.parse(*args)
        self.assertEqual(parsed_args.git_path, '/tmp/gitpath')
        self.assertEqual(parsed_args.uri, 'http://example.com/')
        self.assertEqual(parsed_args.branches, ['master', 'testing'])
コード例 #2
0
    def enrich_git_branches(self, ocean_backend, enrich_backend):
        """Update the information about branches within the documents representing
        commits in the enriched index.

        :param ocean_backend: the ocean backend
        :param enrich_backend: the enrich backend
        """
        logger.debug("[git] study git-branches start")
        for ds in self.prjs_map:
            if ds != "git":
                continue

            urls = self.prjs_map[ds]

            for url in urls:
                cmd = GitCommand(*[url])

                git_repo = GitRepository(cmd.parsed_args.uri, cmd.parsed_args.gitpath)

                logger.debug("[git] study git-branches delete branch info for repo {} in index {}".format(
                             git_repo.uri, self.elastic.anonymize_url(enrich_backend.elastic.index_url)))
                self.delete_commit_branches(git_repo, enrich_backend)

                logger.debug("[git] study git-branches add branch info for repo {} in index {}".format(
                             git_repo.uri, self.elastic.anonymize_url(enrich_backend.elastic.index_url)))
                self.add_commit_branches(git_repo, enrich_backend)

                logger.debug("[git] study git-branches repo {} in index {} processed".format(
                             git_repo.uri, self.elastic.anonymize_url(enrich_backend.elastic.index_url)))

        logger.debug("[git] study git-branches end")
コード例 #3
0
ファイル: git.py プロジェクト: valeriocos/GrimoireELK
    def enrich_git_branches(self, ocean_backend, enrich_backend, run_month_days=[7, 14, 21, 28]):
        """Update the information about branches within the documents representing
        commits in the enriched index.

        The example below shows how to activate the study by modifying the setup.cfg. The study
        `enrich_git_branches` will be run on days depending on the parameter `run_month_days`,
        by default the days are 7, 14, 21, and 28 of each month.

        ```
        [git]
        raw_index = git_raw
        enriched_index = git_enriched
        ...
        studies = [enrich_git_branches]

        [enrich_git_branches]
        run_month_days = [5, 22]
        ```

        :param ocean_backend: the ocean backend
        :param enrich_backend: the enrich backend
        :param run_month_days: days of the month to run this study
        """
        logger.debug("[git] study git-branches start")
        day = datetime_utcnow().day
        run_month_days = list(map(int, run_month_days))
        if day not in run_month_days:
            logger.debug("[git] study git-branches will execute only the days {} of each month".format(run_month_days))
            logger.debug("[git] study git-branches end")
            return

        for ds in self.prjs_map:
            if ds != "git":
                continue

            urls = self.prjs_map[ds]

            for url in urls:
                cmd = GitCommand(*[url])

                git_repo = GitRepository(cmd.parsed_args.uri, cmd.parsed_args.gitpath)

                logger.debug("[git] study git-branches delete branch info for repo {} in index {}".format(
                             git_repo.uri, anonymize_url(enrich_backend.elastic.index_url)))
                self.delete_commit_branches(git_repo, enrich_backend)

                logger.debug("[git] study git-branches add branch info for repo {} in index {}".format(
                             git_repo.uri, anonymize_url(enrich_backend.elastic.index_url)))
                try:
                    self.add_commit_branches(git_repo, enrich_backend)
                except Exception as e:
                    logger.error("[git] study git-branches failed on repo {}, due to {}".format(git_repo.uri, e))
                    continue

                logger.debug("[git] study git-branches repo {} in index {} processed".format(
                             git_repo.uri, anonymize_url(enrich_backend.elastic.index_url)))

        logger.debug("[git] study git-branches end")
コード例 #4
0
ファイル: test_git.py プロジェクト: celan/perceval
    def test_gitpath_init(self, mock_expanduser):
        """Test gitpath initialization"""

        mock_expanduser.return_value = 'testpath'

        args = ['http://example.com/']

        cmd = GitCommand(*args)
        self.assertEqual(cmd.parsed_args.gitpath,
                         'testpath/http://example.com/')

        args = ['http://example.com/', '--git-log', 'data/git_log.txt']

        cmd = GitCommand(*args)
        self.assertEqual(cmd.parsed_args.gitpath, 'data/git_log.txt')

        args = ['http://example.com/', '--git-path', '/tmp/gitpath']

        cmd = GitCommand(*args)
        self.assertEqual(cmd.parsed_args.gitpath, '/tmp/gitpath')
コード例 #5
0
ファイル: git.py プロジェクト: cewilliams/grimoirelab-elk
    def enrich_git_branches(self, ocean_backend, enrich_backend):
        """Update the information about branches within the documents representing
        commits in the enriched index.

        :param ocean_backend: the ocean backend
        :param enrich_backend: the enrich backend
        """
        for ds in self.prjs_map:
            if ds != "git":
                continue

            urls = self.prjs_map[ds]

            for url in urls:
                cmd = GitCommand(*[url])

                git_repo = GitRepository(cmd.parsed_args.uri,
                                         cmd.parsed_args.gitpath)
                self.delete_commit_branches(git_repo, enrich_backend)
                self.add_commit_branches(git_repo, enrich_backend)
コード例 #6
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Author:
#      Sumit Kumar Jangir <*****@*****.**>

#imports
from perceval.backends.core.git import Git
from perceval.backends.core.git import GitCommand
from datetime import datetime

#setting up Git Argument parser
parser = GitCommand.setup_cmd_parser()

# making arguments list
arg = [
    'https://github.com/sumitskj/Prajawalan2019.git', '--git-path',
    '/tmp/clone'
]
args = parser.parse(*arg)

# making Git object
repo = Git(uri=args.uri, gitpath=args.git_path)

# finding the no. of commits and listing them all
count = 0

from_date = datetime(2018, 10, 12)