Update _gerritinfo file when submit to OBS
authorLin Yang <lin.a.yang@intel.com>
Mon, 27 Aug 2012 07:15:15 +0000 (15:15 +0800)
committerLin Yang <lin.a.yang@intel.com>
Tue, 28 Aug 2012 03:23:08 +0000 (11:23 +0800)
_gerritinfo will follow below format:
PROJECT: ${gerrit_project}
COMMIT_ID: ${commit_id}

common/git.py
submitobs.py
submitobs_orig.py

index 6049e9d..0abb3d7 100644 (file)
@@ -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)
index c6f8bcc..50109d9 100755 (executable)
@@ -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
index 5e8d7cf..6695b03 100755 (executable)
@@ -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