-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement issue #1311 — dev-lead fixes-and-merges PRs it did NOT author — races the human driver (dropped a commit) #1312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+684
−51
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,56 @@ | ||
| #!/usr/bin/env bash | ||
| # git-push-guard.sh — no-clobber push helper for dev-lead (#1311). | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| # | ||
| # dev-lead must never overwrite a commit it has not seen. A concurrent writer — | ||
| # a human pushing to the same branch, or the auto-rebase bot — can advance the | ||
| # remote head after dev-lead checked the branch out. push_no_clobber pushes so | ||
| # that such an unseen commit is never discarded: | ||
| # | ||
| # 1. Plain (fast-forward) push first — the common case. It can NEVER discard: | ||
| # a non-fast-forward remote is rejected, not overwritten. | ||
| # 2. Retry with --force-with-lease ONLY when the local branch has DIVERGED | ||
| # from its upstream (history was rewritten, e.g. a rebase). The lease is the | ||
| # remote-tracking ref captured at checkout, so the force ABORTS if the | ||
| # remote advanced beyond what we last fetched. We deliberately do NOT fetch | ||
| # here — a fetch would refresh the lease and defeat the guard — and never | ||
| # use a bare --force. | ||
| # 3. If the lease fails, the remote moved under us: refuse (return non-zero). | ||
| # Discarding an unseen commit is never acceptable. | ||
| # | ||
| # Usage: push_no_clobber [git push args...] e.g. push_no_clobber origin main | ||
|
|
||
| push_no_clobber() { | ||
| local errf | ||
| errf="$(mktemp)" | ||
|
|
||
| if git push "$@" 2>"$errf"; then | ||
| rm -f "$errf" | ||
| return 0 | ||
| fi | ||
|
|
||
| local upstream | ||
| upstream=$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null || true) | ||
|
|
||
| # Retry with --force-with-lease ONLY on a non-fast-forward rejection where our | ||
| # branch has diverged from the upstream we last saw (rewritten history). | ||
| # --force-with-lease (no explicit value) leases against the remote-tracking | ||
| # ref, so it still ABORTS if the remote advanced beyond that ref. | ||
| if grep -qiE 'non-fast-forward|\[rejected\]|fetch first' "$errf" \ | ||
| && [ -n "$upstream" ] \ | ||
| && ! git merge-base --is-ancestor "$upstream" HEAD 2>/dev/null; then | ||
| echo "::notice::push rejected (non-fast-forward) and HEAD diverged from ${upstream} — history was rewritten (likely a rebase); retrying with --force-with-lease (aborts if the remote moved under us)" >&2 | ||
| if git push --force-with-lease "$@" 2>>"$errf"; then | ||
| rm -f "$errf" | ||
| return 0 | ||
| fi | ||
| cat "$errf" >&2 | ||
| rm -f "$errf" | ||
| echo "::error::--force-with-lease refused: the remote branch advanced beyond the commit dev-lead checked out. Refusing to discard an unseen commit." >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| cat "$errf" >&2 | ||
| rm -f "$errf" | ||
| echo "::error::git push failed — the remote head moved (a commit dev-lead never fetched) or access was denied; not overwriting." >&2 | ||
| return 1 | ||
| } | ||
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
tests/dev-lead/fixtures/events/issue_comment_bot_human_authored.json
This file contains hidden or 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,26 @@ | ||
| { | ||
| "_test_expected_intent": "skip", | ||
| "action": "created", | ||
| "issue": { | ||
| "number": 1303, | ||
| "title": "feat: onboard personas", | ||
| "state": "open", | ||
| "user": { | ||
| "login": "donpetry", | ||
| "type": "User" | ||
| }, | ||
| "pull_request": { | ||
| "url": "https://api.github.com/repos/petry-projects/.github-private/pulls/1303" | ||
| } | ||
| }, | ||
| "comment": { | ||
| "id": 4060, | ||
| "body": "SonarQube analysis found 3 new issues:\n- Critical: SQL injection vulnerability in line 42", | ||
| "user": { | ||
| "login": "sonarqubecloud[bot]", | ||
| "type": "Bot" | ||
| } | ||
| }, | ||
| "repository": { "full_name": "petry-projects/.github-private" }, | ||
| "sender": { "login": "sonarqubecloud[bot]", "type": "Bot" } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,27 @@ | ||
| { | ||
| "_test_expected_intent": "review-changes", | ||
| "action": "opened", | ||
| "number": 1402, | ||
| "pull_request": { | ||
| "number": 1402, | ||
| "title": "feat: implement issue #1402", | ||
| "body": "Implements the assigned issue.", | ||
| "state": "open", | ||
| "author_association": "OWNER", | ||
| "user": { | ||
| "login": "donpetry-bot", | ||
| "type": "Bot" | ||
| }, | ||
| "head": { | ||
| "sha": "abc1402def", | ||
| "ref": "dev-lead/issue-1402-20260718-1200", | ||
| "repo": { "full_name": "petry-projects/.github-private" } | ||
| }, | ||
| "base": { | ||
| "ref": "main", | ||
| "repo": { "full_name": "petry-projects/.github-private" } | ||
| } | ||
| }, | ||
| "repository": { "full_name": "petry-projects/.github-private" }, | ||
| "sender": { "login": "donpetry-bot", "type": "User" } | ||
| } |
34 changes: 34 additions & 0 deletions
34
tests/dev-lead/fixtures/events/pr_review_bot_dev_lead_authored.json
This file contains hidden or 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,34 @@ | ||
| { | ||
| "_test_expected_intent": "fix-reviews", | ||
| "action": "submitted", | ||
| "review": { | ||
| "id": 4002, | ||
| "state": "COMMENTED", | ||
| "body": "Please address the following issues in your code.", | ||
| "user": { | ||
| "login": "copilot-pull-request-reviewer[bot]", | ||
| "type": "Bot" | ||
| } | ||
| }, | ||
| "pull_request": { | ||
| "number": 1400, | ||
| "title": "feat: implement issue #1400", | ||
| "state": "open", | ||
| "author_association": "OWNER", | ||
| "user": { | ||
| "login": "donpetry-bot", | ||
| "type": "Bot" | ||
| }, | ||
| "head": { | ||
| "sha": "beef1234cafe", | ||
| "ref": "dev-lead/issue-1400-20260718-1200", | ||
| "repo": { "full_name": "petry-projects/.github-private" } | ||
| }, | ||
| "base": { | ||
| "ref": "main", | ||
| "repo": { "full_name": "petry-projects/.github-private" } | ||
| } | ||
| }, | ||
| "repository": { "full_name": "petry-projects/.github-private" }, | ||
| "sender": { "login": "copilot-pull-request-reviewer[bot]", "type": "Bot" } | ||
| } |
34 changes: 34 additions & 0 deletions
34
tests/dev-lead/fixtures/events/pr_review_bot_human_authored.json
This file contains hidden or 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,34 @@ | ||
| { | ||
| "_test_expected_intent": "skip", | ||
| "action": "submitted", | ||
| "review": { | ||
| "id": 4001, | ||
| "state": "COMMENTED", | ||
| "body": "Please address the following issues in your code.", | ||
| "user": { | ||
| "login": "copilot-pull-request-reviewer[bot]", | ||
| "type": "Bot" | ||
| } | ||
| }, | ||
| "pull_request": { | ||
| "number": 1303, | ||
| "title": "feat: onboard personas", | ||
| "state": "open", | ||
| "author_association": "OWNER", | ||
| "user": { | ||
| "login": "donpetry", | ||
| "type": "User" | ||
| }, | ||
| "head": { | ||
| "sha": "08794259aaaa", | ||
| "ref": "feat/onboard-personas", | ||
| "repo": { "full_name": "petry-projects/.github-private" } | ||
| }, | ||
| "base": { | ||
| "ref": "main", | ||
| "repo": { "full_name": "petry-projects/.github-private" } | ||
| } | ||
| }, | ||
| "repository": { "full_name": "petry-projects/.github-private" }, | ||
| "sender": { "login": "copilot-pull-request-reviewer[bot]", "type": "Bot" } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.