cnauroth commented on code in PR #365:
URL: https://github.com/apache/yetus/pull/365#discussion_r2853733421


##########
precommit/src/main/shell/plugins.d/github.sh:
##########
@@ -336,6 +336,93 @@ function github_determine_branch
   verify_valid_branch "${PATCH_BRANCH}"
 }
 
+## @description  Generate patch and diff files locally via git when the
+## @description  GitHub API fails (e.g., HTTP 406 on PRs with >300 files).
+## @description  Fetches the PR head via refs/pull/N/head and the base branch,
+## @description  then uses git format-patch and git diff to produce the output.
+## @audience     private
+## @stability    evolving
+## @replaceable  no
+## @param        PR number
+## @param        patch output file
+## @param        diff output file
+## @return       0 on success
+## @return       1 on failure
+function github_generate_local_diff
+{
+  declare input=$1
+  declare patchout=$2
+  declare diffout=$3
+  declare base_ref
+  declare base_sha
+  declare head_sha
+  declare merge_base
+
+  yetus_debug "github: attempting local git fallback for PR #${input}"
+
+  # shellcheck disable=SC2016
+  base_ref=$("${AWK}" 'match($0,"\"ref\": \""){print $2}' 
"${PATCH_DIR}/github-pull.json" \
+    | cut -f2 -d\" \
+    | tail -1)
+
+  if [[ -z "${base_ref}" ]]; then
+    yetus_debug "github: cannot determine base ref from PR JSON"
+    return 1
+  fi
+
+  pushd "${BASEDIR}" >/dev/null || return 1
+
+  if ! "${GIT}" fetch origin "refs/pull/${input}/head" >/dev/null 2>&1; then
+    yetus_debug "github: cannot fetch refs/pull/${input}/head"
+    popd >/dev/null || true
+    return 1
+  fi
+
+  head_sha=$("${GIT}" rev-parse FETCH_HEAD)

Review Comment:
   Here and below, there are a few git commands without error checks. Do you 
think they should have error checks, or do you think it's pretty much 
impossible for rev-parse and merge-base to fail?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to