Completed
Pull Request — master (#534)
by Tomaz
02:53
created

ListPackagesAction.run()   A

Complexity

Conditions 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
dl 0
loc 17
rs 9.2
c 1
b 0
f 0
1
import fnmatch
2
3
import requests
4
5
from st2actions.runners.pythonrunner import Action
6
7
URL = 'https://%(api_token)s:@packagecloud.io/api/v1/repos/%(repo)s/packages.json'
8
9
10
class ListPackagesAction(Action):
11
    def run(self, repo, api_token, per_page=1000, filename_filter=None):
12
        values = {'repo': repo, 'api_token': api_token}
13
        url = URL % values
14
        params = {'per_page': per_page}
15
16
        response = requests.get(url, params=params)
17
        data = response.json()
18
19
        if not filename_filter:
20
            return data
21
22
        result = []
23
        for item in data:
24
            if fnmatch.fnmatch(item['filename'], filename_filter):
25
                result.append(item)
26
27
        return result
28