def branch_model(): yield GitBranchModel.get_or_create( branch_name=SampleValues.branch, namespace=SampleValues.repo_namespace, repo_name=SampleValues.repo_name, project_url=SampleValues.project_url, )
def db_trigger(self) -> Optional[AbstractTriggerDbType]: return GitBranchModel.get_or_create( branch_name=self.git_ref, namespace=self.repo_namespace, repo_name=self.repo_name, project_url=self.project_url, )
def db_trigger(self) -> Optional[AbstractTriggerDbType]: if not self._db_trigger: # TODO, do a better job # Probably, try to recreate original classes. if self.event_type in { "PullRequestGithubEvent", "PullRequestPagureEvent", "MergeRequestGitlabEvent", "PullRequestCommentGithubEvent", "MergeRequestCommentGitlabEvent", "PullRequestCommentPagureEvent", "CheckRerunPullRequestEvent", }: self._db_trigger = PullRequestModel.get_or_create( pr_id=self.pr_id, namespace=self.project.namespace, repo_name=self.project.repo, project_url=self.project_url, ) elif self.event_type in { "PushGitHubEvent", "PushGitlabEvent", "PushPagureEvent", "CheckRerunCommitEvent", }: self._db_trigger = GitBranchModel.get_or_create( branch_name=self.git_ref, namespace=self.project.namespace, repo_name=self.project.repo, project_url=self.project_url, ) elif self.event_type in {"ReleaseEvent", "CheckRerunReleaseEvent"}: self._db_trigger = ProjectReleaseModel.get_or_create( tag_name=self.tag_name, namespace=self.project.namespace, repo_name=self.project.repo, project_url=self.project_url, commit_hash=self.commit_sha, ) elif self.event_type in { "IssueCommentEvent", "IssueCommentGitlabEvent", }: self._db_trigger = IssueModel.get_or_create( issue_id=self.issue_id, namespace=self.project.namespace, repo_name=self.project.repo, project_url=self.project_url, ) else: logger.warning( "We don't know, what to search in the database for this event data." ) return self._db_trigger
def db_trigger(self): if not self._db_trigger and self.data.trigger_id is not None: if self.data.trigger in ( TheJobTriggerType.pull_request, TheJobTriggerType.pr_comment, TheJobTriggerType.pr_label, ): self._db_trigger = PullRequestModel.get_by_id( self.data.trigger_id) elif self.data.trigger == TheJobTriggerType.issue_comment: self._db_trigger = IssueModel.get_by_id(self.data.trigger_id) elif self.data.trigger == TheJobTriggerType.release: self._db_trigger = ProjectReleaseModel.get_by_id( self.data.trigger_id) elif self.data.trigger == TheJobTriggerType.push: self._db_trigger = GitBranchModel.get_by_id( self.data.trigger_id) return self._db_trigger
def build_model(self) -> Optional[KojiBuildModel]: if not super().build_model: self._build_model = KojiBuildModel.create( build_id=str(self.build_id), commit_sha=self._commit_sha, web_url=self.web_url, target="noarch", # TODO: where to get this info from? status=self.state.value, run_model=RunModel.create( type=JobTriggerModelType.branch_push, trigger_id=GitBranchModel.get_or_create( branch_name=self.branch_name, repo_name=self.repo_name, namespace=self.namespace, project_url=self.project_url, ).id, ), ) return self._build_model
def mock_push_functionality(request): packit_yaml = ( "{'specfile_path': 'the-specfile.spec', 'synced_files': [], 'jobs':" + str(request.param) + "}" ) flexmock( GithubProject, full_repo_name="packit/hello-world", get_file_content=lambda path, ref: packit_yaml, get_files=lambda ref, filter_regex: ["the-specfile.spec"], get_web_url=lambda: "https://github.com/the-namespace/the-repo", get_pr=lambda pr_id: flexmock(head_commit="12345"), ) flexmock(Github, get_repo=lambda full_name_or_id: None) config = ServiceConfig() config.command_handler_work_dir = SANDCASTLE_WORK_DIR flexmock(ServiceConfig).should_receive("get_service_config").and_return(config) trigger = JobTriggerModel(type=JobConfigTriggerType.commit, id=123) flexmock(AddBranchPushDbTrigger).should_receive("db_trigger").and_return(trigger) flexmock(GitBranchModel).should_receive("get_by_id").with_args(123).and_return( trigger ) flexmock(LocalProject, refresh_the_arguments=lambda: None) flexmock(JobTriggerModel).should_receive("get_by_id").with_args(123456).and_return( trigger ) flexmock(trigger).should_receive("get_trigger_object").and_return( GitBranchModel(name="main") ) flexmock(GitBranchModel).should_receive("get_or_create").with_args( branch_name="main", namespace="packit", repo_name="hello-world", project_url="https://github.com/packit/hello-world", ).and_return(flexmock(id=12, job_config_trigger_type=JobConfigTriggerType.commit)) flexmock(JobTriggerModel).should_receive("get_or_create").and_return( flexmock(id=123456) )
def branch_model(): yield GitBranchModel.get_or_create( branch_name="build-branch", namespace="the-namespace", repo_name="the-repo-name", )