diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f1cf9316e9..c2a7de026b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -621,9 +621,15 @@ shfmt: danger: <<: *precheck_job + # Keep the GIT_DEPTH environment variable set to a "high number" before + # https://github.com/libgit2/libgit2/pull/6662 is addressed and integrated + # into pygit2. + variables: + GIT_DEPTH: 1000 needs: [] script: - - danger-python ci -f + - pip install git+https://gitlab.isc.org/isc-projects/hazard.git + - hazard only: refs: - merge_requests diff --git a/dangerfile.py b/dangerfile.py index ee77f13cd1..2c1e7de14c 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -23,11 +23,13 @@ import gitlab def added_lines(target_branch, paths): import subprocess - subprocess.check_output( - ["/usr/bin/git", "fetch", "--depth", "1", "origin", target_branch] - ) + # Hazard fetches the target branch itself, so there is no need to fetch it + # explicitly using `git fetch --depth 1000 origin `. The + # refs/remotes/origin/ ref is also expected to be readily + # usable by the time this file is executed. + diff = subprocess.check_output( - ["/usr/bin/git", "diff", "FETCH_HEAD..", "--"] + paths + ["/usr/bin/git", "diff", f"origin/{target_branch}...", "--"] + paths ) added_lines = [] for line in diff.splitlines(): @@ -184,7 +186,6 @@ BACKPORT_OF_RE = re.compile( r"Backport\s+of.*(merge_requests/|!)([0-9]+)", flags=re.IGNORECASE ) VERSION_LABEL_RE = re.compile(r"v9.([0-9]+)(-S)?") -backport_desc = BACKPORT_OF_RE.search(danger.gitlab.mr.description) version_labels = [l for l in mr_labels if l.startswith("v9.")] affects_labels = [l for l in mr_labels if l.startswith("Affects v9.")] if is_backport: @@ -203,6 +204,7 @@ if is_backport: "Backport MRs must have their target version in the title. " f"Please put `[9.{minor_ver}{edition}]` at the start of the MR title." ) + backport_desc = BACKPORT_OF_RE.search(danger.gitlab.mr.description or "") if backport_desc is None: fail( "Backport MRs must link to the original MR. Please put "