diff mbox

Add mark_spam.py script

Message ID c923d744-7783-d998-3b32-1525f6979e21@suse.cz
State New
Headers show

Commit Message

Martin Liška Aug. 13, 2016, 7:46 p.m. UTC
On 08/12/2016 11:15 PM, Joseph Myers wrote:
> Next observation on this script: it dies if a bug number in the given
> range doesn't exist, with an error like:
>
> Marking as spam: PR75336
> Traceback (most recent call last):
>   File "./mark_spam.py", line 98, in <module>
>     mark_as_spam(id, args.api_key, args.verbose)
>   File "./mark_spam.py", line 38, in mark_as_spam
>     cc_list = response['bugs'][0]['cc']
> KeyError: 'bugs'
>
> It would be more convenient if it ignored nonexistent bugs rather than
> falling over like this, so that it's only necessary to check that the
> range you pass to the script has no non-spam bugs in it, not that every
> bug number in the range exists.

That's easy to solve, please try to apply following patch on top
of current trunk.

>
> (I don't know why there are gaps in the bug numbers; I suppose some error
> / timeout occurred while the spammers were creating bugs, at a point after
> a bug number had been reserved in the database but before the transaction
> creating the bug was complete - in such circumstances, databases don't
> necessarily unwind the reservation of a number.)
>
diff mbox

Patch

diff --git a/contrib/mark_spam.py b/contrib/mark_spam.py
index 569a03d..f206356 100755
--- a/contrib/mark_spam.py
+++ b/contrib/mark_spam.py
@@ -34,6 +34,10 @@  def mark_as_spam(id, api_key, verbose):
     r = requests.get(u)
     response = json.loads(r.text)
 
+    if 'error' in response and response['error']:
+        print(response['message'])
+        return
+
     # 2) mark the bug as spam
     cc_list = response['bugs'][0]['cc']
     data = {
@@ -49,6 +53,7 @@  def mark_as_spam(id, api_key, verbose):
         'cc': {'remove': cc_list},
         'priority': 'P5',
         'severity': 'trivial',
+        'url': '',
         'assigned_to': 'unassigned@gcc.gnu.org' }
 
     r = requests.put(u, json = data)
@@ -74,7 +79,12 @@  def mark_as_spam(id, api_key, verbose):
     for a in attachments:
         attachment_id = a['id']
         url = '%sbug/attachment/%d' % (base_url, attachment_id)
-        r = requests.put(url, json = {'ids': [attachment_id], 'summary': 'spam', 'comment': 'spam', 'is_obsolete': True, 'api_key': api_key})
+        r = requests.put(url, json = {'ids': [attachment_id],
+            'summary': 'spam',
+            'file_name': 'spam',
+            'content_type': 'application/x-spam',
+            'is_obsolete': True,
+            'api_key': api_key})
         if verbose:
             print(r)
             print(r.text)