| Conditions | 19 |
| Total Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 12 | ||
| 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 -*- |
||
| 123 | def issues(self, |
||
| 124 | milestone=None, |
||
| 125 | state=None, |
||
| 126 | assignee=None, |
||
| 127 | creator=None, |
||
| 128 | mentioned=None, |
||
| 129 | labels=None, |
||
| 130 | sort=None, |
||
| 131 | direction=None, |
||
| 132 | since=None, |
||
| 133 | until=None, |
||
| 134 | branch=None): |
||
| 135 | """Return Issues and Pull Requests.""" |
||
| 136 | self._check_rate() |
||
| 137 | page = 1 |
||
| 138 | issues = [] |
||
| 139 | while True: |
||
| 140 | result = self.repo.issues.get(page=page, |
||
| 141 | per_page=100, |
||
| 142 | milestone=milestone, |
||
| 143 | state=state, |
||
| 144 | assignee=assignee, |
||
| 145 | creator=creator, |
||
| 146 | mentioned=mentioned, |
||
| 147 | labels=labels, |
||
| 148 | sort=sort, |
||
| 149 | direction=direction, |
||
| 150 | since=since) |
||
| 151 | if len(result) > 0: |
||
| 152 | issues += result |
||
| 153 | page = page + 1 |
||
| 154 | else: |
||
| 155 | break |
||
| 156 | |||
| 157 | # If since was provided, filter the issue |
||
| 158 | if since: |
||
| 159 | since_date = self.str_to_date(since) |
||
| 160 | for issue in issues[:]: |
||
| 161 | close_date = self.str_to_date(issue['closed_at']) |
||
| 162 | if close_date < since_date and issue in issues: |
||
| 163 | issues.remove(issue) |
||
| 164 | |||
| 165 | # If until was provided, filter the issue |
||
| 166 | if until: |
||
| 167 | until_date = self.str_to_date(until) |
||
| 168 | for issue in issues[:]: |
||
| 169 | close_date = self.str_to_date(issue['closed_at']) |
||
| 170 | if close_date > until_date and issue in issues: |
||
| 171 | issues.remove(issue) |
||
| 172 | |||
| 173 | # If it is a pr check if it is merged or closed, removed closed ones |
||
| 174 | for issue in issues[:]: |
||
| 175 | pr = issue.get('pull_request', '') |
||
| 176 | |||
| 177 | # Add label names inside additional key |
||
| 178 | issue['loghub_label_names'] = [ |
||
| 179 | l['name'] for l in issue.get('labels') |
||
| 180 | ] |
||
| 181 | |||
| 182 | if pr: |
||
| 183 | number = issue['number'] |
||
| 184 | if not self.is_merged(number) and issue in issues: |
||
| 185 | issues.remove(issue) |
||
| 186 | |||
| 187 | if branch: |
||
| 188 | # Get PR info and get base branch |
||
| 189 | pr_data = self.pr(number) |
||
| 190 | base_ref = pr_data['base']['ref'] |
||
| 191 | if base_ref != branch and issue in issues: |
||
| 192 | issues.remove(issue) |
||
| 193 | |||
| 194 | return issues |
||
| 195 | |||
| 219 |