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.

68 lines · 3.0 KB · executableRaw History
1#!/usr/bin/env bash
2# Mirror Diffinery's codician/diffinery main to github.com/codician-team/diffinery.
3#
4# Every author and committer becomes codician-team and the attribution trailers
5# (Co-authored-by, Claude-Session, Signed-off-by) are dropped, so GitHub lists no
6# personal contributors.
7# The rewrite is deterministic: the same Diffinery history always gives the same
8# GitHub commits, so a sync is a fast-forward unless Diffinery's own history was
9# rewritten (then GitHub follows it). Only main is mirrored.
10#
11# Reads Diffinery with DIFFINERY_TOKEN when set (not needed once the repo is public);
12# MIRROR_SRC can also be a local clone that has main. Pushes with GITHUB_MIRROR_TOKEN
13# when set, otherwise with whatever credentials git already has for github.com.
14# Needs git-filter-repo 2.47.0 (pip install git-filter-repo==2.47.0); another
15# version could write different commits.
16#
17# Usage: scripts/mirror-to-github.sh [--dry-run]
18#
19# MIRROR_WORKDIR=<empty dir> keeps the rewritten repository for inspection.
20set -euo pipefail
21
22SRC=${MIRROR_SRC:-https://diffinery.com/codician/diffinery.git}
23DST=${MIRROR_DST:-https://github.com/codician-team/diffinery.git}
24NAME=${MIRROR_NAME:-codician-team}
25EMAIL=${MIRROR_EMAIL:-codician-team@users.noreply.diffinery.com}
26dry_run=${1:-}
27
28work=${MIRROR_WORKDIR:-}
29if [ -z "$work" ]; then
30 work=$(mktemp -d)
31 trap 'rm -rf "$work"' EXIT
32fi
33
34auth=()
35if [ -n "${DIFFINERY_TOKEN:-}" ]; then
36 # The helper reads the token from the environment, so it never lands on a command line.
37 auth=(-c 'credential.https://diffinery.com.helper=!f() { [ "$1" = get ] && printf "username=x-token\npassword=%s\n" "$DIFFINERY_TOKEN"; }; f')
38fi
39if [ -n "${GITHUB_MIRROR_TOKEN:-}" ]; then
40 auth+=(-c 'credential.https://github.com.helper=!f() { [ "$1" = get ] && printf "username=x-access-token\npassword=%s\n" "$GITHUB_MIRROR_TOKEN"; }; f')
41fi
42git "${auth[@]}" clone --quiet --bare --single-branch --branch main "$SRC" "$work/repo.git"
43cd "$work/repo.git"
44src_head=$(git rev-parse main)
45
46export MIRROR_NAME="$NAME" MIRROR_EMAIL="$EMAIL"
47git filter-repo --force --quiet --refs main --replace-refs delete-no-add \
48 --name-callback 'return os.environ["MIRROR_NAME"].encode()' \
49 --email-callback 'return os.environ["MIRROR_EMAIL"].encode()' \
50 --message-callback '
51import re
52drop = re.compile(r"^(co-authored-by|claude-session|signed-off-by):|^\U0001f916 generated with \[claude code\]|^https://claude\.ai/code/session_", re.I)
53text = message.decode("utf-8", "surrogateescape")
54lines = [l for l in text.split("\n") if not drop.match(l.strip())]
55return ("\n".join(lines).rstrip() + "\n").encode("utf-8", "surrogateescape")'
56
57dst_head=$(git rev-parse main)
58echo "Diffinery main $src_head -> GitHub main $dst_head"
59if [ "$dry_run" = "--dry-run" ]; then
60 git log --format='%h %an <%ae> %s' -3 main
61 exit 0
62fi
63remote=$(git "${auth[@]}" ls-remote "$DST" refs/heads/main | cut -f1)
64if [ "$remote" = "$dst_head" ]; then
65 echo "GitHub is up to date."
66 exit 0
67fi
68git "${auth[@]}" push --force "$DST" main:main