Exemplo n.º 1
0
    def sync_upstream_pull_request_with_fedmsg(self, fedmsg: Dict):
        repo_name = fedmsg["msg"]["pull_request"]["head"]["repo"]["name"]
        namespace = fedmsg["msg"]["pull_request"]["head"]["repo"]["owner"][
            "login"]
        ref = fedmsg["msg"]["pull_request"]["head"]["ref"]
        pr_id = fedmsg["msg"]["pull_request"]["number"]

        github_repo = self._github_service.get_project(  # type: ignore
            repo=repo_name, namespace=namespace)
        local_project = LocalProject(git_project=github_repo)

        package_config = get_packit_config_from_repo(
            sourcegit_project=github_repo, ref=ref)

        if not package_config:
            logger.debug(
                f"No packit config: skipping pull-request {pr_id} for {namespace}/{repo_name}."
            )
            return
        self.sync_upstream_pull_request(
            package_config=package_config,
            pr_id=pr_id,
            dist_git_branch="master",
            upstream_local_project=local_project,
        )
Exemplo n.º 2
0
    def sync_upstream_release_with_fedmsg(self, fedmsg: Dict):
        """
        Sync the upstream release to the distgit pull-request.

        :param fedmsg: fedmsg dict
        """
        repo_name = fedmsg["msg"]["repository"]["name"]
        namespace = fedmsg["msg"]["repository"]["owner"]["login"]
        version = fedmsg["msg"]["release"]["tag_name"]
        https_url = fedmsg["msg"]["repository"]["html_url"]

        github_repo = self._github_service.get_project(  # type: ignore
            repo=repo_name, namespace=namespace)
        local_project = LocalProject(git_project=github_repo)

        package_config = get_packit_config_from_repo(
            sourcegit_project=github_repo, ref=version)

        if not package_config:
            logger.info(
                f"No packit config: skipping release {version} for {namespace}/{repo_name}."
            )
            return

        if not package_config.upstream_project_url:
            package_config.upstream_project_url = https_url

        # TODO: https://github.com/packit-service/packit/issues/103
        self.sync_upstream_release(
            package_config=package_config,
            version=version,
            dist_git_branch="master",
            upstream_local_project=local_project,
        )
Exemplo n.º 3
0
def test_get_packit_config_from_repo(content):
    flexmock(GitProject).should_receive("get_file_content").and_return(content)
    git_project = GitProject(repo="", service=GitService(), namespace="")
    config = get_packit_config_from_repo(sourcegit_project=git_project, ref="")
    assert isinstance(config, PackageConfig)
    assert config.specfile_path == "packit.spec"
    assert set(config.synced_files) == {"packit.spec", ".packit.yaml"}
Exemplo n.º 4
0
 def get_package_config_from_github_release(
     self, event: dict
 ) -> Optional[Tuple[JobTriggerType, PackageConfig, GitProject]]:
     """ look into the provided event and see if it's one for a published github release """
     action = nested_get(event, "action")
     logger.debug(f"action = {action}")
     release = nested_get(event, "release")
     if action == "published" and release:
         repo_namespace = nested_get(event, "repository", "owner", "login")
         repo_name = nested_get(event, "repository", "name")
         if not (repo_namespace and repo_name):
             logger.warning(
                 "We could not figure out the full name of the repository.")
             return None
         release_ref = nested_get(event, "release", "tag_name")
         if not release_ref:
             logger.warning("Release tag name is not set.")
             return None
         logger.info(
             f"New release event {release_ref} for repo {repo_namespace}/{repo_name}."
         )
         gh_proj = GithubProject(repo=repo_name,
                                 namespace=repo_namespace,
                                 service=self.github_service)
         package_config = get_packit_config_from_repo(gh_proj, release_ref)
         return JobTriggerType.release, package_config, gh_proj
     return None
Exemplo n.º 5
0
def test_get_packit_config_from_repo(content):
    flexmock(GitProject).should_receive("get_file_content").and_return(content)
    git_project = GitProject(repo="", service=GitService(), namespace="")
    config = get_packit_config_from_repo(sourcegit_project=git_project, ref="")
    assert isinstance(config, PackageConfig)
    assert Path(config.specfile_path).name == "packit.spec"
    assert config.synced_files == SyncFilesConfig(files_to_sync=[
        SyncFilesItem(src="packit.spec", dest="packit.spec"),
        SyncFilesItem(src=".packit.yaml", dest=".packit2.yaml"),
    ])
Exemplo n.º 6
0
 def get_packit_config(self, namespace: str, repo: str,
                       branch: str) -> PackageConfig:
     github_repo = self.sourcegit_service.get_project(repo=repo,
                                                      namespace=namespace)
     return get_packit_config_from_repo(sourcegit_project=github_repo,
                                        branch=branch)