|
12 | 12 | * labels a mirror `upstream-closed` and closes it when upstream closed the |
13 | 13 | original, unless the mirror has `agent:working` or an open fork PR |
14 | 14 | mentions it; then it only labels and comments |
| 15 | + * labels a mirror `upstream-open` while it is closed here as completed (fixed |
| 16 | + in the fork) but its upstream original is still open, and removes the label |
| 17 | + once upstream closes it: the list of upstream tickets waiting to be closed |
| 18 | + is `issues?state=closed&labels=upstream-open` |
15 | 19 |
|
16 | 20 | It refuses to create mirrors (exit 1) when the listing of existing mirrors looks |
17 | 21 | short: empty while the fork has mirrors, or more than BACKFILL_LIMIT unmirrored |
|
36 | 40 | MAX_BODY = 60000 |
37 | 41 | COMMENT_CHARS = 1500 |
38 | 42 | LAST_COMMENTS = 5 |
| 43 | +FIXED_OPEN = "upstream-open" # closed here as completed, upstream still open |
39 | 44 | BACKFILL_LIMIT = 5 # older-than-newest gaps tolerated (e.g. a mirror deleted by hand) |
40 | 45 | DRY = False |
41 | 46 | UPSTREAM = None |
@@ -156,10 +161,11 @@ def main(): |
156 | 161 | if up.lower() == fork.lower(): |
157 | 162 | sys.exit("--upstream and --fork must differ") |
158 | 163 | summary = {"upstream_open": 0, "created": [], "refreshed": [], "closed": [], "flagged_closed": [], |
159 | | - "pending_create": 0, "dry_run": DRY} |
| 164 | + "pending_create": 0, "fixed_here_open_upstream": [], "dry_run": DRY} |
160 | 165 |
|
161 | 166 | for name, color, desc in [("mirror", "c5def5", "Downstream copy of an upstream issue"), |
162 | | - ("upstream-closed", "d4c5f9", "The upstream original was closed")]: |
| 167 | + ("upstream-closed", "d4c5f9", "The upstream original was closed"), |
| 168 | + (FIXED_OPEN, "0e8a16", "Closed here as fixed; the upstream original is still open")]: |
163 | 169 | api(f"/repos/{fork}/labels", "POST", {"name": name, "color": color, "description": desc}, ok_codes=("422",)) |
164 | 170 |
|
165 | 171 | open_up = {i["number"]: i for i in paged(f"/repos/{up}/issues?state=open") if "pull_request" not in i} |
@@ -209,14 +215,31 @@ def mirrors_of_up(issues): |
209 | 215 | open_prs = None |
210 | 216 | for n, m in sorted(by_up.items()): |
211 | 217 | hit = MARKER.search(m["body"]) |
| 218 | + labels = {l["name"] for l in m.get("labels") or []} |
| 219 | + # Closed here as fixed while upstream is open: flag it, so the upstream |
| 220 | + # tickets waiting to be closed are one query away. Only by_up's pick |
| 221 | + # (an open mirror if there is one) counts, so a closed duplicate of an |
| 222 | + # open mirror is never flagged. |
| 223 | + fixed_here = m["state"] == "closed" and m.get("state_reason") == "completed" |
| 224 | + if fixed_here and n in open_up: |
| 225 | + summary["fixed_here_open_upstream"].append(n) |
| 226 | + if FIXED_OPEN not in labels: |
| 227 | + api(f"/repos/{fork}/issues/{m['number']}/labels", "POST", {"labels": [FIXED_OPEN]}) |
| 228 | + elif FIXED_OPEN in labels: |
| 229 | + # Reopened here, or upstream closed it. Confirm the latter first: |
| 230 | + # a short upstream listing must not strip every label. |
| 231 | + st = (api(f"/repos/{up}/issues/{n}", ok_codes=("404", "410")) or {}) if fixed_here else {} |
| 232 | + if st.get("state") == "open": |
| 233 | + summary["fixed_here_open_upstream"].append(n) |
| 234 | + else: |
| 235 | + api(f"/repos/{fork}/issues/{m['number']}/labels/{FIXED_OPEN}", "DELETE", ok_codes=("404",)) |
212 | 236 | if n in open_up: |
213 | 237 | i = open_up[n] |
214 | 238 | if m["state"] == "open" and hit.group(3) != i["updated_at"]: |
215 | 239 | api(f"/repos/{fork}/issues/{m['number']}", "PATCH", |
216 | 240 | {"title": title_for(i), "body": build_body(up, i, last_comments(up, i))}) |
217 | 241 | summary["refreshed"].append(n) |
218 | 242 | continue |
219 | | - labels = {l["name"] for l in m.get("labels") or []} |
220 | 243 | # Already flagged and kept open for the maintainer: don't comment again every run. |
221 | 244 | if m["state"] != "open" or "upstream-closed" in labels: |
222 | 245 | continue |
|
0 commit comments