66from pymongo import MongoClient
77from enum import Enum
88import requests
9+ import yaml
910
1011INPUT_ACCOUNT_ID = "kmpySmUISimoRrJL6NL73w"
1112INPUT_ORG_ID = "default"
@@ -36,6 +37,9 @@ class DBKeys(Enum):
3637 BRANCH = "branch"
3738 OBJECT_ID_OF_YAML = "objectIdOfYaml"
3839 YAML = "yaml"
40+ TARGET_IDENTIFIER = "targetIdentifier"
41+ PIPELINE_BRANCH_NAME = "pipelineBranchName"
42+ TRIGGER = "trigger"
3943 SETTINGS = "settings"
4044
4145
@@ -225,6 +229,32 @@ def delete_yaml_git_configs():
225229 }
226230 yaml_git_config_collection .delete_many (find_criteria )
227231
232+ def update_triggers ():
233+ query = {
234+ DBKeys .ACCOUNT_ID .value : INPUT_ACCOUNT_ID ,
235+ DBKeys .ORG_IDENTIFIER .value : INPUT_ORG_ID ,
236+ DBKeys .PROJECT_IDENTIFIER .value : INPUT_PROJECT_ID ,
237+ }
238+ triggers = pms_db .triggersNG .find (query )
239+ for record in triggers :
240+ pipelineId = record .get (DBKeys .TARGET_IDENTIFIER .value );
241+ pipelineQuery = {
242+ DBKeys .ACCOUNT_ID .value : INPUT_ACCOUNT_ID ,
243+ DBKeys .ORG_IDENTIFIER .value : INPUT_ORG_ID ,
244+ DBKeys .PROJECT_IDENTIFIER .value : INPUT_PROJECT_ID ,
245+ DBKeys .IDENTIFIER .value : pipelineId ,
246+ DBKeys .IS_FROM_DEFAULT_BRANCH .value : True
247+ }
248+ pipeline = pms_db .pipelinesPMS .find_one (pipelineQuery )
249+ if pipeline is None :
250+ continue
251+
252+ pipelineBranchName = pipeline .get (DBKeys .BRANCH .value );
253+
254+ trigger_yaml = yaml .safe_load (record .get (DBKeys .YAML .value ));
255+ trigger_yaml .get (DBKeys .TRIGGER .value )[DBKeys .PIPELINE_BRANCH_NAME .value ] = pipelineBranchName
256+ record [DBKeys .YAML .value ] = yaml .dump (trigger_yaml , sort_keys = False );
257+ pms_db .triggersNG .update_one ({"_id" : record .get ("_id" )}, {"$set" : record }, upsert = False )
228258
229259if __name__ == "__main__" :
230260 setup_mongo_client ()
@@ -234,6 +264,7 @@ def delete_yaml_git_configs():
234264 delete_non_default_branch_entities ()
235265 # enable_gitx_via_api()
236266 enable_new_gitx ()
267+ update_triggers ()
237268 migrate_records_from_inline_to_remote ()
238269 cleanup_connector_entities ()
239270 # reset_git_sync_sdk_cache()
0 commit comments