Coverage for heliumcli/actions/listbuilds.py: 62.50%

32 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-01 17:33 +0000

1import os 

2 

3import git 

4 

5from .. import utils 

6 

7__author__ = "Alex Laird" 

8__copyright__ = "Copyright 2018, Helium Edu" 

9__version__ = "1.5.0" 

10 

11 

12class ListBuildsAction: 

13 def __init__(self): 

14 self.name = "list-builds" 

15 self.help = "List available builds" 

16 

17 def setup(self, subparsers): 

18 parser = subparsers.add_parser(self.name, help=self.help) 

19 parser.add_argument("--latest", action="store_true", help="Only list the latest build") 

20 parser.set_defaults(action=self) 

21 

22 def run(self, args): 

23 config = utils.get_config() 

24 projects_dir = utils.get_projects_dir() 

25 

26 if config["projectsRelativeDir"] != ".": 

27 root_dir = os.path.abspath(os.path.join(projects_dir, "..")) 

28 if os.path.exists(os.path.join(root_dir, ".git")): 

29 print(utils.get_repo_name(root_dir, config["remoteName"])) 

30 

31 repo = git.Repo(root_dir) 

32 repo.git.fetch(tags=True, prune=True) 

33 version_tags = utils.sort_tags(repo.tags) 

34 

35 if len(version_tags) == 0: 

36 print("No version tags have been created yet.") 

37 

38 return 

39 

40 if args.latest: 

41 print(version_tags[-1]) 

42 else: 

43 for tag in version_tags: 

44 print(tag) 

45 

46 print("")