#69 Handling response in data method in updates2stable
Merged 8 years ago by ralph. Opened 8 years ago by shalini.
shalini/fedora-hubs bugfix/updates2stable  into  develop

@@ -53,26 +53,30 @@ 

      url = bodhiurl + query

      headers = {'Accept': 'application/json'}

      response = requests.get(url, headers=headers)

-     data = response.json()

- 

-     # Limit it this to only the updates that haven't already requested stable

-     # but which can actually be pushed to stable now.

-     data['updates'] = [

-         update for update in data['updates']

-         if update['request'] is None and

-         any([giveaway in comment['text'] for comment in update['comments']])

-     ]

- 

-     # Stuff some useful information in there.

-     baseurl = 'https://apps.fedoraproject.org/packages/images/icons/'

-     for update in data['updates']:

-         build = update['builds'][0]

-         nvr = build['nvr']

-         package = parse_nvr(nvr)

-         update['icon'] = baseurl + package[0] + '.png'

-         update['link'] = bodhiurl + update['title']

- 

-     return data

+     if response.status_code == 200:

Here you can do a simple: if response if that response is a requests request object.

+         data = response.json()

+ 

+         # Limit it this to only the updates that haven't already requested stable

Just noticed a minor typo here from before

+         # but which can actually be pushed to stable now.

+         data['updates'] = [

+             update for update in data['updates']

+             if update['request'] is None and

+             any([giveaway in comment['text'] for comment in update['comments']])

+         ]

+ 

+         # Stuff some useful information in there.

+         baseurl = 'https://apps.fedoraproject.org/packages/images/icons/'

+         for update in data['updates']:

+             build = update['builds'][0]

+             nvr = build['nvr']

+             package = parse_nvr(nvr)

+             update['icon'] = baseurl + package[0] + '.png'

+             update['link'] = bodhiurl + update['title']

+ 

+         return data

+     else:

+         data = {}

+         return data

  

  

  def parse_nvr(nvr):

no initial comment

Just noticed a minor typo here from before

Here you can do a simple: if response if that response is a requests request object.

@pingou is right! You can treat those response objects as booleans, which is very handy.

Nonetheless, I'm going to merge this as-is. @shalini, if you want to change the way you handle those response objects later, feel free to!

Metadata