feat(fork_flow): step3 fast smoke testing

This commit is contained in:
江畅
2020-08-25 11:40:15 +08:00
parent 75a9490ad9
commit eca7ced6c8
3 changed files with 51 additions and 7 deletions
+16 -5
View File
@@ -1393,12 +1393,16 @@ class Project(object):
if not pushurl:
pushurl = self.manifest.manifestProject.config.GetString('repo.pushurl')
if not pushurl:
pushurl = branch.remote.name
# 从user_info中提取namespace进行push_url的set
html_url = self._UserUrl()
namespace = self._GiteeNamespace(html_url)
pushurl = 'git@gitee.com:' + '/' + namespace
# pushurl = branch.remote.name
else:
pushurl = pushurl.rstrip('/') + '/' + self.name
remote = self.manifest.remotes.get(branch.remote.name)
if remote and remote.autodotgit is not False:
pushurl += ".git"
# remote = self.manifest.remotes.get(branch.remote.name)
# if remote and remote.autodotgit is not False:
# pushurl += ".git"
cmd = ['push']
if opt.force:
@@ -1472,8 +1476,9 @@ class Project(object):
post_url = '/'.join([gitee_url, namespace, self.name, 'forks'])
payload = {"access_token": token}
r = requests.post(post_url, json=payload)
msg = r.json()
# check r.msg
return r.status_code
return r.status_code, msg
def _GiteeNamespace(self, url=None):
"""
@@ -1492,6 +1497,12 @@ class Project(object):
# print("remote.url: %s doesn't belong to gitee" % self.remote.url)
raise PullRequestError("remote.url: %s doesn't belong to gitee" % self.remote.url)
def _UserUrl(self, token):
gitee_url = 'https://gitee.com/api/v5/user'
payload = {'access_token': token}
r = requests.get(gitee_url, json=payload)
return r.json()['html_url']
def UploadForReview(self, branch=None,
people=([], []),
dryrun=False,
+13
View File
@@ -299,6 +299,19 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
branch.name,
str(branch.error)),
file=sys.stderr)
status_code, msg = branch.project.ForkProject()
if status_code == 201:
print('[FORK OK] %-15s %s' % (
branch.project.relpath + '/',
branch.name),
file=sys.stderr)
else:
print(('[FORK FAILED] %-15s %-15s') % (
branch.project.relpath + '/',
branch.name,
str(msg['message'])),
file=sys.stderr)
if branch.have_pr_errors:
if not branch.pull_requested:
if len(str(branch.pr_error)) <= 30:
+22 -2
View File
@@ -24,6 +24,7 @@ from git_command import git
import gitc_utils
from progress import Progress
from project import SyncBuffer
from git_config import GitConfig
class Start(Command):
@@ -54,6 +55,7 @@ revision specified in the manifest.
if not git.check_ref_format('heads/%s' % nb):
self.OptionParser.error("'%s' is not a valid name" % nb)
def Execute(self, opt, args):
nb = args[0]
err = []
@@ -91,11 +93,29 @@ revision specified in the manifest.
if not opt.all:
fork_success_count = 0
token = self.manifest.manifestProject.config.GetString('repo.token')
if not token:
token = GitConfig.ForUser().GetString('repo.token')
if not token:
sys.stderr.write('repo.token is None, Please set it, you need `repo config -h`\n')
sys.exit(1)
pushurl = self.manifest.manifestProject.config.GetString('repo.pushurl')
success_msg = None
for project in all_projects:
status_code = project.ForkProject(token)
status_code, msg = project.ForkProject(token)
if status_code == 201:
fork_success_count += 1
print("fork_success: {}".format(fork_success_count))
if not success_msg:
success_msg = msg
if fork_success_count > 0 and pushurl is None:
# 初始化push_url
# 把response中的信息存到push_url中
ssh_url = success_msg['namespace']['ssh_url']
pushurl = ssh_url.split('/')[0]
self.manifest.manifestProject.config.SetString('repo.pushurl', pushurl)
print("fork_success: %s" %fork_success_count)
# 展示fork状态,失败、成功、已存在