-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] Harve.sh: script that search enterprise commits in public odoo …
…forks
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script search for odoo forks that contains enterprise revisions | ||
# Culture point if you know why this script has this name. | ||
|
||
set -euo pipefail | ||
|
||
test "${DEBUG:-0}" != 0 && set -x | ||
|
||
workdir="${XDG_CACHE_HOME:-${HOME}/.cache}/Harve" | ||
mkdir -p "$workdir" | ||
venv="${workdir}/.venv" | ||
|
||
if [[ ! -d "$workdir/.git" ]]; then | ||
git init -q "$workdir" | ||
fi | ||
|
||
if [[ ! -d "$venv" ]]; then | ||
python3 -m venv "$venv" | ||
"$venv/bin/pip" install -U pip | ||
"$venv/bin/pip" install PyGithub | ||
fi | ||
|
||
# Generate config file with remotes | ||
"$venv/bin/python" > "$workdir/.git/config" <<EOP | ||
#!/usr/bin/env python3 | ||
import os | ||
import sys | ||
from github import Github | ||
REMOTE = """\ | ||
[remote "{remote}"] | ||
url = {url} | ||
fetch = +refs/heads/*:refs/remotes/{remote}/* | ||
fetch = +refs/pull/*/head:refs/remotes/{remote}/pr/* | ||
""" | ||
def forks(repo): | ||
print(REMOTE.format(remote=repo.full_name, url=repo.git_url)) | ||
if not repo.forks_count: | ||
return | ||
for frk in repo.get_forks(): | ||
try: | ||
forks(frk) | ||
except Exception as e: | ||
print(f"cannot get {frk.full_name}: {e}", file=sys.stderr) | ||
# Token is required to get over the low rate-limit of unauthentified requests | ||
gh = Github(os.getenv("GH_TOKEN")) | ||
forks(gh.get_repo("odoo/odoo")) | ||
EOP | ||
|
||
git="git -C $workdir/.git" | ||
|
||
jobs=$(( ($(nproc) + 1) / 2)) | ||
|
||
# some repo may not be accessible, ignore errors | ||
$git fetch --all --prune --quiet --no-auto-gc --multiple --jobs="$jobs" 2>/dev/null || true | ||
|
||
rm -f "$workdir/.git/gc.log" | ||
$git gc --quiet | ||
|
||
set -x | ||
# The search for the hash will return an error if not found. That the inverse of what we want. | ||
$git branch --all --contains 4295585aff34ba9881ed7f64bce3481e3d217dcd || exit 0 | ||
exit 1 |