def __gen_sample(ctx: click.Context, distribution: str, end: str, start: str, num_rev: int, only_code_commits: bool) -> None: """ Add revisions based on a sampling Distribution. Distribution: The sampling method to use """ sampling_method: NormalSamplingMethod = NormalSamplingMethod \ .get_sampling_method_type( distribution )() project_repo_path = get_local_project_git_path(ctx.obj['project']) if end != "HEAD" and not is_commit_hash(end): end = get_commits_before_timestamp(end, project_repo_path)[0].hash if start is not None and not is_commit_hash(start): commits_before = get_commits_before_timestamp(start, project_repo_path) if commits_before: start = commits_before[0].hash else: start = get_initial_commit(project_repo_path).hash cmap = create_lazy_commit_map_loader(ctx.obj['project'], None, end, start)() extend_with_distrib_sampling(ctx.obj['case_study'], cmap, sampling_method, ctx.obj['merge_stage'], num_rev, ctx.obj['ignore_blocked'], only_code_commits) store_case_study(ctx.obj['case_study'], ctx.obj['path'])
def command_template(context: click.Context, **kwargs: tp.Any) -> None: # extract common arguments and plot config from context plot_config: PlotConfig = PlotConfig(False) try: generator_instance = generator_cls(plot_config, **kwargs) plots = generator_instance.generate() plot = plots[0] if len(plots) > 1: def set_plot(selected_plot: Plot) -> None: nonlocal plot plot = selected_plot cli_list_choice( "The given plot generator creates multiple plots" " please select one:", plots, lambda p: p.name, set_plot) cmap = create_lazy_commit_map_loader(context.obj['project'], None, 'HEAD', None)() extend_with_smooth_revs(context.obj['case_study'], cmap, context.obj['boundary_gradient'], context.obj['ignore_blocked'], plot, context.obj['merge_stage']) store_case_study(context.obj['case_study'], context.obj['path']) except PlotGeneratorFailed as ex: print(f"Failed to create plot generator {generator_cls.NAME}: " f"{ex.message}")
def store(self) -> None: """Persist the current state of the paper config saving all case studies to their corresponding files in the paper config path.""" for case_study_list in self.__case_studies.values(): for case_study in case_study_list: store_case_study(case_study, self.__path) self.store_artefacts()
def gen(self) -> None: """Generate the case study using the selected strategy, project and strategy specific arguments.""" cmap = create_lazy_commit_map_loader(self.selected_project, None, 'HEAD', None)() version = self.cs_version.value() case_study = CaseStudy(self.revision_list_project, version) paper_config = vara_cfg()["paper_config"]["current_config"].value path = Path(vara_cfg()["paper_config"]["folder"].value) / ( paper_config + f"/{self.revision_list_project}_{version}.case_study") if self.strategie_forms.currentIndex( ) == GenerationStrategie.SAMPLE.value: sampling_method = NormalSamplingMethod.get_sampling_method_type( self.sampling_method.currentText()) extend_with_distrib_sampling(case_study, cmap, sampling_method(), 0, self.num_revs.value(), True, self.code_commits.clicked) elif self.strategie_forms.currentIndex( ) == GenerationStrategie.SELECT_REVISION.value: selected_rows = self.revision_list.selectionModel().selectedRows(0) selected_commits = [row.data() for row in selected_rows] extend_with_extra_revs(case_study, cmap, selected_commits, 0) self.revision_list.clearSelection() self.revision_list.update() elif self.strategie_forms.currentIndex( ) == GenerationStrategie.REVS_PER_YEAR.value: extend_with_revs_per_year( case_study, cmap, 0, True, get_local_project_git_path(self.selected_project), self.revs_per_year.value(), self.seperate.checkState()) store_case_study(case_study, path)
def __gen_specific(ctx: click.Context, revisions: tp.List[str]) -> None: """ Adds a list of specified revisions to the CS. Revisions: Revisions to add """ cmap = create_lazy_commit_map_loader(ctx.obj['project'], None, 'HEAD', None)() extend_with_extra_revs(ctx.obj['case_study'], cmap, revisions, ctx.obj['merge_stage']) store_case_study(ctx.obj['case_study'], ctx.obj['path'])
def __gen_latest(ctx: click.Context) -> None: """Add the latest revision of the project to the CS.""" cmap = generate_commit_map(ctx.obj["git_path"]) case_study: CaseStudy = ctx.obj['case_study'] repo = pygit2.Repository(pygit2.discover_repository(ctx.obj["git_path"])) last_commit = FullCommitHash.from_pygit_commit(repo[repo.head.target]) case_study.include_revisions([(last_commit, cmap.time_id(last_commit))]) store_case_study(case_study, ctx.obj['path'])
def __gen_release(ctx: click.Context, release_type: ReleaseType) -> None: """ Extend a case study with revisions marked as a release. This relies on the project to determine appropriate revisions. release_type: Release type to consider """ cmap = create_lazy_commit_map_loader(ctx.obj['project'], None, 'HEAD', None)() extend_with_release_revs(ctx.obj['case_study'], cmap, release_type, ctx.obj['ignore_blocked'], ctx.obj['merge_stage']) store_case_study(ctx.obj['case_study'], ctx.obj['path'])
def __gen_bug_commits(ctx: click.Context, report_type: tp.Type['BaseReport']) -> None: """ Extend a case study with revisions that either introduced or fixed a bug as determined by the given SZZ tool. REPORT_TYPE: report to use for determining bug regions """ cmap = create_lazy_commit_map_loader(ctx.obj['project'], None, 'HEAD', None)() extend_with_bug_commits(ctx.obj['case_study'], cmap, report_type, ctx.obj['merge_stage'], ctx.obj['ignore_blocked']) store_case_study(ctx.obj['case_study'], ctx.obj['path'])
def __gen_per_year(ctx: click.Context, revs_per_year: int, separate: bool) -> None: """ Add a number of revisions per year. revs-per-year: number of revisions to generate per year """ cmap = create_lazy_commit_map_loader(ctx.obj['project'], None, 'HEAD', None)() extend_with_revs_per_year(ctx.obj['case_study'], cmap, ctx.obj['merge_stage'], ctx.obj['ignore_blocked'], ctx.obj['git_path'], revs_per_year, separate) store_case_study(ctx.obj['case_study'], ctx.obj['path'])