"""
return filter(None, self._exec_git('ls-files')[1].splitlines())
- def rev_parse(self, name):
+ def rev_parse(self, name, *args):
""" Find the SHA1 of a given name commit id"""
- options = [ "--quiet", "--verify", name ]
- cmd = ['git', 'rev-parse']
- ret, commit = runner.runtool(' '.join(cmd + options))
- if ret == 0:
- return commit.strip()
+ options = ["--quiet", "--verify", name]
+ options += list(args)
+ with Workdir(self.path):
+ ret, outs = self._exec_git('rev-parse', options)
+ if not ret:
+ return outs.strip()
else:
return None
ret, outs = self._exec_git('show', list(args))
if not ret:
return outs.splitlines()
+ else:
+ return None
def fetch(self, *args):
"""Download objects and refs from another repository
ret, outs = self._exec_git('describe', list(args))
if not ret:
return outs.strip()
+ else:
+ return None
def pull(self, *args):
"""Fetch from and merge with another repository or a local branch
ret, outs = self._exec_git('format-patch', list(args))
if not ret:
return outs.splitlines()
+ else:
+ return None
def branch_contains(self, cmitid):
with Workdir(self.path):
from envparas import *
import gbp.rpm
-mappingprj = 'scm/git-obs-mapping'
gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
packagingdir = utils.parse_link('%s/%s' % (prjdir, 'packaging'))
print('packaging dir is %s/%s' % (prjdir, packagingdir))
+ '''
# Only when there is tag submit/*, it's for submit
needsr = False
print('\n------------------------\nCheck whether contain submit tag')
- tag = mygit.describe('--exact-match --match "submit/*"', GERRIT_PATCHSET_REVISION)
+ if GERRIT_BRANCH == 'master':
+ branch = 'trunk'
+ else:
+ branch = GERRIT_BRANCH
+ tag = mygit.describe('--exact-match --match "submit/%s/*"' % branch, GERRIT_PATCHSET_REVISION)
if tag:
+ print 'submit tag : %s, on branch %s' % (tag, GERRIT_BRANCH)
needsr = True
print('submitted to obs: %s' % needsr)
+ '''
mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, GERRIT_BRANCH)
print 'git-obs-mapping:', mapping
specfile = '%s/%s/%s.spec' % (prjdir, packagingdir, prj)
print('specfile %s' % specfile)
+ '''
if not obs_stg_prj or needsr:
print('check obs target: %s' % obs_dest_prj)
obstarget.append(obs_dest_prj)
obsprj = obspkg.ObsProject(obs_dest_prj, apiurl = OBS_API_URL, oscrc = OBS_OSCRC_PATH)
if check_obs_newpkg(obsprj, spec.name):
newpkg = True
+ '''
if specfile not in speclist:
speclist.append(specfile)
if not mapping:
checkobsmsg = '[IMPORTANT NOTICE]: The change for %s branch will not be submitted to OBS according configuration in gerrit scm/git-obs-mapping project. If needed, please modify scm/git-obs-mapping to enable submission to OBS.' % GERRIT_BRANCH
+ '''
elif not obstarget:
- checkobsmsg = '[IMPORTANT NOTICE]: This change will not be submitted to OBS. If want to trigger submission to OBS, please create an annotated tag submit/$(tizen_version)/$(date -u +%F.%H%M%S) on this commit and push to gerrit.'
+ checkobsmsg = '[IMPORTANT NOTICE]: This change will not be submitted to OBS. If want to trigger submission to OBS, please use gbs submit, which will create an annotated tag submit/$(tizen_version)/$(date -u +%F.%H%M%S) on this commit and push to gerrit.'
else:
checkobsmsg = '[IMPORTANT NOTICE]: '
if newpkg:
checkobsmsg += '[New Package] '
checkobsmsg += 'This change will be submitted to OBS %s project!!!' % ' '.join(obstarget)
+ '''
if missedspec:
checkspecmsg += '\n\nError: Can not find %s under packaging directory!' % ' '.join(missedspec)
print('\n-------------------------------\ncheck obs target result:\n%s' % checkobsmsg)
+ if checkobsmsg:
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkobsmsg))
print('\n-------------------------------\ncheck specfile result:\n%s' % checkspecmsg)
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkobsmsg))
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkspecmsg))
+ if checkspecmsg:
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkspecmsg))
end()
from envparas import *
import errors
import mysql
+from send_mail import sendmail
+
import gbp.rpm
-mappingprj = 'scm/git-obs-mapping'
-rpmlintprj = 'scm/rpmlint-config'
giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
ret = { 'rc' : {'success' : 0, 'failure' : 0, 'retry' : 1},
end('retry')
# if scm/rpmlint-config changed, update HOME/.config/rpmlint
+ print '\n', GERRIT_PROJECT, rpmlintprj
if GERRIT_PROJECT == rpmlintprj:
if not os.path.exists('%s/.config' % JENKINS_HOME):
os.makedirs('%s/.config' % JENKINS_HOME)
mygit = git.Git(prjdir)
+ checktagmsg = ''
if GERRIT_EVENT_TYPE == "REF_UPDATED":
- branchs = mygit.branch_contains(GERRIT_REFNAME)
- if branchs:
- # the tagged commit has been merged on gerrit
- mygit.checkout(GERRIT_REFNAME)
- tag = GERRIT_REFNAME[len('refs/tags/'):]
- print 'submit tag : %s, which belongs to branch %s' % (tag, ''.join(branchs))
+ tag = GERRIT_REFNAME[len('refs/tags/'):]
+ if tag.find('/',len('submit/')) != -1:
+ branch = tag[len('submit/'):tag.find('/',len('submit/'))]
+ if branch == 'trunk':
+ branch = 'master'
+ branchs = mygit.branch_contains(GERRIT_REFNAME)
+ if branchs:
+ # the tagged commit has been merged on gerrit
+ if branch not in branchs:
+ checktagmsg = 'Tag %s only can be used to submit commit on %s branch to OBS. Please check and re-submit another proper tag. Recommend to use "gbs submit" to do this.' % (tag, branch)
+ else:
+ GERRIT_BRANCH = branch
+ print 'submit tag : %s, on branch %s' % (tag, branch)
+ else:
+ # The tagged commmit still open, abort submit this time
+ print '\nThis change is still open in gerrit, exit now'
+ checktagmsg = 'The commit tag %s attached is still open in gerrit. After reviewer accpet this commit, it will be submitted to OBS corresponding project.' % tag
else:
- # The tagged commmit still open, abort submit this time
- print '\nThis change is still open in gerrit, exit now'
- end('success')
+ print 'tag %s don\'t match the name format, exit now' % tag
+ checktagmsg = 'Backend service cannot find branch info in tag %s. Please create tag "submit/<branchname>/<date.time>" and submit to gerrit. Recommend to use "gbs submit" to do this.' % tag
else:
# Only when there is tag submit/*, it's for submit
- tag = mygit.describe('--exact-match --match "submit/*"', GERRIT_PATCHSET_REVISION)
- if tag:
- mygit.checkout(GERRIT_PATCHSET_REVISION)
- branchs = [GERRIT_BRANCH]
- print 'submit tag : %s, which belongs to branch %s' % (tag, ''.join(branchs))
+ if GERRIT_BRANCH == 'master':
+ branch = 'trunk'
else:
- print '\nThis change don\'t contain submit/* tag, exit now'
+ branch = GERRIT_BRANCH
+ tag = mygit.describe('--exact-match --match "submit/%s/*"' % branch, GERRIT_PATCHSET_REVISION)
+ if tag:
+ print 'submit tag : %s, on branch %s' % (tag, GERRIT_BRANCH)
+ else:
+ print '\nThis change don\'t contain submit/*/* tag, exit now'
end('success')
+ commitinfo = mygit.get_commit_info(tag)
+ tagger = mygit.get_tagger(tag)
+ if not tagger:
+ print '\ntag %s is not annotated tag, exit now' % tag
+ end('failure')
+ if checktagmsg:
+ print checktagmsg
+ checktagmsg = 'Hi, %s,\n\n' % tagger['author'] + checktagmsg + '\n\n----------------------------------------------------------------\nAutomatically generated by backend service.\nPlease DO NOT Reply!'
+ sendmail('[submit to OBS failed]: tag %s' % tag, checktagmsg, FROM_EMAIL, tagger['email'])
+ end('failure')
+
packagingdir = utils.parse_link('%s/%s' % (prjdir, 'packaging'))
print('packaging dir is %s/%s' % (prjdir, packagingdir))
- commitinfo = mygit.get_commit_info(tag)
- tagger = mygit.get_tagger(tag)
msg = 'Tag: %s\nCommit: %s %s\nSubmitter: %s <%s>' % (tag, commitinfo['id'], commitinfo['subject'], tagger['author'], tagger['email'])
- mapping = []
- for br in branchs:
- mapping += utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, br)
+ mygit.checkout(tag)
+
+ mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, GERRIT_BRANCH)
print 'git-obs-mapping:', mapping
reqlist = []
end('retry')
# post sr info back to gerrit
- if GERRIT_EVENT_TYPE == "REF_UPDATED":
- gerritinfo = utils.get_gerrit_info(GERRIT_PROJECT, commitinfo['id'])
- print 'gerritinfo', gerritinfo
- if gerritinfo:
- GERRIT_CHANGE_NUMBER = gerritinfo['changenum']
- GERRIT_PATCHSET_NUMBER = gerritinfo['patchsetnum']
-
- if GERRIT_CHANGE_NUMBER and GERRIT_CHANGE_NUMBER:
- comment = 'A request has been created to submit this commit to OBS %s project.\n- Submitter: %s <%s>\nTag: %s\nRequest ID: %s' % (' '.join(dstprjlist), tagger['author'], tagger['email'], tag, ' '.join(reqlist))
- print '%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment)
- runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment))
- else:
- print 'GERRIT_CHANGE_NUMBER %s and GERRIT_CHANGE_NUMBER %s is empty.' % (GERRIT_CHANGE_NUMBER, GERRIT_CHANGE_NUMBER)
+ if reqlist:
+ if GERRIT_EVENT_TYPE == "REF_UPDATED":
+ gerritinfo = utils.get_gerrit_info(GERRIT_PROJECT, commitinfo['id'])
+ print 'gerritinfo', gerritinfo
+ if gerritinfo:
+ GERRIT_CHANGE_NUMBER = gerritinfo['changenum']
+ GERRIT_PATCHSET_NUMBER = gerritinfo['patchsetnum']
+
+ requrl = ''
+ for req in reqlist:
+ requrl += ' %s/request/show/%s' % (OBS_URL, req)
+ comment = 'A request has been created to submit this commit to OBS %s project.\n- Commit: %s %s\n- Tag: %s\n- Submitter: %s <%s>\n- Request URL:%s' % (' '.join(dstprjlist), commitinfo['id'], commitinfo['subject'], tag, tagger['author'], tagger['email'], requrl)
+
+ if GERRIT_CHANGE_NUMBER and GERRIT_CHANGE_NUMBER:
+ print '%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment)
+ runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment))
+ else:
+ print 'GERRIT_CHANGE_NUMBER %s and GERRIT_CHANGE_NUMBER %s is empty.' % (GERRIT_CHANGE_NUMBER, GERRIT_CHANGE_NUMBER)
+
+ comment = 'Hi, %s,\n\n' % tagger['author'] + comment + '\n\n----------------------------------------------------------------\nAutomatically generated by backend service.\nPlease DO NOT Reply!'
+ sendmail('[submit to OBS success]: tag %s' % tag, comment, FROM_EMAIL, tagger['email'])
+
end('success')