Coverage for portality/ui/debug_toolbar.py: 96%

26 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-19 18:38 +0100

1from flask_debugtoolbar import DebugToolbarExtension 

2from flask_debugtoolbar.panels import DebugPanel 

3 

4from portality.lib import paths 

5 

6 

7class BranchNamePanel(DebugPanel): 

8 name = 'branch_name' 

9 has_content = True 

10 

11 def get_branch_name(self): 

12 _git_head_file = paths.get_project_root().joinpath('.git/HEAD') 

13 if _git_head_file.is_file(): 

14 return (_git_head_file.read_text() 

15 .strip().replace('ref: refs/heads/', '') 

16 .replace('ref: ', '')) 

17 return 'Unknown, git HEAD not found ' 

18 

19 def nav_title(self): 

20 return 'Branch name' 

21 

22 def title(self): 

23 return 'Branch name' 

24 

25 def nav_subtitle(self): 

26 return self.get_branch_name() 

27 

28 def url(self): 

29 return '' 

30 

31 def content(self): 

32 return f'<h1 style="font-size: 30px;">{self.get_branch_name()}</h1>' 

33 

34 

35class DoajDebugToolbar(DebugToolbarExtension): 

36 

37 def _default_config(self, app): 

38 config = super()._default_config(app) 

39 config['DEBUG_TB_PANELS'] += (f'{BranchNamePanel.__module__}.{BranchNamePanel.__name__}',) 

40 return config