Ejemplo n.º 1
0
 def test_repo_data(self):
     repo = "user/test"
     stub_list = [
         Config({"full_name": repo}),
         Config({"full_name": "wrong_repo"})
     ]
     self.client.repo_list = mock.Mock(return_value=stub_list)
     self.assertEquals(self.client.repo_data(repo).full_name(), repo)
Ejemplo n.º 2
0
 def repo_list(self, force=False, filters=[], file_filters=[], orgs=[]):
     if self.repos is not None and not force:
         return self.filter_repos(filters, file_filters)
     if os.path.isfile(self.cache_file) and not force:
         self.repos = [Config(repo)
                       for repo in load_json_file(self.cache_file)]
         return self.filter_repos(filters, file_filters)
     repos = []
     if len(orgs) <= 0:
         orgs = copy(self.config.orgs())
     for org_login in orgs:
         for repo in self.client.organization(org_login).repositories():
             repos.append(repo_hash(repo))
     write_json_file(self.cache_file, repos)
     self.repos = [Config(repo) for repo in repos]
     return self.filter_repos(filters, file_filters)
Ejemplo n.º 3
0
 def print_node(self, node, attrs=[]):
     wrapper = Config(node)
     self.log.title(wrapper.displayName())
     self.log.info("  - offline: %s" % wrapper.offline())
     self.log.info("  - idle: %s" % wrapper.idle())
     for key in attrs:
         self.log.info("  - %s: %s" % (key, node[key]))
Ejemplo n.º 4
0
 def filter_repo_jobs(self, repo):
     """Map a repo (object from the repo module) to all jobs in given
     job config objects"""
     templates = {}
     for cfg in [Config(cfg) for cfg in self.metas]:
         meta_templates = TemplateFetcher(cfg).templates(repo)
         if not len(meta_templates) <= 0:
             if cfg.instance() not in templates:
                 templates[cfg.instance()] = []
             templates[cfg.instance()] += meta_templates
     return templates
Ejemplo n.º 5
0
    def execute(self, opts):
        try:
            icfg = self.app.config.jenkins.instances()[opts.instance]
        except KeyError:
            self.log.error("no such instance [%s]" % (opts.instance))
            return

        fork = opts.repo
        org = None
        if fork is None:
            fork = git.name_from_local_remote(opts.fork)
            org = git.org_from_name(fork)
        else:
            org, _ = opts.repo.split("/", 1)
        fork = fork.lower()
        org = org.lower()
        repo_name = fork.replace("%s/" % org, "")

        self.log.title("Fetching github data for %s (org: %s)" % (fork, org))

        repo = repo_hash(
            self.app.github(opts.api_url).repository(org, repo_name))

        self.log.title("Fetched metadata for %s" % fork)
        self.log.info(json.dumps(repo, indent=2))

        workspace = opts.workspace
        if workspace is None:
            workspace = self._default_workspace(fork)
        workspace = "%s-%i" % (workspace, int(time.time()))

        self.app.workspace.set_dir(workspace)
        self.clean_workspace(workspace)
        self.app.workspace.create_subdir(opts.instance)
        params = self.repo_params(opts.instance, fork, Config(repo))
        user_params = params_from_str(opts.params)
        if bool(user_params):
            self.log.info("Injecting params: %s" % user_params)
        params['name'] = '%s-project' % params['name']
        params.update(user_params)
        self.write_instance_templates(opts.instance, fork, params,
                                      opts.templates, opts.vars)
        ok = 0
        try:
            create_jobs(opts.instance, self.app.workspace, icfg,
                        self.app.workspace._default_libdir())
        except Exception as err:
            self.log.error("Could not provision jobs: %s" % err)
            ok = 1
        self.log.info("Project templates created in:")
        print(workspace)
        return ok
Ejemplo n.º 6
0
 def templates(self, repo):
     if not type(repo) == Config:
         repo = Config(repo)
     if self.cfg.owner() != repo.owner():
         return []
     if self.cfg.repo.exists() and self.cfg.repo() != repo.name():
         return []
     if self.private_only and not repo.private():
         return []
     if self.forks_only and repo.fork():
         return []
     if self.cfg.include.exists() and repo.name() not in self.cfg.include():
         return []
     return self.cfg.templates()
Ejemplo n.º 7
0
 def wanted_node(self, node, filters=[]):
     if len(filters) == 0:
         return True
     wrapper = Config(node)
     if wrapper.displayName() == "master":
         return False
     if "offline" in filters or "online" in filters:
         if wrapper.offline() and "offline" in filters:
             return True
         if wrapper.offline() and "online" in filters:
             return False
     if "idle" in filters or "busy" in filters:
         if wrapper.idle() and "idle" in filters:
             return True
         if wrapper.idle() and "busy" in filters:
             return False
     return False
Ejemplo n.º 8
0
 def load_config(self, cfg_file=None):
     if cfg_file is None:
         cfg_file = prep_default_config()
     self.config = Config(load_json_file(cfg_file))
Ejemplo n.º 9
0
 def __init__(self, log):
     self.config = Config({})
     self.log = log
     self.workspace = Workspace()
Ejemplo n.º 10
0
 def __init__(self, template_meta):
     if not type(template_meta) == Config:
         template_meta = Config(template_meta)
     self.cfg = template_meta
     self.private_only = not template_meta.include_public()
     self.forks_only = not template_meta.include_forks()
Ejemplo n.º 11
0
 def setUp(self):
     self.cfg = Config({"foo": "bar"})