| Conditions | 15 |
| Total Lines | 69 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| 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:
Complex classes like GitHubRepo.issues() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # -*- coding: utf-8 -*- |
||
| 75 | def issues(self, |
||
| 76 | milestone=None, |
||
| 77 | state=None, |
||
| 78 | assignee=None, |
||
| 79 | creator=None, |
||
| 80 | mentioned=None, |
||
| 81 | labels=None, |
||
| 82 | sort=None, |
||
| 83 | direction=None, |
||
| 84 | since=None, |
||
| 85 | until=None, |
||
| 86 | branch=None): |
||
| 87 | """Return Issues and Pull Requests.""" |
||
| 88 | page = 1 |
||
| 89 | issues = [] |
||
| 90 | while True: |
||
| 91 | result = self.repo.issues.get(page=page, |
||
| 92 | per_page=100, |
||
| 93 | milestone=milestone, |
||
| 94 | state=state, |
||
| 95 | assignee=assignee, |
||
| 96 | creator=creator, |
||
| 97 | mentioned=mentioned, |
||
| 98 | labels=labels, |
||
| 99 | sort=sort, |
||
| 100 | direction=direction, |
||
| 101 | since=since) |
||
| 102 | if len(result) > 0: |
||
| 103 | issues += result |
||
| 104 | page = page + 1 |
||
| 105 | else: |
||
| 106 | break |
||
| 107 | |||
| 108 | # If since was provided, filter the issue |
||
| 109 | if since: |
||
| 110 | since_date = self.str_to_date(since) |
||
| 111 | for issue in issues[:]: |
||
| 112 | close_date = self.str_to_date(issue['closed_at']) |
||
| 113 | if close_date < since_date: |
||
| 114 | issues.remove(issue) |
||
| 115 | |||
| 116 | # If until was provided, filter the issue |
||
| 117 | if until: |
||
| 118 | until_date = self.str_to_date(until) |
||
| 119 | for issue in issues[:]: |
||
| 120 | close_date = self.str_to_date(issue['closed_at']) |
||
| 121 | if close_date > until_date: |
||
| 122 | issues.remove(issue) |
||
| 123 | |||
| 124 | # If it is a pr check if it is merged or closed, removed closed ones |
||
| 125 | for issue in issues[:]: |
||
| 126 | pr = issue.get('pull_request', '') |
||
| 127 | |||
| 128 | # Add label names inside additional key |
||
| 129 | issue['_label_names'] = [l['name'] for l in issue.get('labels')] |
||
| 130 | |||
| 131 | if pr: |
||
| 132 | number = issue['number'] |
||
| 133 | if not self.is_merged(number): |
||
| 134 | issues.remove(issue) |
||
| 135 | |||
| 136 | if branch: |
||
| 137 | # Get PR info and get base branch |
||
| 138 | pr_data = self.pr(number) |
||
| 139 | base_ref = pr_data['base']['ref'] |
||
| 140 | if base_ref != branch: |
||
| 141 | issues.remove(issue) |
||
| 142 | |||
| 143 | return issues |
||
| 144 | |||
| 167 |