fix(ci): detect untracked upstream items regardless of number
Problem: the digest script filtered by `number > last_number`, so any upstream item with a number below the highest tracked entry was silently skipped. Solution: collect the set of all tracked numbers from `doc/upstream.md` and filter by `number not in tracked` instead. For merged PRs, also filter by the fork's creation date via `GITHUB_REPOSITORY` to avoid pulling in ancient pre-fork history.
This commit is contained in:
parent
5a8cbf10ff
commit
5a7429f1e4
1 changed files with 31 additions and 25 deletions
52
.github/scripts/upstream_digest.py
vendored
52
.github/scripts/upstream_digest.py
vendored
|
|
@ -4,28 +4,28 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from datetime import date, timedelta
|
|
||||||
|
|
||||||
|
|
||||||
UPSTREAM = "stevearc/oil.nvim"
|
UPSTREAM = "stevearc/oil.nvim"
|
||||||
UPSTREAM_MD = "doc/upstream.md"
|
UPSTREAM_MD = "doc/upstream.md"
|
||||||
|
FORK_REPO = os.environ.get("GITHUB_REPOSITORY", "")
|
||||||
|
|
||||||
PRS_HEADING = "## Upstream PRs"
|
PRS_HEADING = "## Upstream PRs"
|
||||||
ISSUES_HEADING = "## Issues"
|
ISSUES_HEADING = "## Issues"
|
||||||
|
|
||||||
|
|
||||||
def get_last_tracked_number():
|
def get_tracked_numbers():
|
||||||
try:
|
try:
|
||||||
with open(UPSTREAM_MD) as f:
|
with open(UPSTREAM_MD) as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
numbers = re.findall(
|
return {
|
||||||
|
int(n)
|
||||||
|
for n in re.findall(
|
||||||
r"\[#(\d+)\]\(https://github\.com/stevearc/oil\.nvim", content
|
r"\[#(\d+)\]\(https://github\.com/stevearc/oil\.nvim", content
|
||||||
)
|
)
|
||||||
if numbers:
|
}
|
||||||
return max(int(n) for n in numbers)
|
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
return set()
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def gh(*args):
|
def gh(*args):
|
||||||
|
|
@ -38,14 +38,23 @@ def gh(*args):
|
||||||
return result.stdout.strip()
|
return result.stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
def fetch_items(last_number, since_date):
|
def get_fork_created_at():
|
||||||
|
if FORK_REPO:
|
||||||
|
data = json.loads(gh("repo", "view", FORK_REPO, "--json", "createdAt"))
|
||||||
|
return data["createdAt"]
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_items(tracked):
|
||||||
|
fork_created = get_fork_created_at()
|
||||||
|
|
||||||
merged_prs = json.loads(
|
merged_prs = json.loads(
|
||||||
gh(
|
gh(
|
||||||
"pr", "list",
|
"pr", "list",
|
||||||
"--repo", UPSTREAM,
|
"--repo", UPSTREAM,
|
||||||
"--state", "merged",
|
"--state", "merged",
|
||||||
"--limit", "100",
|
"--limit", "100",
|
||||||
"--json", "number,title,url",
|
"--json", "number,title,url,mergedAt",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
open_prs = json.loads(
|
open_prs = json.loads(
|
||||||
|
|
@ -54,7 +63,7 @@ def fetch_items(last_number, since_date):
|
||||||
"--repo", UPSTREAM,
|
"--repo", UPSTREAM,
|
||||||
"--state", "open",
|
"--state", "open",
|
||||||
"--limit", "100",
|
"--limit", "100",
|
||||||
"--json", "number,title,createdAt,url",
|
"--json", "number,title,url",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
open_issues = json.loads(
|
open_issues = json.loads(
|
||||||
|
|
@ -63,19 +72,17 @@ def fetch_items(last_number, since_date):
|
||||||
"--repo", UPSTREAM,
|
"--repo", UPSTREAM,
|
||||||
"--state", "open",
|
"--state", "open",
|
||||||
"--limit", "100",
|
"--limit", "100",
|
||||||
"--json", "number,title,createdAt,url",
|
"--json", "number,title,url",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if last_number is not None:
|
merged_prs = [
|
||||||
merged_prs = [x for x in merged_prs if x["number"] > last_number]
|
x for x in merged_prs
|
||||||
open_prs = [x for x in open_prs if x["number"] > last_number]
|
if x["number"] not in tracked
|
||||||
open_issues = [x for x in open_issues if x["number"] > last_number]
|
and (fork_created is None or x.get("mergedAt", "") >= fork_created)
|
||||||
else:
|
]
|
||||||
cutoff = since_date.isoformat()
|
open_prs = [x for x in open_prs if x["number"] not in tracked]
|
||||||
merged_prs = []
|
open_issues = [x for x in open_issues if x["number"] not in tracked]
|
||||||
open_prs = [x for x in open_prs if x.get("createdAt", "") >= cutoff]
|
|
||||||
open_issues = [x for x in open_issues if x.get("createdAt", "") >= cutoff]
|
|
||||||
|
|
||||||
merged_prs.sort(key=lambda x: x["number"])
|
merged_prs.sort(key=lambda x: x["number"])
|
||||||
open_prs.sort(key=lambda x: x["number"])
|
open_prs.sort(key=lambda x: x["number"])
|
||||||
|
|
@ -104,10 +111,9 @@ def append_to_section(content, heading, new_rows):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
last_number = get_last_tracked_number()
|
tracked = get_tracked_numbers()
|
||||||
since_date = date.today() - timedelta(days=30)
|
|
||||||
|
|
||||||
merged_prs, open_prs, open_issues = fetch_items(last_number, since_date)
|
merged_prs, open_prs, open_issues = fetch_items(tracked)
|
||||||
|
|
||||||
total = len(merged_prs) + len(open_prs) + len(open_issues)
|
total = len(merged_prs) + len(open_prs) + len(open_issues)
|
||||||
if total == 0:
|
if total == 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue