!3 优化push流程,高亮fork提示

* use old head
* optimize gitee-pr head
* optimize fork info format
* add stderr
* add fork color
* add confirm to fork repository
* optimize GetPushableBranch
This commit is contained in:
MarineJ
2020-09-09 15:01:08 +08:00
parent c072dfc5a4
commit c1ab24078a
3 changed files with 37 additions and 26 deletions
+7 -2
View File
@@ -112,6 +112,7 @@ class Coloring(object):
self._section = 'color.%s' % section_type
self._config = config
self._out = sys.stdout
self._errout = sys.stderr
on = DEFAULT
if on is None:
@@ -145,13 +146,17 @@ class Coloring(object):
def nl(self):
self._out.write('\n')
def printer(self, opt=None, fg=None, bg=None, attr=None):
def printer(self, opt=None, fg=None, bg=None, attr=None, ot='stdout'):
s = self
c = self.colorer(opt, fg, bg, attr)
def f(fmt, *args):
s._out.write(c(fmt, *args))
return f
def fe(fmt, *args):
s._errout.write(c(fmt, *args))
out_f = f if ot == 'stdout' else fe
return out_f
def nofmt_printer(self, opt=None, fg=None, bg=None, attr=None):
s = self
+10
View File
@@ -1352,6 +1352,16 @@ class Project(object):
if rb.commits:
return rb
return None
def GetPushableBranch(self, branch_name):
"""Get a single pushable branch, or None.
"""
branch = self.GetBranch(branch_name)
base = branch.LocalMerge
if branch.LocalMerge:
rb = ReviewableBranch(self, branch, base)
return rb
return None
def UploadNoReview(self, opt, peoples, branch=None):
"""If not review server defined, uploads the named branch directly to git server.
+20 -24
View File
@@ -21,7 +21,7 @@ import sys
from command import InteractiveCommand
from editor import Editor
from error import UploadError, GitError, PullRequestError, ForkProjectError
from project import ReviewableBranch
from color import Coloring
from pyversion import is_python3
if not is_python3():
@@ -49,6 +49,12 @@ def _SplitUsers(values):
result.extend([s.strip() for s in value.split(',')])
return result
class PushColoring(Coloring):
def __init__(self, config):
Coloring.__init__(self, config, 'status')
self.fork = self.printer('fork', fg='green', ot='stderr')
class Push(InteractiveCommand):
common = True
helpSummary = "Upload changes for create pull requests on Gitee"
@@ -247,6 +253,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
self._UploadAndReport(opt, todo, peoples)
def _UploadAndReport(self, opt, todo, peoples):
out = PushColoring(self.manifest.manifestProject.config)
exist_regex = r'^ 已存在相同源分支.*'
have_errors = False
for branch in todo:
@@ -308,18 +315,19 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
try:
status_code, msg = branch.project.ForkProject()
if status_code == 201:
print('[FORK OK] %-15s %s' % (
hfk = out.fork
fork_info = 'Remote repository is syncing code, please wait for a while'
hfk('[FORK OK] %-15s %-15s (%s) \n' % (
branch.project.relpath + '/',
branch.name),
file=sys.stderr)
branch.name, fork_info))
else:
print(('[FORK FAILED] %-15s %-15s %s') % (
print(('[FORK FAILED] %-15s %-15s (%s)') % (
branch.project.relpath + '/',
branch.name,
unicode(msg['message'])),
file=sys.stderr)
except ForkProjectError as e:
print(('[FORK FAILED] %-15s %-15s %s') % (
print(('[FORK FAILED] %-15s %-15s (%s)') % (
branch.project.relpath + '/',
branch.name,
unicode(e)),
@@ -379,25 +387,13 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
sys.exit(1)
# if not create new branch, check whether branch has new commit.
if branch:
for project in project_list:
branch_tmp = branch
if (not opt.new_branch and
project.GetUploadableBranch(branch) is None):
for project in project_list:
branch_tmp = branch if branch else project.CurrentBranch
if (not opt.new_branch and
project.GetUploadableBranch(branch_tmp) is None):
continue
branch_tmp = project.GetBranch(branch_tmp)
if branch_tmp.LocalMerge:
rb = ReviewableBranch(project, branch_tmp, branch_tmp.LocalMerge)
pending.append((project, [rb]))
else:
for project in project_list:
if (not opt.new_branch and
project.GetUploadableBranch(project.CurrentBranch) is None):
continue
if project.CurrentBranch:
branch = project.GetBranch(project.CurrentBranch)
rb = ReviewableBranch(project, branch, branch.LocalMerge)
rb = project.GetPushableBranch(branch_tmp)
if rb:
pending.append((project, [rb]))
if opt.reviewers: