def validate_repo_state(self, repo):
     """Validate a repository meets current CircuitPython criteria.  Expects
     a dictionary with a GitHub API repository state (like from the list_repos
     function).  Returns a list of string error messages for the repository.
     """
     if not (repo["owner"]["login"] == "adafruit"
             and repo["name"].startswith("Adafruit_CircuitPython")):
         return []
     full_repo = github.get("/repos/" + repo["full_name"])
     if not full_repo.ok:
         return [ERROR_UNABLE_PULL_REPO_DETAILS]
     full_repo = full_repo.json()
     errors = []
     if repo["has_wiki"]:
         errors.append(ERROR_WIKI_DISABLED)
     if not repo["license"] and not repo["name"] in BUNDLE_IGNORE_LIST:
         errors.append(ERROR_MISSING_LICENSE)
     if not repo["permissions"]["push"]:
         errors.append(ERROR_MISSING_LIBRARIANS)
     if not common_funcs.is_repo_in_bundle(full_repo["clone_url"], self.bundle_submodules) and \
        not repo["name"] in BUNDLE_IGNORE_LIST:  # Don't assume the bundle will
         # bundle itself and possibly
         # other repos.
         errors.append(ERROR_NOT_IN_BUNDLE)
     if "allow_squash_merge" not in full_repo or full_repo[
             "allow_squash_merge"] or full_repo["allow_rebase_merge"]:
         errors.append(ERROR_ONLY_ALLOW_MERGES)
     return errors
 def test_not_in_bundle(self):
     bundle_submodules = [('libraries/register', {
         'path': 'libraries/helpers/register',
         'url': 'https://github.com/adafruit/Adafruit_CircuitPython_Register.git'})]
     result = common_funcs.is_repo_in_bundle(
         'https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO.git',
         bundle_submodules)
     self.assertFalse(result)
 def test_differing_url_scheme(self):
     bundle_submodules = [('libraries/register', {
         'path': 'libraries/helpers/register',
         'url': 'https://github.com/adafruit/Adafruit_CircuitPython_Register.git'})]
     result = common_funcs.is_repo_in_bundle(
         'http://github.com/adafruit/Adafruit_CircuitPython_Register.git',
         bundle_submodules)
     self.assertTrue(result)
    def validate_repo_state(self, repo):
        """Validate a repository meets current CircuitPython criteria.  Expects
        a dictionary with a GitHub API repository state (like from the list_repos
        function).  Returns a list of string error messages for the repository.
        """
        if not (repo["owner"]["login"] == "adafruit" and
                repo["name"].startswith("Adafruit_CircuitPython")):
            return []

        search_keys = {
            "has_wiki",
            "license",
            "permissions",
            "allow_squash_merge",
            "allow_rebase_merge",
        }

        repo_fields = repo.copy()

        repo_fields_keys = set(repo_fields.keys())
        repo_missing_some_keys = search_keys.difference(repo_fields_keys)

        if repo_missing_some_keys:
            # only call the API if the passed in `repo` doesn't have what
            # we need.
            response = github.get("/repos/" + repo["full_name"])
            if not response.ok:
                return [ERROR_UNABLE_PULL_REPO_DETAILS]
            repo_fields = response.json()

        errors = []

        if not repo_fields.get("description"):
            errors.append(ERROR_MISSING_DESCRIPTION)

        if repo_fields.get("has_wiki"):
            errors.append(ERROR_WIKI_DISABLED)

        if (not repo_fields.get("license") and
            not repo["name"] in BUNDLE_IGNORE_LIST):
                errors.append(ERROR_MISSING_LICENSE)

        if not repo_fields.get("permissions", {}).get("push"):
            errors.append(ERROR_MISSING_LIBRARIANS)

        repo_in_bundle = common_funcs.is_repo_in_bundle(repo_fields["clone_url"],
                                                        self.bundle_submodules)
        if not repo_in_bundle and not repo["name"] in BUNDLE_IGNORE_LIST:
                # Don't assume the bundle will bundle itself and possibly
                # other repos.
                errors.append(ERROR_NOT_IN_BUNDLE)

        if (repo_fields.get("allow_squash_merge") or
            repo_fields.get("allow_rebase_merge")):
                errors.append(ERROR_ONLY_ALLOW_MERGES)
        return errors