|
110 | 110 | """ |
111 | 111 |
|
112 | 112 |
|
| 113 | +def _apply_github_filters(item, _filter, upstream, item_type="issue"): |
| 114 | + """ |
| 115 | + Apply GitHub filters (labels, milestone, other fields) to an item. |
| 116 | +
|
| 117 | + :param dict item: GitHub issue or PR data |
| 118 | + :param dict _filter: Filter configuration |
| 119 | + :param str upstream: Upstream repository name |
| 120 | + :param str item_type: Type of item for logging ("issue" or "PR") |
| 121 | + :returns: True if item passes all filters, False otherwise |
| 122 | + :rtype: bool |
| 123 | + """ |
| 124 | + for key, expected in _filter.items(): |
| 125 | + if key == "labels": |
| 126 | + # special handling for label: we look for it in the list of labels |
| 127 | + actual = {label["name"] for label in item.get("labels", [])} |
| 128 | + if actual.isdisjoint(expected): |
| 129 | + log.debug( |
| 130 | + "Labels %s not found on %s: %s", expected, upstream, item_type |
| 131 | + ) |
| 132 | + return False |
| 133 | + elif key == "milestone": |
| 134 | + # special handling for milestone: use the number |
| 135 | + milestone = item.get(key) or {} # Key might exist with value `None` |
| 136 | + actual = milestone.get("number") |
| 137 | + if expected != actual: |
| 138 | + log.debug( |
| 139 | + "Milestone %s not set on %s: %s", expected, upstream, item_type |
| 140 | + ) |
| 141 | + return False |
| 142 | + else: |
| 143 | + # direct comparison |
| 144 | + actual = item.get(key) |
| 145 | + if actual != expected: |
| 146 | + log.debug( |
| 147 | + "Actual %r %r != expected %r on %s %s", |
| 148 | + key, |
| 149 | + actual, |
| 150 | + expected, |
| 151 | + upstream, |
| 152 | + item_type, |
| 153 | + ) |
| 154 | + return False |
| 155 | + return True |
| 156 | + |
| 157 | + |
113 | 158 | def handle_github_message(body, config, is_pr=False): |
114 | 159 | """ |
115 | 160 | Handle GitHub message from FedMsg. |
@@ -140,33 +185,8 @@ def handle_github_message(body, config, is_pr=False): |
140 | 185 | _filter = config["sync2jira"].get("filters", {}).get("github", {}).get(upstream, {}) |
141 | 186 |
|
142 | 187 | issue = body["issue"] |
143 | | - for key, expected in _filter.items(): |
144 | | - if key == "labels": |
145 | | - # special handling for label: we look for it in the list of msg labels |
146 | | - actual = {label["name"] for label in issue["labels"]} |
147 | | - if actual.isdisjoint(expected): |
148 | | - log.debug("Labels %s not found on issue: %s", expected, upstream) |
149 | | - return None |
150 | | - elif key == "milestone": |
151 | | - # special handling for milestone: use the number |
152 | | - milestone = issue.get(key) or {} # Key might exist with value `None` |
153 | | - actual = milestone.get("number") |
154 | | - if expected != actual: |
155 | | - log.debug("Milestone %s not set on issue: %s", expected, upstream) |
156 | | - return None |
157 | | - else: |
158 | | - # direct comparison |
159 | | - actual = issue.get(key) |
160 | | - if actual != expected: |
161 | | - log.debug( |
162 | | - "Actual %r %r != expected %r on issue %s", |
163 | | - key, |
164 | | - actual, |
165 | | - expected, |
166 | | - upstream, |
167 | | - ) |
168 | | - return None |
169 | | - |
| 188 | + if not _apply_github_filters(issue, _filter, upstream, "issue"): |
| 189 | + return None |
170 | 190 | if is_pr and not issue.get("closed_at"): |
171 | 191 | log.debug( |
172 | 192 | "%r is a pull request. Ignoring.", issue.get("html_url", "<missing URL>") |
|
0 commit comments