From f699ccaeba7db618b0c7e18f633ef8431a6fbd16 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Mon, 27 Aug 2012 15:15:15 +0800 Subject: [PATCH] Update _gerritinfo file when submit to OBS _gerritinfo will follow below format: PROJECT: ${gerrit_project} COMMIT_ID: ${commit_id} --- common/git.py | 2 +- submitobs.py | 14 ++++++++++++++ submitobs_orig.py | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/common/git.py b/common/git.py index 6049e9d..0abb3d7 100644 --- a/common/git.py +++ b/common/git.py @@ -78,7 +78,7 @@ class Git: def rev_parse(self, name, *args): """ Find the SHA1 of a given name commit id""" - options = ["--quiet", "--verify", name] + options = ["--quiet", "--verify", "%s^{commit}" % name] options += list(args) with Workdir(self.path): ret, outs = self._exec_git('rev-parse', options) diff --git a/submitobs.py b/submitobs.py index c6f8bcc..50109d9 100755 --- a/submitobs.py +++ b/submitobs.py @@ -141,6 +141,17 @@ def update_changelog(obspkg, gitprj, tagname): for line in lines: log.write(line) +def update_gerritinfo(obspkg, gitprj, commitid): + """ update the _gerritinfo file""" + workdingdir = obspkg.get_workdir() + + lines = 'PROJECT: %s\nCOMMIT_ID: %s' % (gitprj, commitid) + print '_gerritinfo:\n', lines + gerritinfo = os.path.join(workdingdir, '_gerritinfo') + with open(gerritinfo, 'w') as log: + for line in lines: + log.write(line) + def end(result = 'success'): print 'execute result: %s' % result db = mysql.Database(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DB_NAME) @@ -313,6 +324,9 @@ if __name__ == '__main__': # update changelog with git tag info update_changelog(localpkg, mygit, tag) + # update gerritinfo with git info + update_gerritinfo(localpkg, GERRIT_PROJECT, GERRIT_PATCHSET_REVISION) + localpkg.update_local() retry_count = 3 diff --git a/submitobs_orig.py b/submitobs_orig.py index 5e8d7cf..6695b03 100755 --- a/submitobs_orig.py +++ b/submitobs_orig.py @@ -75,6 +75,17 @@ def sendmail(subject, body, mail_from, mail_to): for key in mail_env.keys(): f.write('%s=%s\n' %(key, mail_env[key])) +def update_gerritinfo(obspkg, gitprj, commitid): + """ update the _gerritinfo file """ + workdingdir = obspkg.get_workdir() + + lines = 'PROJECT: %s\nCOMMIT_ID: %s' % (gitprj, commitid) + print '_gerritinfo:\n', lines + gerritinfo = os.path.join(workdingdir, '_gerritinfo') + with open(gerritinfo, 'w') as log: + for line in lines: + log.write(line) + def end(result = 'success'): print 'execute result: %s' % result # cleanup workspace @@ -220,6 +231,10 @@ if __name__ == '__main__': localpkg.remove_all() for myfile in os.listdir(tarballdir): shutil.copy2(os.path.join(tarballdir, myfile), os.path.join(oscworkdir, myfile)) + + # update gerritinfo with git info + update_gerritinfo(localpkg, GERRIT_PROJECT, GERRIT_PATCHSET_REVISION) + localpkg.update_local() retry_count = 3 -- 2.7.4