|
| 1 | +name: "Migrate Rejected → Not Accepted" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + dry_run: |
| 7 | + description: "Preview changes without updating issues" |
| 8 | + required: true |
| 9 | + default: true |
| 10 | + type: boolean |
| 11 | + |
| 12 | +permissions: |
| 13 | + issues: write |
| 14 | + contents: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + relabel: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout repo |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Setup Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: "3.11" |
| 27 | + |
| 28 | + - name: Install requests |
| 29 | + run: pip install requests |
| 30 | + |
| 31 | + - name: Replace labels |
| 32 | + env: |
| 33 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + REPO_FULL: ${{ github.repository }} |
| 35 | + DRY_RUN: ${{ inputs.dry_run }} |
| 36 | + run: | |
| 37 | + python - <<'PY' |
| 38 | + import os, sys, requests |
| 39 | + from requests.adapters import HTTPAdapter |
| 40 | + try: |
| 41 | + from urllib3.util.retry import Retry |
| 42 | + retry = Retry(total=5, backoff_factor=0.7, |
| 43 | + status_forcelist=[429,500,502,503,504]) |
| 44 | + except Exception: |
| 45 | + retry = None |
| 46 | +
|
| 47 | + token = os.getenv("GITHUB_TOKEN") |
| 48 | + repo_full = os.getenv("REPO_FULL") |
| 49 | + dry_run = os.getenv("DRY_RUN","true").lower() == "true" |
| 50 | +
|
| 51 | + if not token or not repo_full: |
| 52 | + print("Missing env vars", file=sys.stderr); sys.exit(1) |
| 53 | + owner, repo = repo_full.split("/", 1) |
| 54 | +
|
| 55 | + s = requests.Session() |
| 56 | + s.headers.update({ |
| 57 | + "Authorization": f"Bearer {token}", |
| 58 | + "Accept": "application/vnd.github+json" |
| 59 | + }) |
| 60 | + if retry: s.mount("https://", HTTPAdapter(max_retries=retry)) |
| 61 | +
|
| 62 | + def list_all_issues(): |
| 63 | + url = f"https://api.github.com/repos/{owner}/{repo}/issues" |
| 64 | + params = {"state":"all", "per_page":100} |
| 65 | + first = True |
| 66 | + while url: |
| 67 | + r = s.get(url, params=params if first else None) |
| 68 | + first = False |
| 69 | + if r.status_code != 200: |
| 70 | + print("List issues failed:", r.text); sys.exit(1) |
| 71 | + for it in r.json(): |
| 72 | + if "pull_request" not in it: |
| 73 | + yield it |
| 74 | + url = r.links.get("next",{}).get("url") |
| 75 | + params = None |
| 76 | +
|
| 77 | + def update_labels(num, labels): |
| 78 | + if dry_run: |
| 79 | + print(f"DRY-RUN: would update issue #{num} labels → {labels}") |
| 80 | + return |
| 81 | + r = s.put(f"https://api.github.com/repos/{owner}/{repo}/issues/{num}/labels", |
| 82 | + json={"labels": labels}) |
| 83 | + if r.status_code not in (200,201): |
| 84 | + print(f"Update labels failed for #{num}: {r.status_code} {r.text}") |
| 85 | +
|
| 86 | + changed = 0 |
| 87 | + for issue in list_all_issues(): |
| 88 | + labels = [l["name"] for l in issue["labels"]] |
| 89 | + if "Rejected" in labels: |
| 90 | + new_labels = [l for l in labels if l != "Rejected"] |
| 91 | + if "Not Accepted" not in new_labels: |
| 92 | + new_labels.append("Not Accepted") |
| 93 | + update_labels(issue["number"], new_labels) |
| 94 | + changed += 1 |
| 95 | +
|
| 96 | + if dry_run: |
| 97 | + print(f"DRY-RUN complete. {changed} issue(s) would be updated.") |
| 98 | + else: |
| 99 | + print(f"Done. Updated {changed} issue(s).") |
| 100 | + PY |
0 commit comments