Conditions | 5 |
Total Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | |||
9 | def run(self, api_user, repository, name, body, github_type, |
||
10 | target_commitish="master", version_increase="patch", |
||
11 | draft=False, prerelease=False): |
||
12 | |||
13 | enterprise = self._is_enterprise(github_type) |
||
14 | |||
15 | if api_user: |
||
16 | self.token = self._get_user_token(api_user, |
||
17 | enterprise) |
||
18 | |||
19 | release = self._request("GET", |
||
20 | "/repos/{}/releases/latest".format(repository), |
||
21 | None, |
||
22 | self.token, |
||
23 | enterprise) |
||
24 | |||
25 | (major, minor, patch) = release['tag_name'].split(".") |
||
26 | major = int(major.replace("v", "")) |
||
27 | minor = int(minor) |
||
28 | patch = int(patch) |
||
29 | |||
30 | if version_increase == "major": |
||
31 | major += 1 |
||
32 | minor = 0 |
||
33 | patch = 0 |
||
34 | elif version_increase == "minor": |
||
35 | minor += 1 |
||
36 | patch = 0 |
||
37 | elif version_increase == "patch": |
||
38 | patch += 1 |
||
39 | |||
40 | tag_name = "v{}.{}.{}".format(major, |
||
41 | minor, |
||
42 | patch) |
||
43 | |||
44 | payload = {"tag_name": tag_name, |
||
45 | "target_commitish": target_commitish, |
||
46 | "name": name, |
||
47 | "body": body, |
||
48 | "draft": draft, |
||
49 | "prerelease": prerelease} |
||
50 | |||
51 | release = self._request("POST", |
||
52 | "/repos/{}/releases".format(repository), |
||
53 | payload, |
||
54 | self.token, |
||
55 | enterprise) |
||
56 | |||
57 | ts_published_at = time.mktime( |
||
58 | datetime.datetime.strptime( |
||
59 | release['published_at'], |
||
60 | "%Y-%m-%dT%H:%M:%SZ").timetuple()) |
||
61 | |||
62 | results = {'author': release['author']['login'], |
||
63 | 'html_url': release['html_url'], |
||
64 | 'tag_name': release['tag_name'], |
||
65 | 'target_commitish': release['target_commitish'], |
||
66 | 'name': release['name'], |
||
67 | 'body': release['body'], |
||
68 | 'draft': release['draft'], |
||
69 | 'prerelease': release['prerelease'], |
||
70 | 'created_at': release['created_at'], |
||
71 | 'published_at': release['published_at'], |
||
72 | 'ts_published_at': ts_published_at, |
||
73 | 'total_assets': len(release['assets'])} |
||
74 | results['response'] = release |
||
75 | |||
76 | return results |
||
77 |