示例#1
0
 def db_trigger(self) -> Optional[AbstractTriggerDbType]:
     return IssueModel.get_or_create(
         issue_id=self.issue_id,
         namespace=self.repo_namespace,
         repo_name=self.repo_name,
         project_url=self.project_url,
     )
示例#2
0
    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
示例#3
0
 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
示例#4
0
def test_issue_comment_propose_downstream_handler(
        mock_issue_comment_functionality,
        issue_comment_propose_downstream_event):
    flexmock(PackitAPI).should_receive("sync_release").and_return(
        PullRequest(
            title="foo",
            description="bar",
            target_branch="baz",
            source_branch="yet",
            id=1,
            status=PRStatus.open,
            url="https://xyz",
            author="me",
            created=datetime.now(),
        ))
    flexmock(
        GithubProject,
        get_files=lambda ref, filter_regex: [],
        get_web_url=lambda: "https://github.com/the-namespace/the-repo",
        is_private=lambda: False,
    )

    flexmock(IssueCommentEvent, db_trigger=IssueModel(id=123))
    flexmock(IssueModel).should_receive("get_by_id").with_args(123).and_return(
        flexmock(issue_id=12345))
    flexmock(Signature).should_receive("apply_async").once()

    processing_results = SteveJobs().process_message(
        issue_comment_propose_downstream_event)
    event_dict, job, job_config, package_config = get_parameters_from_results(
        processing_results)

    results = run_propose_downstream_handler(
        package_config=package_config,
        event=event_dict,
        job_config=job_config,
    )

    assert first_dict_value(results["job"])["success"]