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

ListPackagesAction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
rs 10
c 1
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 17 4
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