@@ -10,7 +10,7 @@ def self.name
1010
1111 def self . unified_diff_tip
1212 <<~TIP
13- When updating and artifact provied unified diffs, for example :
13+ When updating and artifact in diff mode unified diffs can be applied :
1414
1515 If editing:
1616
@@ -50,7 +50,7 @@ def self.signature
5050 {
5151 name : "update_artifact" ,
5252 description :
53- "Updates an existing web artifact with new HTML, CSS, or JavaScript content.\n #{ unified_diff_tip } " ,
53+ "Updates an existing web artifact with new HTML, CSS, or JavaScript content.\n #{ unified_diff_tip } " ,
5454 parameters : [
5555 {
5656 name : "artifact_id" ,
@@ -79,6 +79,14 @@ def self.signature
7979 type : "string" ,
8080 required : true ,
8181 } ,
82+ {
83+ name : "diff_mode" ,
84+ description :
85+ "How would you like to apply the diff? (replace, append or diff) default is diff" ,
86+ type : "string" ,
87+ required : false ,
88+ enum : %w[ replace append diff ] ,
89+ } ,
8290 ] ,
8391 }
8492 end
@@ -114,12 +122,28 @@ def invoke
114122 end
115123
116124 begin
117- artifact . apply_diff (
118- html_diff : parameters [ :html_diff ] ,
119- css_diff : parameters [ :css_diff ] ,
120- js_diff : parameters [ :js_diff ] ,
121- change_description : parameters [ :change_description ] ,
122- )
125+ if parameters [ :diff_mode ] == "diff"
126+ artifact . apply_diff (
127+ html_diff : parameters [ :html_diff ] ,
128+ css_diff : parameters [ :css_diff ] ,
129+ js_diff : parameters [ :js_diff ] ,
130+ change_description : parameters [ :change_description ] ,
131+ )
132+ elsif parameters [ :diff_mode ] == "replace"
133+ artifact . create_new_version (
134+ html : parameters [ :html_diff ] || artifact . html ,
135+ css : parameters [ :css_diff ] || artifact . css ,
136+ js : parameters [ :js_diff ] || artifact . js ,
137+ change_description : parameters [ :change_description ] ,
138+ )
139+ else
140+ artifact . create_new_version (
141+ html : ( artifact . html + "\n " + parameters [ :html_diff ] . to_s ) . strip ,
142+ css : ( artifact . css + "\n " + parameters [ :css_diff ] . to_s ) . strip ,
143+ js : ( artifact . js + "\n " + parameters [ :js_diff ] . to_s ) . strip ,
144+ change_description : parameters [ :change_description ] ,
145+ )
146+ end
123147
124148 update_custom_html ( artifact )
125149 success_response ( artifact )
@@ -172,12 +196,26 @@ def update_custom_html(artifact = nil)
172196 def success_response ( artifact )
173197 @chain_next_response = false
174198
175- {
199+ hash = {
176200 status : "success" ,
177201 artifact_id : artifact . id ,
178202 version : artifact . versions . last . version_number ,
179203 message : "Artifact updated successfully and rendered to user." ,
180204 }
205+
206+ if parameters [ :html_diff ] . present?
207+ hash [ :new_artifact_html ] = artifact . html
208+ end
209+
210+ if parameters [ :css_diff ] . present?
211+ hash [ :new_artifact_css ] = artifact . css
212+ end
213+
214+ if parameters [ :js_diff ] . present?
215+ hash [ :new_artifact_js ] = artifact . js
216+ end
217+
218+ hash
181219 end
182220
183221 def error_response ( message )
0 commit comments