From e556aa184c5635bc353309a81a10a016c334e960 Mon Sep 17 00:00:00 2001 From: Yonghee Han Date: Mon, 18 Sep 2017 20:42:44 +0900 Subject: [PATCH] [Github] Add a github item in description Change-Id: Ia172c2a2249f3126937814d31c2e2dbc3b9e5edd --- common/buildservice.py | 6 +++++ common/workflow.py | 7 +++--- job_request.py | 62 ++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/common/buildservice.py b/common/buildservice.py index 6bad21a..78f694b 100644 --- a/common/buildservice.py +++ b/common/buildservice.py @@ -688,6 +688,7 @@ class BuildService(OSC): submitter = saved_info.get('submitter') or '' download_num = saved_info.get('download_num') or int(0) submissions = saved_info.get('submissions') or [] + github = saved_info.get('github') or [] saved_info.update(info) if 'projects' in info: saved_info['projects'] = list(set(projects + info['projects'])) @@ -721,11 +722,16 @@ class BuildService(OSC): for s in info['submissions']: submissions = filter(lambda a: a != s, submissions) saved_info['submissions'] = submissions + info['submissions'] + if 'github' in info: + for s in info['github']: + github = filter(lambda a: a != s, github) + saved_info['github'] = github + info['github'] self.set_description(json.dumps(saved_info), prj, pkg) def get_info(self, prj, pkg=None): """Get info dictionary, saved in description.""" + for count in (1, 2, 3): description = self.get_description(prj, pkg) if not description: continue diff --git a/common/workflow.py b/common/workflow.py index 451ab32..a62d499 100644 --- a/common/workflow.py +++ b/common/workflow.py @@ -540,9 +540,10 @@ def create_project(build, obs_project, submit_list, mode=MODE_NORMAL): } # Enable Github Connection if submit_list[0].get('github_type'): - info['github_type'] = {'github_fetch_url': submit_list[0].get('github_fetch_url'), \ - 'github_full_name': submit_list[0].get('github_full_name'), \ - } + info['github'] = [] + item = {'project': git_project, \ + 'url': submit_list[0].get('github_fetch_url')} + info['github'].append(item) if mode == MODE_SRSYNC: submissions = [] diff --git a/job_request.py b/job_request.py index bba4e12..3c5c738 100644 --- a/job_request.py +++ b/job_request.py @@ -55,17 +55,38 @@ def request_url(request_id): else: return '%s' % (request_id) -def tag_info(prj, tag): +def tag_info(prj, tag, event_fields=None): """Get git tag info""" + git_cache = os.path.join(os.getenv('GIT_CACHE_DIR')) + + if event_fields.get('github'): + github = event_fields.get('github') + prjdir = os.path.join(git_cache, prj) + giturl = None + git_cache_dir = None + for item in github: + if prj in item.get('project'): + giturl = github.get('url') + gitorg = giturl.split(':')[1] + git_full_name = os.path.join(gitorg, prj) + prjdir = os.path.join(git_cache, git_full_name) + git_cache_dir = os.path.join(git_cache, gitorg) + break + else: # GERRIT + prjdir = os.path.join(git_cache, prj) + giturl = None + git_cache_dir = None + try: - mygit = Git('%s.git' % os.path.join(os.getenv('GIT_CACHE_DIR'), prj)) + mygit = Git(prjdir) if mygit.find_tag(tag): return mygit.get_tag(tag) except GitRepositoryError: # tag is not found, try to clone # clone gerrit project to local dir - if not clone_gitproject(prj, os.path.join(os.getenv('WORKSPACE'), prj)): + if not clone_gitproject(prj, os.path.join(os.getenv('WORKSPACE'), prj), \ + giturl=giturl, git_cache_dir=git_cache_dir): exit(1) mygit = Git(os.path.join(os.getenv('WORKSPACE'), prj)) @@ -151,7 +172,7 @@ def obs_git_data(event_fields): obs_req_pkg_name = event_fields['packages'][projects.index(project)] except Exception as err: print 'Warning: not able to find package name from description' - tag = tag_info(project, entry['GIT_TAG']) + tag = tag_info(project, entry['GIT_TAG'], event_fields) if tag: tag.update({'GIT_PROJECT': project, 'OBS_REQ_PKG_SRC': obs_req_pkg_name, @@ -429,6 +450,9 @@ def main(): # SR-SYNC: SR listing and its pure git repos. if 'submissions' in saved_info: submissions = unicode_to_str(saved_info['submissions']) + if 'github' in saved_info: + event_fields['github'] = saved_info.get('github') + except Exception as err: print 'Not able to fetch package list from OBS %s' % err event_fields['packages'] = [] @@ -487,14 +511,34 @@ def main(): event_fields['state'] == 'revoked')): notify_submiter(event_fields, data) + git_cache = os.path.join(os.getenv('GIT_CACHE_DIR')) + # Enable Github Connection + if event_fields.get('github'): + github = event_fields.get('github') + prjdir = os.path.join(git_cache, data['GIT_PROJECT']) + giturl = None + git_cache_dir = None + for item in github: + if data['GIT_PROJECT'] in item.get('project'): + giturl = item.get('url') + gitorg = giturl.split(':')[1] + git_full_name = os.path.join(gitorg, data['GIT_PROJECT']) + prjdir = os.path.join(git_cache, git_full_name) + git_cache_dir = os.path.join(git_cache, gitorg) + print "GITHUB prjdir=%s git_cache_dir=%s" %(prjdir, git_cache_dir) + break + else: # GERRIT + prjdir = os.path.join(git_cache, data['GIT_PROJECT']) + giturl = None + git_cache_dir = None + print "GERRIT prjdir=%s git_cache_dir=%s" %(prjdir, git_cache_dir) try: - gitprj = Git('%s/%s.git' % (os.getenv('GIT_CACHE_DIR'), - data['GIT_PROJECT'])) + gitprj = Git(prjdir) except GitRepositoryError, err: # clone project to local workspace if it doesn't exist in git cache - if not clone_gitproject(data['GIT_PROJECT'], - os.path.join(os.getenv('WORKSPACE'), - data['GIT_PROJECT'])): + if not clone_gitproject(data['GIT_PROJECT'], \ + os.path.join(os.getenv('WORKSPACE'), data['GIT_PROJECT']), \ + giturl=giturl, git_cache_dir=git_cache_dir): return -1 gitprj = Git('%s/%s' % (os.getenv('WORKSPACE'), data['GIT_PROJECT'])) -- 2.7.4