Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

1 file changed+12−1
modifiedscripts/mirror-to-github.sh+12−1View file
@@ -102,11 +102,14 @@
102102 req.add_header("Authorization", f"Bearer {token}")
103103 try:
104104 with urllib.request.urlopen(req, timeout=30) as r:
105- return r.status, json.load(r)
105+ data = r.read()
106+ return r.status, json.loads(data) if data else None
106107 except urllib.error.HTTPError as e:
107108 return e.code, None
108109
109110 token = os.environ["GITHUB_MIRROR_TOKEN"]
111+status, me = call("GET", f"{dst.split('/repos/')[0]}/user", token=token)
112+me = me.get("login") if status == 200 else None
110113 status, releases = call("GET", f"{src}/releases?per_page=100", token=os.environ.get("DIFFINERY_TOKEN"))
111114 if status != 200:
112115 raise SystemExit(f"could not list Diffinery releases ({status})")
@@ -115,6 +118,14 @@
115118 continue
116119 want = {"name": r["name"], "body": r["body"] or "", "prerelease": r["prerelease"]}
117120 status, have = call("GET", f"{dst}/releases/tags/{r['tag_name']}", token=token)
121+ if status == 200 and me and (have.get("author") or {}).get("login") != me:
122+ # A mirrored release belongs to the mirror's account: one made by anyone else is made again.
123+ status, _ = call("DELETE", f"{dst}/releases/{have['id']}", token=token)
124+ if status != 204:
125+ print(f"warning: could not replace GitHub release {r['tag_name']} ({status})")
126+ continue
127+ print(f"release {r['tag_name']}: deleted the copy {have['author']['login']} made")
128+ status = 404
118129 if status == 404:
119130 status, _ = call("POST", f"{dst}/releases", {"tag_name": r["tag_name"], **want}, token)
120131 print(f"release {r['tag_name']}: created ({status})")