From 3cb857219881668bfddafcade1cecb1113f32de6 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 1 Aug 2021 16:49:35 +0300 Subject: support setting "dir" for individual repositories --- cgitize/config.py | 8 ++++++-- cgitize/repo.py | 4 +++- examples/cgitize.toml | 6 ++++++ test/integration/example/test.sh | 20 ++++++++++---------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/cgitize/config.py b/cgitize/config.py index 35ba05f..2f074bb 100644 --- a/cgitize/config.py +++ b/cgitize/config.py @@ -130,6 +130,10 @@ class HostedRepo: def id(self): return self._impl['id'] + @property + def dir(self): + return self._impl.get('dir') + class Config: DEFAULT_PATH = '/etc/cgitize/cgitize.toml' @@ -155,7 +159,7 @@ class Config: github = GitHub(self.github.access_token) for r in self.github.repositories.enum_repositories(): r = HostedRepo(r) - yield Repo.from_github(github.get_repo(r), self) + yield Repo.from_github(github.get_repo(r), self, r.dir) for u in self.github.users.enum_users(): u = User(u) yield from (Repo.from_github(r, self, u.dir) for r in github.get_user_repos(u)) @@ -164,7 +168,7 @@ class Config: bitbucket = Bitbucket(self.bitbucket.username, self.bitbucket.app_password) for r in self.bitbucket.repositories.enum_repositories(): r = HostedRepo(r) - yield Repo.from_bitbucket(bitbucket.get_repo(r), self) + yield Repo.from_bitbucket(bitbucket.get_repo(r), self, r.dir) for u in self.bitbucket.users.enum_users(): u = User(u) yield from (Repo.from_bitbucket(r, self, u.dir) for r in bitbucket.get_user_repos(u)) diff --git a/cgitize/repo.py b/cgitize/repo.py index cce3209..133cdc8 100644 --- a/cgitize/repo.py +++ b/cgitize/repo.py @@ -20,7 +20,9 @@ class Repo: if 'clone_url' not in src: raise ValueError("every repository must have 'clone_url'") clone_url = src['clone_url'] - return Repo(name, clone_url, owner=owner, desc=desc, homepage=homepage) + subdir = src.get('dir') + return Repo(name, clone_url, owner=owner, desc=desc, homepage=homepage, + subdir=subdir) @staticmethod def from_github(src, config, subdir=None): diff --git a/examples/cgitize.toml b/examples/cgitize.toml index 19b7056..e789875 100644 --- a/examples/cgitize.toml +++ b/examples/cgitize.toml @@ -31,6 +31,8 @@ dir = "github-dir" id = "ekmett/lens" [github.repositories.pytomlpp] id = "bobfang1992/pytomlpp" +# You can put repositories in a subdirectory: +dir = "python" [bitbucket] # If some of the repositories hosted on Bitbucket are private, you can use "app @@ -51,6 +53,8 @@ dir = "bitbucket-dir" # Some random repositories hosted on Bitbucket: [bitbucket.repositories.cef] id = "chromiumembedded/cef" +# You can put repositories in a subdirectory: +dir = "chromiumembedded" [bitbucket.repositories.upc-runtime] id = "berkeleylab/upc-runtime" @@ -62,3 +66,5 @@ name = "wintun" clone_url = "https://git.zx2c4.com/wintun" owner = "Jason A. Donenfeld" desc = "Layer 3 TUN Driver for Windows" +# You can put repositories in a subdirectory: +dir = "wireguard" diff --git a/test/integration/example/test.sh b/test/integration/example/test.sh index b8135f5..ee5656d 100755 --- a/test/integration/example/test.sh +++ b/test/integration/example/test.sh @@ -121,13 +121,13 @@ test_ssh() { setup_ssh cgitize verify_repos \ - lens \ - cef \ - wintun \ + lens \ + chromiumembedded/cef \ + wireguard/wintun \ github-dir/cgitize-test-repository \ bitbucket-dir/cgitize-test-repository verify_origin lens 'git@github.com:ekmett/lens.git' - verify_origin cef 'git@bitbucket.org:chromiumembedded/cef.git' + verify_origin chromiumembedded/cef 'git@bitbucket.org:chromiumembedded/cef.git' verify_origin github-dir/cgitize-test-repository 'git@github.com:egor-tensin/cgitize-test-repository.git' verify_origin bitbucket-dir/cgitize-test-repository 'git@bitbucket.org:egor-tensin/cgitize-test-repository.git' cleanup @@ -142,13 +142,13 @@ test_https() { setup_https cgitize verify_repos \ - lens \ - cef \ - wintun \ + lens \ + chromiumembedded/cef \ + wireguard/wintun \ github-dir/cgitize-test-repository \ bitbucket-dir/cgitize-test-repository verify_origin lens 'https://github.com/ekmett/lens.git' - verify_origin cef 'https://bitbucket.org/chromiumembedded/cef.git' + verify_origin chromiumembedded/cef 'https://bitbucket.org/chromiumembedded/cef.git' verify_origin github-dir/cgitize-test-repository 'https://github.com/egor-tensin/cgitize-test-repository.git' verify_origin bitbucket-dir/cgitize-test-repository 'https://bitbucket.org/egor-tensin/cgitize-test-repository.git' cleanup @@ -162,8 +162,8 @@ test_one_repo() { setup_https cgitize --repo cef - verify_repos cef - verify_no_repos lens wintun + verify_repos chromiumembedded/cef + verify_no_repos lens wireguard/wintun cleanup } -- cgit v1.2.3