TPE-244 Adding extra information for SR Sync 03/146303/1
authorhyokeun <hyokeun.jeon@samsung.com>
Mon, 28 Aug 2017 02:40:57 +0000 (11:40 +0900)
committerhyokeun <hyokeun.jeon@samsung.com>
Mon, 28 Aug 2017 02:40:57 +0000 (11:40 +0900)
Change-Id: Ib5ca71c032aedc248e5a606684dd74acaf9e41be

job_buildmonitor.py
job_submit_request_sync.py

index 04cc3ee..dbd08ab 100644 (file)
@@ -2055,6 +2055,43 @@ def sync_package_build_for_sr_detail_sr_stage(git_tag, bm_start_datetime,
             # [1] end stage / [2] start stage
             start_pre_build_for_sr_stage(git_tag, bm_start_datetime,
                                          bm_end_datetime, pre_build_project_id)
+
+def sync_sr_update_comment(sr, email, bm_member_sr_info):
+
+    query = "SELECT id FROM sr_status WHERE sr = %s"
+    query_data = (sr,)
+    parent_sr_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    query = "SELECT submit_time FROM sr_status WHERE sr = %s"
+    parent_sr_time = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    if parent_sr_id != INVALID_ID:
+        comment = ''
+        sr_mapping = {}
+        for pname in bm_member_sr_info:
+            for item in bm_member_sr_info[pname]:
+                if item.get('snapshot', 'SYNC') not in sr_mapping:
+                    sr_mapping[item.get('snapshot', 'SYNC')] = [item.get('git_tag')]
+                else:
+                    if item.get('git_tag') not in sr_mapping[item.get('snapshot', 'SYNC')]:
+                        sr_mapping[item.get('snapshot', 'SYNC')].append(item.get('git_tag'))
+        for snapshot in sr_mapping:
+            comment = '%s\n%s:' % (comment, snapshot)
+            for _sr in sr_mapping[snapshot]:
+                query = "SELECT id FROM sr_status WHERE sr = %s"
+                query_data = (_sr,)
+                _sr_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+                comment = '%s%s,' % (comment, _sr_id)
+        print comment
+
+        query = "INSERT INTO sr_comment (sr_status_id, user, comment, commented_date) VALUES(%s, %s, %s, %s)"
+        query_data = (parent_sr_id, email.replace('<', '').replace('>', ''), comment, parent_sr_time)
+        buildmonitor_db.do_query(query, query_data)
+
+        query = "UPDATE sr_status SET num_comments = num_comments + 1 WHERE sr = %s"
+        query_data = (sr,)
+        buildmonitor_db.do_query(query, query_data)
+
 #==================================================================================
 def main():
     """
@@ -2208,12 +2245,15 @@ def main():
                 # member sr for [sr_commit]
                 sync_sr_submit_for_sr_commit(commit_date, commit_msg,
                                              submit_date, submit_msg,
-                                             submitter, _sr,
-                                             _project, gerrit_newrev,
+                                             _submitter, _sr,
+                                             _project, _cid,
                                              gerrit_account_name)
 
         #update_sr_submit_log_completed(git_tag)
 
+        # Update log for tracing
+        sync_sr_update_comment(bm_sync_git_tag, submitter, bm_member_sr_info)
+
     #=======================================================
     # [PRE] Build
     #=======================================================
@@ -2575,3 +2615,4 @@ if __name__ == '__main__':
         print err
         bm_disconnect_db()
         sys.exit(1)
+
index 3908a5e..a6ca27a 100644 (file)
@@ -82,6 +82,7 @@ def request_sr_list_for_snapshot(project, snapshot, reason):
             for index, item in enumerate(sr.get('packages')):
                 sr_list.append({sr.get('sr'): [ {'repo': item.get('repo'),
                                                  'cid': item.get('cid'),
+                                                 'snapshot': snapshot,
                                                  'submitter': sr.get('submitters')[index]}
                                               ]})
         ret_data['requests'].append({'snapshot': snapshot, 'submit_list': sr_list})