Coverage for src/gitlabracadabra/mixins/rename_branches.py: 93%

20 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-14 23:10 +0200

1# 

2# Copyright (C) 2019-2025 Mathieu Parent <math.parent@gmail.com> 

3# 

4# This program is free software: you can redistribute it and/or modify 

5# it under the terms of the GNU Lesser General Public License as published by 

6# the Free Software Foundation, either version 3 of the License, or 

7# (at your option) any later version. 

8# 

9# This program is distributed in the hope that it will be useful, 

10# but WITHOUT ANY WARRANTY; without even the implied warranty of 

11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

12# GNU Lesser General Public License for more details. 

13# 

14# You should have received a copy of the GNU Lesser General Public License 

15# along with this program. If not, see <http://www.gnu.org/licenses/>. 

16 

17import logging 

18 

19from gitlabracadabra.objects.object import GitLabracadabraObject 

20 

21logger = logging.getLogger(__name__) 

22 

23 

24class RenameBranchesMixin(GitLabracadabraObject): 

25 """Object with branches that can be renamed.""" 

26 

27 """_process_rename_branches() 

28 

29 Process the rename_branches param. 

30 """ 

31 

32 def _process_rename_branches(self, param_name, param_value, *, dry_run=False, skip_save=False): 

33 assert param_name == "rename_branches" # noqa: S101 

34 assert not skip_save # noqa: S101 

35 for branch_pair in param_value: 

36 for old_name, new_name in branch_pair.items(): 

37 if new_name not in self._get_current_branches(): 

38 if old_name not in self._get_current_branches(): 

39 logger.info( 

40 "[%s] NOT Renaming branch from %s to %s (old branch not found)", 

41 self._name, 

42 old_name, 

43 new_name, 

44 ) 

45 else: 

46 self._current_branches.append(new_name) 

47 self._current_branches.remove(old_name) 

48 if dry_run: 48 ↛ 49line 48 didn't jump to line 49 because the condition on line 48 was never true

49 logger.info( 

50 "[%s] NOT Renaming branch from %s to %s (dry-run)", self._name, old_name, new_name 

51 ) 

52 else: 

53 logger.info("[%s] Renaming branch from %s to %s", self._name, old_name, new_name) 

54 self._obj.branches.create( 

55 { 

56 "branch": new_name, 

57 "ref": old_name, 

58 } 

59 ) 

60 self._obj.branches.delete(old_name)