Esempio n. 1
0
    def run(self, labels: list, analysis_id: Optional[str] = None):
        """Run the provenance check bot."""
        if self.parsed_payload:
            if self.parsed_payload.get("event") not in _EVENTS_SUPPORTED:
                _LOGGER.info(
                    "ThothProvenanceManager doesn't act on %r events.",
                    self.parsed_payload.get("event"),
                )
                return

        if not analysis_id:
            with cloned_repo(self, depth=1) as repo:
                self.repo = repo
                if not (os.path.isfile("Pipfile")
                        and os.path.isfile("Pipfile.lock")):
                    _LOGGER.warning(
                        "Pipfile or Pipfile.lock is missing from repo, opening issue"
                    )
                    issue = self.get_issue_by_title("Missing pipenv files")
                    if issue is None:
                        self.project.create_issue(
                            title="Missing pipenv files",
                            body=
                            "Check your repository to make sure Pipfile and Pipfile.lock exist.",
                            labels=labels,
                        )
                    return False
                _LOGGER.info((self.service_url + self.slug))
                lib.provenance_check_here(
                    nowait=True, origin=f"{self.service_url}/{self.slug}")
            return True
        else:
            if not analysis_id.startswith("provenance"):
                _LOGGER.debug(
                    "Analysis id isn't provenance, manager terminating...")
                return False

            with cloned_repo(self, depth=1) as repo:
                res = lib.get_analysis_results(analysis_id)
                if res is None:
                    _LOGGER.error(
                        "Provenance check failed on server side, contact the maintainer"
                    )
                    return False
                if res[1] is False:
                    _LOGGER.info(
                        "Provenance check found problems, creating issue...")
                    self._issue_provenance_error(res, labels)
                    return False
                else:
                    _LOGGER.info(
                        "Provenance check found no problems, carry on coding :)"
                    )
                    return True
Esempio n. 2
0
    def run(self, labels: list, analysis_id=None):
        """Run the provenance check bot."""
        if self.parsed_payload:
            if self.parsed_payload.get('event') not in _EVENTS_SUPPORTED:
                _LOGGER.info(
                    "ThothProvenanceManager doesn't act on %r events.",
                    self.parsed_payload.get('event'))
                return

        if not analysis_id:
            with cloned_repo(self.service_url, self.slug, depth=1) as repo:
                self.repo = repo
                if not (os.path.isfile("Pipfile")
                        and os.path.isfile("Pipfile.lock")):
                    _LOGGER.warning(
                        "Pipfile or Pipfile.lock is missing from repo, opening issue"
                    )
                    self.sm.open_issue_if_not_exist(
                        "Missing pipenv files",
                        lambda:
                        "Check your repository to make sure Pipfile and Pipfile.lock exist.",
                        labels=labels)
                    return False
                _LOGGER.info((self.service_url + self.slug))
                lib.provenance_check_here(
                    nowait=True, origin=f"{self.service_url}/{self.slug}")
            return True
        else:
            with cloned_repo(self.service_url, self.slug, depth=1) as repo:
                res = lib.get_analysis_results(analysis_id)
                if res is None:
                    _LOGGER.error(
                        "Provenance check failed on server side, contact the maintainer"
                    )
                    return False
                if res[1] is False:
                    _LOGGER.info(
                        "Provenance check found problems, creating issue...")
                    self._issue_provenance_error(res, labels)
                    return False
                else:
                    _LOGGER.info(
                        "Provenance check found no problems, carry on coding :)"
                    )
                    return True
Esempio n. 3
0
def step_impl(context, provenance_check_case: str):
    """Call library function from Thamos to submit analysis to Thoth."""
    project_dir = os.path.join("features", "data", "project", provenance_check_case)
    config.explicit_host = context.user_api_host

    original_dir = os.getcwd()
    try:
        os.chdir(project_dir)
        context.analysis_id = provenance_check_here(
            nowait=True,
            force=True,
        )
    finally:
        os.chdir(original_dir)

    assert context.analysis_id, "No provenance check analysis id retrieved"