Merge lp:~kfogel/launchpad/538219-debdiff-is-patch-too into lp:launchpad

Proposed by Karl Fogel
Status: Merged
Merged at revision: not available
Proposed branch: lp:~kfogel/launchpad/538219-debdiff-is-patch-too
Merge into: lp:launchpad
Diff against target: 107 lines (+64/-2)
4 files modified
lib/lp/bugs/browser/bugattachment.py (+11/-1)
lib/lp/bugs/browser/bugmessage.py (+1/-1)
lib/lp/bugs/stories/bugattachments/10-add-bug-attachment.txt (+49/-0)
lib/lp/bugs/stories/bugattachments/20-edit-bug-attachment.txt (+3/-0)
To merge this branch: bzr merge lp:~kfogel/launchpad/538219-debdiff-is-patch-too
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+22488@code.launchpad.net

Description of the change

When a plaintext file with a name ending in ".diff", ".debdiff", or ".patch" is offered by the user as a patch attachment, have Launchpad trust the user and not prompt for confirmation.

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote :

nice work!

And thanks for fixing all the typos I made in earlier branches :)

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/bugs/browser/bugattachment.py'
--- lib/lp/bugs/browser/bugattachment.py 2010-01-28 11:07:50 +0000
+++ lib/lp/bugs/browser/bugattachment.py 2010-03-30 21:00:57 +0000
@@ -40,9 +40,19 @@
40 """40 """
4141
42 def guessContentType(self, filename, file_content):42 def guessContentType(self, filename, file_content):
43 """Guess the content type a file with the given anme and content."""43 """Guess the content type a file with the given name and content."""
44 guessed_type, encoding = guess_content_type(44 guessed_type, encoding = guess_content_type(
45 name=filename, body=file_content)45 name=filename, body=file_content)
46 # Zope's guess_content_type() doesn't consider all the factors
47 # we want considered. So after we get its answer, we probe a
48 # little further. But we still don't look at the encoding nor
49 # the file content, because we'd like to avoid reimplementing
50 # 'patch'. See bug #538219 for more.
51 if (guessed_type == 'text/plain'
52 and (filename.endswith('.diff')
53 or filename.endswith('.debdiff')
54 or filename.endswith('.patch'))):
55 guessed_type = 'text/x-diff'
46 return guessed_type56 return guessed_type
4757
48 def attachmentTypeConsistentWithContentType(58 def attachmentTypeConsistentWithContentType(
4959
=== modified file 'lib/lp/bugs/browser/bugmessage.py'
--- lib/lp/bugs/browser/bugmessage.py 2010-01-28 11:07:50 +0000
+++ lib/lp/bugs/browser/bugmessage.py 2010-03-30 21:00:57 +0000
@@ -107,7 +107,7 @@
107 # If the patch flag is not consistent with the result of107 # If the patch flag is not consistent with the result of
108 # the guess made in attachmentTypeConsistentWithContentType(),108 # the guess made in attachmentTypeConsistentWithContentType(),
109 # we use the guessed type and lead the user to a page109 # we use the guessed type and lead the user to a page
110 # where he can override the flag value, if Luanchpad's110 # where he can override the flag value, if Launchpad's
111 # guess is wrong.111 # guess is wrong.
112 patch_flag_consistent = (112 patch_flag_consistent = (
113 self.attachmentTypeConsistentWithContentType(113 self.attachmentTypeConsistentWithContentType(
114114
=== modified file 'lib/lp/bugs/stories/bugattachments/10-add-bug-attachment.txt'
--- lib/lp/bugs/stories/bugattachments/10-add-bug-attachment.txt 2010-01-28 11:07:50 +0000
+++ lib/lp/bugs/stories/bugattachments/10-add-bug-attachment.txt 2010-03-30 21:00:57 +0000
@@ -204,3 +204,52 @@
204 ... print li_tag.a.renderContents()204 ... print li_tag.a.renderContents()
205 A fix for this bug.205 A fix for this bug.
206 A better icon for foo206 A better icon for foo
207
208We expect Launchpad to believe us (that is, not ask for confirmation)
209when we tell it that plain text files whose names end in ".diff",
210".debdiff", or ".patch" are patch attachments:
211
212 >>> user_browser.open(
213 ... 'http://bugs.launchpad.dev/firefox/+bug/1/+addcomment')
214 >>> foo_file.seek(0)
215 >>> user_browser.getControl('Attachment').add_file(
216 ... foo_file, 'text/plain', 'foo3.diff')
217 >>> user_browser.getControl('Description').value = 'the foo3 patch'
218 >>> patch_control = user_browser.getControl(
219 ... 'This attachment contains a solution (patch) for this bug')
220 >>> patch_control.selected = True
221 >>> user_browser.getControl(
222 ... name="field.comment").value = 'Add foo3.diff as a patch.'
223 >>> user_browser.getControl('Post Comment').click()
224 >>> user_browser.url
225 'http://bugs.launchpad.dev/firefox/+bug/1'
226
227 >>> user_browser.open(
228 ... 'http://bugs.launchpad.dev/firefox/+bug/1/+addcomment')
229 >>> foo_file.seek(0)
230 >>> user_browser.getControl('Attachment').add_file(
231 ... foo_file, 'text/plain', 'foo4.debdiff')
232 >>> user_browser.getControl('Description').value = 'the foo4 patch'
233 >>> patch_control = user_browser.getControl(
234 ... 'This attachment contains a solution (patch) for this bug')
235 >>> patch_control.selected = True
236 >>> user_browser.getControl(
237 ... name="field.comment").value = 'Add foo4.debdiff as a patch.'
238 >>> user_browser.getControl('Post Comment').click()
239 >>> user_browser.url
240 'http://bugs.launchpad.dev/firefox/+bug/1'
241
242 >>> user_browser.open(
243 ... 'http://bugs.launchpad.dev/firefox/+bug/1/+addcomment')
244 >>> foo_file.seek(0)
245 >>> user_browser.getControl('Attachment').add_file(
246 ... foo_file, 'text/plain', 'foo5.patch')
247 >>> user_browser.getControl('Description').value = 'the foo5 patch'
248 >>> patch_control = user_browser.getControl(
249 ... 'This attachment contains a solution (patch) for this bug')
250 >>> patch_control.selected = True
251 >>> user_browser.getControl(
252 ... name="field.comment").value = 'Add foo5.patch as a patch.'
253 >>> user_browser.getControl('Post Comment').click()
254 >>> user_browser.url
255 'http://bugs.launchpad.dev/firefox/+bug/1'
207256
=== modified file 'lib/lp/bugs/stories/bugattachments/20-edit-bug-attachment.txt'
--- lib/lp/bugs/stories/bugattachments/20-edit-bug-attachment.txt 2010-01-28 11:07:50 +0000
+++ lib/lp/bugs/stories/bugattachments/20-edit-bug-attachment.txt 2010-03-30 21:00:57 +0000
@@ -76,6 +76,9 @@
76 Another title76 Another title
77 A fix for this bug.77 A fix for this bug.
78 A better icon for foo78 A better icon for foo
79 the foo3 patch
80 the foo4 patch
81 the foo5 patch
7982
80...while it is gone from the portlet "Bug attachments".83...while it is gone from the portlet "Bug attachments".
8184