Skip to content

Commit

Permalink
Merge pull request #36 from gridhead/repotest
Browse files Browse the repository at this point in the history
Add some tests for the repository assets wrangling options
  • Loading branch information
gridhead authored Oct 16, 2023
2 parents fec7463 + 218b4ff commit ddc206b
Show file tree
Hide file tree
Showing 6 changed files with 518 additions and 80 deletions.
16 changes: 13 additions & 3 deletions protop2g/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,42 +97,47 @@ def main(srce, dest, pkey, gkey, fusr, tusr):
@click.option(
"-s",
"--status",
"status",
type=click.Choice(["OPEN", "SHUT", "FULL"], case_sensitive=False),
help="Extract issue tickets of the mentioned status",
multiple=False,
default="OPEN",
)
@click.option(
"-r",
"--ranges",
"ranges",
nargs=2,
help="Extract issue tickets in the mentioned ranges",
default=None,
)
@click.option(
"-p",
"--select",
"select",
type=str,
help="Extract issue tickets of the selected numbers",
default=None,
)
@click.option(
"-c",
"--comments",
"comments",
help="Transfer all the associated comments",
default=False,
is_flag=True,
)
@click.option(
"-l",
"--labels",
"labels",
help="Migrate all the associated labels",
default=False,
is_flag=True,
)
@click.option(
"-a",
"--commit",
"commit",
help="Assert issue ticket states as they were",
default=False,
is_flag=True,
Expand Down Expand Up @@ -170,8 +175,13 @@ def main_transfer_tkts(status, select, ranges, comments, labels, commit):
help="Initialize transfer of repository assets",
context_settings={"show_default": True},
)
@click.option("-b", "--brcs", "brcs", multiple=True, help="List of branches to extract")
@click.option("-b", "--brcs", "brcs", type=str, default=None, help="List of branches to extract")
def main_transfer_repo(brcs):
keepbrcs(brcs)
brcslist = []

if brcs is not None:
brcslist = [indx.strip() for indx in brcs.split(",")]

keepbrcs(brcslist)
showstat()
showrepo()
3 changes: 2 additions & 1 deletion protop2g/view/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

def showrepo():
try:
section("Starting migration...")
pushobjc = PushRepo()
section("Attempting source namespace assets clone...")
sclorslt = pushobjc.downsrce()
Expand Down Expand Up @@ -94,6 +95,6 @@ def showrepo():
general("Exception occurred: %s" % str(sclorslt[1]))
sys.exit(1)
except Exception as expt:
failure("Source namespace assets clone failed!")
failure("Migration failed!")
general("Exception occurred: %s" % str(expt))
sys.exit(1)
4 changes: 0 additions & 4 deletions protop2g/work/keep.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ def keepqant(qant):
standard.tktstate = "open"


def keepcmts(comments):
standard.movecmts = comments


def keeptkts(status, tktgroup, comments, labels, commit):
# Vote what kind of issue tickets are to be moved
# Default Open
Expand Down
129 changes: 57 additions & 72 deletions protop2g/work/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ def downsrce(self):
strttime = time.time()
Repo.clone_from(url=self.srce, to_path=self.sloc.name)
stoptime = time.time()
if os.path.exists(os.path.join(self.sloc.name, ".git")):
return True, "%.2f" % (stoptime - strttime)
else:
return False, "UNAVAILABLE"
return True, "%.2f" % (stoptime - strttime)
except Exception as expt:
return False, str(expt)

Expand All @@ -63,86 +60,74 @@ def downdest(self):
strttime = time.time()
Repo.clone_from(url=self.dest, to_path=self.dloc.name)
stoptime = time.time()
if os.path.exists(os.path.join(self.dloc.name, ".git")):
return True, "%.2f" % (stoptime - strttime)
else:
return False, "UNAVAILABLE"
return True, "%.2f" % (stoptime - strttime)
except Exception as expt:
return False, str(expt)

def cbrcsrce(self):
try:
if os.path.exists(os.path.join(self.sloc.name, ".git")):
repoobjc = Repo(path=self.sloc.name)
brcslist = [
refx.name.replace("%s/" % standard.dfremote, "")
for refx in repoobjc.remote(standard.dfremote).refs
]
standard.sbrcavbl = list(brcslist)
return True, brcslist
else:
return False, "Cloned source namespace assets could not be found"
except Exception as expt:
return False, str(expt)
if os.path.exists(os.path.join(self.sloc.name, ".git")):
repoobjc = Repo(path=self.sloc.name)
brcslist = [
refx.name.replace("%s/" % standard.dfremote, "")
for refx in repoobjc.remote(standard.dfremote).refs
]
standard.sbrcavbl = list(brcslist)
return True, brcslist
else:
return False, "Cloned source namespace assets could not be found"

def cbrcdest(self):
try:
if os.path.exists(os.path.join(self.dloc.name, ".git")):
repoobjc = Repo(path=self.dloc.name)
brcslist = [
refx.name.replace("%s/" % standard.dfremote, "")
for refx in repoobjc.remote(standard.dfremote).refs
]
standard.dbrcavbl = list(brcslist)
return True, brcslist
else:
return False, "Cloned destination namespace assets could not be found"
except Exception as expt:
return False, str(expt)
if os.path.exists(os.path.join(self.dloc.name, ".git")):
repoobjc = Repo(path=self.dloc.name)
brcslist = [
refx.name.replace("%s/" % standard.dfremote, "")
for refx in repoobjc.remote(standard.dfremote).refs
]
standard.dbrcavbl = list(brcslist)
return True, brcslist
else:
return False, "Cloned destination namespace assets could not be found"

def tnfsrepo(self):
try:
if os.path.exists(os.path.join(self.sloc.name, ".git")):
strttime = time.time()
repoobjc = Repo(path=self.sloc.name)
repoobjc.create_remote(standard.nrmtname, url=standard.desthuto)
if len(standard.brtocopy) == 0:
standard.tnfsqant = len(standard.sbrcavbl)
tnfswarn(False, standard.tnfsqant)
for brdx in standard.sbrcavbl:
if os.path.exists(os.path.join(self.sloc.name, ".git")):
strttime = time.time()
repoobjc = Repo(path=self.sloc.name)
repoobjc.create_remote(standard.nrmtname, url=standard.desthuto)
if len(standard.brtocopy) == 0:
standard.tnfsqant = len(standard.sbrcavbl)
tnfswarn(False, standard.tnfsqant)
for brdx in standard.sbrcavbl:
repoobjc.git.checkout("%s" % brdx)
repoobjc.git.push(standard.nrmtname, "--set-upstream", brdx, "--force")
tnfsprog(
brdx,
standard.sbrcavbl.index(brdx) + 1,
len(standard.sbrcavbl),
True,
)
standard.tnfsindx += 1
else:
standard.tnfsqant = len(standard.brtocopy)
tnfswarn(True, standard.tnfsqant)
for brdx in standard.brtocopy:
if brdx in standard.sbrcavbl:
repoobjc.git.checkout("%s" % brdx)
repoobjc.git.push(standard.nrmtname, "--set-upstream", brdx, "--force")
tnfsprog(
brdx,
standard.sbrcavbl.index(brdx) + 1,
len(standard.sbrcavbl),
standard.brtocopy.index(brdx) + 1,
len(standard.brtocopy),
True,
)
standard.tnfsindx += 1
else:
standard.tnfsqant = len(standard.brtocopy)
tnfswarn(True, standard.tnfsqant)
for brdx in standard.brtocopy:
if brdx in standard.sbrcavbl:
repoobjc.git.checkout("%s" % brdx)
repoobjc.git.push(standard.nrmtname, "--set-upstream", brdx, "--force")
tnfsprog(
brdx,
standard.brtocopy.index(brdx) + 1,
len(standard.brtocopy),
True,
)
standard.tnfsindx += 1
else:
tnfsprog(
brdx,
standard.brtocopy.index(brdx) + 1,
len(standard.brtocopy),
False,
)
stoptime = time.time()
return True, "%.2f" % (stoptime - strttime)
else:
return False, "Cloned namespace assets could not be found"
except Exception as expt:
return False, str(expt)
else:
tnfsprog(
brdx,
standard.brtocopy.index(brdx) + 1,
len(standard.brtocopy),
False,
)
stoptime = time.time()
return True, "%.2f" % (stoptime - strttime)
else:
return False, "Cloned namespace assets could not be found"
Loading

0 comments on commit ddc206b

Please sign in to comment.