@@ -55,11 +55,10 @@ def update
5555
5656 record . update ( JSON . parse ( request . body . read ) [ singular_name ] )
5757 if record . valid?
58- @changes = { :"env_vars" => { created : "name: #{ record . name } , is_public: #{ record . public } , branch: #{ record . branch || 'all' } " } }
58+ @changes = { :"env_vars" => { created : "name: #{ record . name } , is_public: #{ record . public } , branch: #{ record . branch || 'all' } " } } if is_env_var?
5959
6060 repo_settings . save
61- run_callbacks :after_save
62- @changes = { }
61+ run_callbacks :after_save if is_env_var?
6362
6463 respond_with ( record , type : singular_name , version : :v2 )
6564 else
@@ -73,11 +72,10 @@ def create
7372
7473 record = collection . create ( JSON . parse ( request . body . read ) [ singular_name ] )
7574 if record . valid?
76- @changes = { :"env_vars" => { created : "name: #{ record . name } , is_public: #{ record . public } , branch: #{ record . branch || 'all' } " } }
75+ @changes = { :"env_vars" => { created : "name: #{ record . name } , is_public: #{ record . public } , branch: #{ record . branch || 'all' } " } } if is_env_var?
7776
7877 repo_settings . save
79- run_callbacks :after_save
80- @changes = { }
78+ run_callbacks :after_save if is_env_var?
8179
8280 respond_with ( record , type : singular_name , version : :v2 )
8381 else
@@ -90,11 +88,10 @@ def destroy
9088 disallow_migrating! ( repo )
9189
9290 record = collection . destroy ( params [ :id ] ) || record_not_found
93- @changes = { :"env_vars" => { destroyed : "name: #{ record . name } , is_public: #{ record . public } , branch: #{ record . branch || 'all' } " } }
91+ @changes = { :"env_vars" => { destroyed : "name: #{ record . name } , is_public: #{ record . public } , branch: #{ record . branch || 'all' } " } } if is_env_var?
9492
9593 repo_settings . save
96- run_callbacks :after_save
97- @changes = { }
94+ run_callbacks :after_save if is_env_var?
9895
9996 respond_with ( record , type : singular_name , version : :v2 )
10097 end
@@ -131,11 +128,16 @@ def changes
131128 @changes
132129 end
133130
131+ def is_env_var?
132+ singular_name == 'env_var'
133+ end
134+
134135 private
135136
136137 def save_audit
137138 change_source = access_token . app_id == 2 ? 'admin-v2' : 'travis-api'
138139 Travis ::API ::V3 ::Models ::Audit . create! ( owner : current_user , change_source : change_source , source : @repo , source_changes : { settings : self . changes } )
140+ @changes = { }
139141 end
140142 end
141143end
0 commit comments