9
9
import re
10
10
import tempfile
11
11
import pprint
12
- import getpass
13
12
import logging
14
13
15
14
from git import Repo , GitError
@@ -53,6 +52,7 @@ def __init__(self,
53
52
54
53
self .conf_name = config
55
54
self .rebuild_reason = rebuild_reason
55
+ self .gitlab_usage = None
56
56
self .do_image = None
57
57
self .exclude_image = None
58
58
self .do_set = None
@@ -119,10 +119,8 @@ def _setup_args(self, args):
119
119
self .rebuild_reason = args .rebuild_reason
120
120
if getattr (args , 'check_script' , None ) is not None and args .check_script :
121
121
self .check_script = args .check_script
122
- if getattr (args , 'disable_klist' , None ) is not None and args .disable_klist :
123
- self .disable_klist = args .disable_klist
124
- if getattr (args , 'latest_release' , None ) is not None and args .latest_release :
125
- self .latest_release = args .latest_release
122
+ self .disable_klist = args .disable_klist
123
+ self .latest_release = args .latest_release
126
124
if getattr (args , 'output_file' , None ) is not None and args .output_file :
127
125
self .output_file = args .output_file
128
126
@@ -150,7 +148,7 @@ def git_ops(self):
150
148
if not self ._git_ops :
151
149
self ._git_ops = GitOperations (self .base_image , self .conf ,
152
150
self .rebuild_reason ,
153
- self .logger .getChild ("- git-ops" ))
151
+ self .logger .getChild ("git-ops" ))
154
152
return self ._git_ops
155
153
156
154
@property
@@ -449,16 +447,16 @@ def set_repo_url(self, repo_url):
449
447
450
448
def list_images (self ):
451
449
"""Prints list of images that we work with"""
452
- for i in self ._get_images ():
453
- self .logger .info (i ["component" ])
450
+ for image in self ._get_images ():
451
+ self .logger .info (image ["component" ])
454
452
455
453
def print_upstream (self ):
456
454
"""Prints the upstream name and url for images used in config"""
457
- for i in self ._get_images ():
455
+ for image in self ._get_images ():
458
456
ups_name = re .search (r".*\/([a-zA-Z0-9-]+).git" ,
459
- i ["git_url" ]).group (1 )
460
- msg = f"{ i .get ('component' )} { i .get ('name' )} { ups_name } " \
461
- f"{ i .get ('git_url' )} { i .get ('git_path' )} { i .get ('git_branch' )} "
457
+ image ["git_url" ]).group (1 )
458
+ msg = f"{ image .get ('component' )} { image .get ('name' )} { ups_name } " \
459
+ f"{ image .get ('git_url' )} { image .get ('git_path' )} { image .get ('git_branch' )} "
462
460
self .logger .info (msg )
463
461
464
462
def show_config_contents (self ):
@@ -502,17 +500,14 @@ def pull_downstream(self):
502
500
Additionally runs a script against each repository if check_script is set,
503
501
checking its exit value.
504
502
"""
505
- self ._check_kerb_ticket ()
506
- tmp = self ._get_tmp_workdir ()
507
- self ._change_workdir (tmp )
508
- images = self ._get_images ()
509
- for i in images :
510
- self .distgit ._clone_downstream (i ["component" ], i ["git_branch" ])
503
+ tmp , images = self .preparation ()
504
+ for image in images :
505
+ self .distgit ._clone_downstream (image ["component" ], image ["git_branch" ])
511
506
# If check script is set, run the script provided for each config entry
512
507
if self .check_script :
513
- for i in images :
514
- self .distgit .check_script (i ["component" ], self .check_script ,
515
- i ["git_branch" ])
508
+ for image in images :
509
+ self .distgit .check_script (image ["component" ], self .check_script ,
510
+ image ["git_branch" ])
516
511
517
512
def pull_upstream (self ):
518
513
"""
@@ -521,24 +516,19 @@ def pull_upstream(self):
521
516
Additionally runs a script against each repository if check_script is set,
522
517
checking its exit value.
523
518
"""
524
- tmp = self ._get_tmp_workdir ()
525
- self ._change_workdir (tmp )
526
- images = self ._get_images ()
527
- for i in images :
519
+ tmp , images = self .preparation ()
520
+ for image in images :
528
521
# Use unversioned name as a path for the repository
529
- ups_name = i ["name" ].split ('-' )[0 ]
530
- self .distgit ._clone_upstream (i ["git_url" ],
531
- ups_name ,
532
- commands = i ["commands" ])
522
+ ups_name = image ["name" ].split ('-' )[0 ]
523
+ self .git_ops .clone_upstream (image ["git_url" ], ups_name , commands = image ["commands" ])
533
524
# If check script is set, run the script provided for each config entry
534
525
if self .check_script :
535
- for i in images :
536
- ups_name = i ["name" ].split ('-' )[0 ]
537
- self .distgit .check_script (i ["component" ], self .check_script ,
538
- os .path .join (ups_name , i ["git_path" ]))
526
+ for image in images :
527
+ ups_name = image ["name" ].split ('-' )[0 ]
528
+ self .distgit .check_script (image ["component" ], self .check_script ,
529
+ os .path .join (ups_name , image ["git_path" ]))
539
530
540
- def push_changes (self ):
541
- """Pushes changes for all components into downstream dist-git repository"""
531
+ def preparation (self ):
542
532
# Check for kerberos ticket
543
533
self ._check_kerb_ticket ()
544
534
tmp = self ._get_tmp_workdir (setup_dir = False )
@@ -547,31 +537,22 @@ def push_changes(self):
547
537
raise RebuilderError (msg )
548
538
self ._change_workdir (tmp )
549
539
images = self ._get_images ()
540
+ return tmp , images
541
+
542
+ def push_changes (self ):
543
+ """Pushes changes for all components into downstream dist-git repository"""
550
544
545
+ tmp , images = self .preparation ()
551
546
self .distgit .push_changes (tmp , images )
552
547
553
548
def dist_git_rebase (self ):
554
549
"""
555
550
Do a rebase against a new base/s2i image.
556
551
Does not pull in upstream changes of layered images.
557
552
"""
558
- self .dist_git_changes (rebase = True )
559
-
560
- def dist_git_changes (self , rebase : bool = False ):
561
- """Method to merge changes from upstream into downstream
553
+ self .dist_git_merge_changes (rebase = True )
562
554
563
- Pulls both downstream and upstream repositories into a temporary directory.
564
- Merge is done by copying tracked files from upstream into downstream.
565
-
566
- Args:
567
- rebase (bool, optional): Specifies whether a rebase should be done instead.
568
- """
569
- # Check for kerberos ticket
570
- self ._check_kerb_ticket ()
571
- tmp = self ._get_tmp_workdir ()
572
- self ._change_workdir (tmp )
573
- images = self ._get_images ()
574
- self .distgit .dist_git_changes (images , rebase )
555
+ def git_changes_report (self , tmp ):
575
556
self .logger .info ("\n Git location: " + tmp )
576
557
if self .args :
577
558
tmp_str = ' --tmp ' + self .tmp_workdir if self .tmp_workdir else '"'
@@ -583,13 +564,23 @@ def dist_git_changes(self, rebase: bool = False):
583
564
"cwt git push && cwt build"
584
565
"[base/core/s2i] --repo-url link-to-repo-file" )
585
566
567
+ def dist_git_merge_changes (self , rebase : bool = False ):
568
+ """Method to merge changes from upstream into downstream
569
+
570
+ Pulls both downstream and upstream repositories into a temporary directory.
571
+ Merge is done by copying tracked files from upstream into downstream.
572
+
573
+ Args:
574
+ rebase (bool, optional): Specifies whether a rebase should be done instead.
575
+ """
576
+ tmp , images = self .preparation ()
577
+ self .distgit .dist_git_merge_changes (images , rebase )
578
+ self .git_changes_report (tmp = tmp )
579
+
586
580
def merge_future_branches (self ):
587
581
"""Merges current branch with future branches"""
588
582
# Check for kerberos ticket
589
- self ._check_kerb_ticket ()
590
- tmp = self ._get_tmp_workdir ()
591
- self ._change_workdir (tmp )
592
- images = self ._get_images ()
583
+ tmp , images = self .preparation ()
593
584
self .distgit .merge_future_branches (images )
594
585
595
586
def show_git_changes (self , components : List = None ):
@@ -599,9 +590,8 @@ def show_git_changes(self, components: List = None):
599
590
components (list of str, optional): List of components to show changes for
600
591
Walks through all downstream repositories and calls 'git-show' on each of them.
601
592
"""
593
+ tmp , _ = self .preparation ()
602
594
if not components :
603
595
images = self ._get_images ()
604
- components = [i ["component" ] for i in images ]
605
- tmp = self ._get_tmp_workdir ()
606
- self ._change_workdir (tmp )
596
+ components = [image ["component" ] for image in images ]
607
597
self .distgit .show_git_changes (tmp , components )
0 commit comments