mirror of
https://github.com/lubuntu-team/ci-tooling.git
synced 2025-02-24 08:41:08 +00:00
Add a clone_repository function.
This commit is contained in:
parent
4459f1e196
commit
a98c025718
@ -15,5 +15,38 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import git
|
||||
from os import getenv
|
||||
from yaml import CLoader
|
||||
from yaml import load as yaml_load
|
||||
from shutil import rmtree
|
||||
from tempfile import mkdtemp
|
||||
|
||||
class Generator:
|
||||
def clone_repository(self):
|
||||
# Assuming this is ran inside Jenkins, this fetches the env vars set in
|
||||
# the job config. If those don't exist, we need to throw an error,
|
||||
# because otherwise we have no metadata to actually pull from
|
||||
metadata_url = getenv("METADATA_URL")
|
||||
metadata_repo_name = getenv("METADATA_REPO_NAME")
|
||||
if not metadata_url or metadata_url == "" or not metadata_repo_name \
|
||||
or metadata_repo_name == "":
|
||||
raise ValueError("METADATA_URL and METADATA_REPO_NAME must be set")
|
||||
|
||||
# Create a temporary directory in the most secure manner possible and
|
||||
# clone the metadata, throwing the directory away when we're done
|
||||
try:
|
||||
metadata_loc = mkdtemp()
|
||||
git.Git(metadata_loc).clone(metadata_url)
|
||||
|
||||
# Load ci.conf and parse it
|
||||
with open(metadata_loc + "/" + metadata_repo_name + "/ci.conf") \
|
||||
as metadata_conf_file:
|
||||
metadata_conf = yaml_load(metadata_conf_file, Loader=CLoader)
|
||||
finally:
|
||||
rmtree(metadata_loc)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Hello world!")
|
||||
generator = Generator()
|
||||
generator.clone_repository()
|
||||
|
Loading…
x
Reference in New Issue
Block a user