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
1=== modified file 'lib/lp/bugs/browser/bugattachment.py'
2--- lib/lp/bugs/browser/bugattachment.py 2010-01-28 11:07:50 +0000
3+++ lib/lp/bugs/browser/bugattachment.py 2010-03-30 21:00:57 +0000
4@@ -40,9 +40,19 @@
5 """
6
7 def guessContentType(self, filename, file_content):
8- """Guess the content type a file with the given anme and content."""
9+ """Guess the content type a file with the given name and content."""
10 guessed_type, encoding = guess_content_type(
11 name=filename, body=file_content)
12+ # Zope's guess_content_type() doesn't consider all the factors
13+ # we want considered. So after we get its answer, we probe a
14+ # little further. But we still don't look at the encoding nor
15+ # the file content, because we'd like to avoid reimplementing
16+ # 'patch'. See bug #538219 for more.
17+ if (guessed_type == 'text/plain'
18+ and (filename.endswith('.diff')
19+ or filename.endswith('.debdiff')
20+ or filename.endswith('.patch'))):
21+ guessed_type = 'text/x-diff'
22 return guessed_type
23
24 def attachmentTypeConsistentWithContentType(
25
26=== modified file 'lib/lp/bugs/browser/bugmessage.py'
27--- lib/lp/bugs/browser/bugmessage.py 2010-01-28 11:07:50 +0000
28+++ lib/lp/bugs/browser/bugmessage.py 2010-03-30 21:00:57 +0000
29@@ -107,7 +107,7 @@
30 # If the patch flag is not consistent with the result of
31 # the guess made in attachmentTypeConsistentWithContentType(),
32 # we use the guessed type and lead the user to a page
33- # where he can override the flag value, if Luanchpad's
34+ # where he can override the flag value, if Launchpad's
35 # guess is wrong.
36 patch_flag_consistent = (
37 self.attachmentTypeConsistentWithContentType(
38
39=== modified file 'lib/lp/bugs/stories/bugattachments/10-add-bug-attachment.txt'
40--- lib/lp/bugs/stories/bugattachments/10-add-bug-attachment.txt 2010-01-28 11:07:50 +0000
41+++ lib/lp/bugs/stories/bugattachments/10-add-bug-attachment.txt 2010-03-30 21:00:57 +0000
42@@ -204,3 +204,52 @@
43 ... print li_tag.a.renderContents()
44 A fix for this bug.
45 A better icon for foo
46+
47+We expect Launchpad to believe us (that is, not ask for confirmation)
48+when we tell it that plain text files whose names end in ".diff",
49+".debdiff", or ".patch" are patch attachments:
50+
51+ >>> user_browser.open(
52+ ... 'http://bugs.launchpad.dev/firefox/+bug/1/+addcomment')
53+ >>> foo_file.seek(0)
54+ >>> user_browser.getControl('Attachment').add_file(
55+ ... foo_file, 'text/plain', 'foo3.diff')
56+ >>> user_browser.getControl('Description').value = 'the foo3 patch'
57+ >>> patch_control = user_browser.getControl(
58+ ... 'This attachment contains a solution (patch) for this bug')
59+ >>> patch_control.selected = True
60+ >>> user_browser.getControl(
61+ ... name="field.comment").value = 'Add foo3.diff as a patch.'
62+ >>> user_browser.getControl('Post Comment').click()
63+ >>> user_browser.url
64+ 'http://bugs.launchpad.dev/firefox/+bug/1'
65+
66+ >>> user_browser.open(
67+ ... 'http://bugs.launchpad.dev/firefox/+bug/1/+addcomment')
68+ >>> foo_file.seek(0)
69+ >>> user_browser.getControl('Attachment').add_file(
70+ ... foo_file, 'text/plain', 'foo4.debdiff')
71+ >>> user_browser.getControl('Description').value = 'the foo4 patch'
72+ >>> patch_control = user_browser.getControl(
73+ ... 'This attachment contains a solution (patch) for this bug')
74+ >>> patch_control.selected = True
75+ >>> user_browser.getControl(
76+ ... name="field.comment").value = 'Add foo4.debdiff as a patch.'
77+ >>> user_browser.getControl('Post Comment').click()
78+ >>> user_browser.url
79+ 'http://bugs.launchpad.dev/firefox/+bug/1'
80+
81+ >>> user_browser.open(
82+ ... 'http://bugs.launchpad.dev/firefox/+bug/1/+addcomment')
83+ >>> foo_file.seek(0)
84+ >>> user_browser.getControl('Attachment').add_file(
85+ ... foo_file, 'text/plain', 'foo5.patch')
86+ >>> user_browser.getControl('Description').value = 'the foo5 patch'
87+ >>> patch_control = user_browser.getControl(
88+ ... 'This attachment contains a solution (patch) for this bug')
89+ >>> patch_control.selected = True
90+ >>> user_browser.getControl(
91+ ... name="field.comment").value = 'Add foo5.patch as a patch.'
92+ >>> user_browser.getControl('Post Comment').click()
93+ >>> user_browser.url
94+ 'http://bugs.launchpad.dev/firefox/+bug/1'
95
96=== modified file 'lib/lp/bugs/stories/bugattachments/20-edit-bug-attachment.txt'
97--- lib/lp/bugs/stories/bugattachments/20-edit-bug-attachment.txt 2010-01-28 11:07:50 +0000
98+++ lib/lp/bugs/stories/bugattachments/20-edit-bug-attachment.txt 2010-03-30 21:00:57 +0000
99@@ -76,6 +76,9 @@
100 Another title
101 A fix for this bug.
102 A better icon for foo
103+ the foo3 patch
104+ the foo4 patch
105+ the foo5 patch
106
107 ...while it is gone from the portlet "Bug attachments".
108