Skip to content

fix merge upstream workflow - #106

Merged
littleboobs merged 1 commit into
masterfrom
fix-merge-upstream-workflow
Jun 2, 2026
Merged

fix merge upstream workflow #106
littleboobs merged 1 commit into
masterfrom
fix-merge-upstream-workflow

Conversation

@littleboobs

@littleboobs littleboobs commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Информация о PR

bruh

@littleboobs
littleboobs merged commit 15561b0 into master Jun 2, 2026
14 checks passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds error handling to the git push commands in modular_nemesis/tools/merge_upstream.sh to provide a descriptive error message when the push fails due to insufficient token permissions. The reviewer suggested refactoring the conditional block to eliminate code duplication by setting the push options dynamically and executing the checkout and push commands once after the conditional block.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 58 to 66
if git ls-remote --exit-code --heads origin "${MERGE_BRANCH}" >/dev/null 2>&1; then
log "Branch ${MERGE_BRANCH} exists, resetting it to upstream/${UPSTREAM_BRANCH}"
git checkout -f -B "${MERGE_BRANCH}" "upstream/${UPSTREAM_BRANCH}"
git push --force origin "${MERGE_BRANCH}"
git push --force origin "${MERGE_BRANCH}" || die "failed to push ${MERGE_BRANCH}; the token needs 'contents' AND 'workflows' write (upstream changes .github/workflows/* files)"
else
log "Creating branch ${MERGE_BRANCH} from upstream/${UPSTREAM_BRANCH}"
git checkout -f -B "${MERGE_BRANCH}" "upstream/${UPSTREAM_BRANCH}"
git push -u origin "${MERGE_BRANCH}"
git push -u origin "${MERGE_BRANCH}" || die "failed to push ${MERGE_BRANCH}; the token needs 'contents' AND 'workflows' write (upstream changes .github/workflows/* files)"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

🟡 Рекомендация по улучшению структуры кода

Приветствую! Я проанализировала предложенные Вами изменения.

Проблема:
В текущей реализации наблюдается дублирование кода в блоках if и else:

  1. Команда git checkout -f -B "${MERGE_BRANCH}" "upstream/${UPSTREAM_BRANCH}" выполняется в обеих ветках.
  2. Длинное сообщение об ошибке в die "..." для команды git push полностью дублируется.

Это усложняет чтение кода и его дальнейшую поддержку.

Решение:
Рекомендуется вынести общую логику (команды checkout и push) за пределы условного оператора, а в самом условии определять только специфичный флаг для отправки изменений (--force или -u). Это сделает скрипт более лаконичным и избавит от дублирования.

Suggested change
if git ls-remote --exit-code --heads origin "${MERGE_BRANCH}" >/dev/null 2>&1; then
log "Branch ${MERGE_BRANCH} exists, resetting it to upstream/${UPSTREAM_BRANCH}"
git checkout -f -B "${MERGE_BRANCH}" "upstream/${UPSTREAM_BRANCH}"
git push --force origin "${MERGE_BRANCH}"
git push --force origin "${MERGE_BRANCH}" || die "failed to push ${MERGE_BRANCH}; the token needs 'contents' AND 'workflows' write (upstream changes .github/workflows/* files)"
else
log "Creating branch ${MERGE_BRANCH} from upstream/${UPSTREAM_BRANCH}"
git checkout -f -B "${MERGE_BRANCH}" "upstream/${UPSTREAM_BRANCH}"
git push -u origin "${MERGE_BRANCH}"
git push -u origin "${MERGE_BRANCH}" || die "failed to push ${MERGE_BRANCH}; the token needs 'contents' AND 'workflows' write (upstream changes .github/workflows/* files)"
fi
if git ls-remote --exit-code --heads origin "${MERGE_BRANCH}" >/dev/null 2>&1; then
log "Branch ${MERGE_BRANCH} exists, resetting it to upstream/${UPSTREAM_BRANCH}"
push_opts="--force"
else
log "Creating branch ${MERGE_BRANCH} from upstream/${UPSTREAM_BRANCH}"
push_opts="-u"
fi
git checkout -f -B "${MERGE_BRANCH}" "upstream/${UPSTREAM_BRANCH}"
git push ${push_opts} origin "${MERGE_BRANCH}" || die "failed to push ${MERGE_BRANCH}; the token needs 'contents' AND 'workflows' write (upstream changes .github/workflows/* files)"
References
  1. Раздел 4.1 репозиторного стайлгайда рекомендует выявлять дублирование кода и устранять повторяющиеся блоки для улучшения читаемости и поддержки. (link)

@littleboobs
littleboobs deleted the fix-merge-upstream-workflow branch June 2, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant