Skip to content

Commit c099808

Browse files
committed
Add script and Justfile targets to sync all PRs with origin/main
1 parent c78fe5a commit c099808

File tree

3 files changed

+121
-4
lines changed

3 files changed

+121
-4
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,18 @@ WORKDIR /app
4646

4747
RUN git clone --branch main /source /app --local
4848
RUN git remote set-url origin https://github.com/oleander/git-ai.git
49+
RUN git pull origin main
4950
RUN cargo fetch
5051
RUN cargo build
52+
RUN cargo clippy
53+
54+
ARG PR_NUMBER
55+
ARG GH_TOKEN
56+
ENV GH_TOKEN=$GH_TOKEN
57+
RUN gh pr checkout $PR_NUMBER
58+
RUN cargo fetch
59+
RUN cargo build
60+
RUN cargo clippy
5161

5262
# Default command that can be overridden
5363
SHELL ["/bin/bash", "-lc"]

Justfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@ integration-test:
2828
docker build -t git-ai-test .
2929
docker run --rm git-ai-test -e OPENAI_API_KEY=$OPENAI_API_KEY
3030

31-
# just pr "gh pr checkout 74 && cargo fmt --all"
32-
# just pr "gh pr checkout 74 && cargo build"
33-
pr CMD:
34-
docker build --target pr-tester -t git-ai-pr-tester .
31+
# just pr 74 "cargo fmt --all"
32+
# just pr 74 "cargo build"
33+
pr PR_NUMBER CMD:
34+
docker build --build-arg PR_NUMBER={{PR_NUMBER}} --build-arg GH_TOKEN=$(gh auth token) --target pr-tester -t git-ai-pr-tester .
3535
docker run -i --rm -e GITHUB_TOKEN=$(gh auth token) git-ai-pr-tester bash -c "{{CMD}}"
36+
37+
# Sync all open PRs with origin/main
38+
sync-prs:
39+
./scripts/sync-all-prs
40+
41+
# Sync a specific PR with origin/main
42+
sync-pr PR_NUM:
43+
just pr {{PR_NUM}} "git fetch origin main && git merge origin/main --no-edit && cargo fmt --all && cargo check && git push origin HEAD"

scripts/sync-all-prs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Sync all open PRs with origin/main using the Justfile pr command
4+
#
5+
# This script:
6+
# 1. Fetches all open PRs from GitHub
7+
# 2. For each PR, uses `just pr` to checkout and merge origin/main
8+
# 3. Handles merge conflicts if they occur
9+
# 4. Pushes the updated branch back to origin
10+
11+
set -e
12+
13+
# Colors for output
14+
RED='\033[0;31m'
15+
GREEN='\033[0;32m'
16+
YELLOW='\033[1;33m'
17+
BLUE='\033[0;34m'
18+
NC='\033[0m' # No Color
19+
20+
echo -e "${BLUE}=== Syncing all open PRs with origin/main ===${NC}"
21+
echo ""
22+
23+
# Get list of open PRs using gh CLI
24+
echo -e "${BLUE}Fetching open PRs...${NC}"
25+
PR_LIST=$(gh pr list --state open --json number,headRefName --jq '.[] | "\(.number):\(.headRefName)"')
26+
27+
if [ -z "$PR_LIST" ]; then
28+
echo -e "${YELLOW}No open PRs found.${NC}"
29+
exit 0
30+
fi
31+
32+
echo -e "${GREEN}Found the following open PRs:${NC}"
33+
echo "$PR_LIST" | while IFS=: read -r pr_num branch; do
34+
echo " PR #$pr_num: $branch"
35+
done
36+
echo ""
37+
38+
# Get current origin/main SHA
39+
MAIN_SHA=$(git rev-parse origin/main)
40+
echo -e "${BLUE}Current origin/main SHA: ${MAIN_SHA:0:8}${NC}"
41+
echo ""
42+
43+
# Track success/failure
44+
SUCCESSFUL_PRS=()
45+
FAILED_PRS=()
46+
CONFLICT_PRS=()
47+
48+
# Sync each PR
49+
echo "$PR_LIST" | while IFS=: read -r pr_num branch; do
50+
echo ""
51+
echo -e "${BLUE}=== Syncing PR #$pr_num ($branch) ===${NC}"
52+
53+
# Build the command to run inside the pr-tester container
54+
SYNC_CMD="gh pr checkout $pr_num && \
55+
git fetch origin main && \
56+
git merge origin/main --no-edit && \
57+
cargo fmt --all && \
58+
cargo check && \
59+
git push origin $branch"
60+
61+
# Run the command using the pr command from Justfile
62+
if just pr "$SYNC_CMD"; then
63+
echo -e "${GREEN}✓ Successfully synced PR #$pr_num${NC}"
64+
SUCCESSFUL_PRS+=("$pr_num")
65+
else
66+
EXIT_CODE=$?
67+
if [ $EXIT_CODE -eq 1 ]; then
68+
echo -e "${RED}✗ Merge conflict in PR #$pr_num${NC}"
69+
echo -e "${YELLOW} Please resolve manually:${NC}"
70+
echo -e " just pr \"gh pr checkout $pr_num && git status\""
71+
CONFLICT_PRS+=("$pr_num")
72+
else
73+
echo -e "${RED}✗ Failed to sync PR #$pr_num (exit code: $EXIT_CODE)${NC}"
74+
FAILED_PRS+=("$pr_num")
75+
fi
76+
fi
77+
done
78+
79+
# Summary
80+
echo ""
81+
echo -e "${BLUE}=== Summary ===${NC}"
82+
if [ ${#SUCCESSFUL_PRS[@]} -gt 0 ]; then
83+
echo -e "${GREEN}Successfully synced (${#SUCCESSFUL_PRS[@]}):${NC} ${SUCCESSFUL_PRS[*]}"
84+
fi
85+
if [ ${#CONFLICT_PRS[@]} -gt 0 ]; then
86+
echo -e "${YELLOW}Conflicts requiring manual resolution (${#CONFLICT_PRS[@]}):${NC} ${CONFLICT_PRS[*]}"
87+
fi
88+
if [ ${#FAILED_PRS[@]} -gt 0 ]; then
89+
echo -e "${RED}Failed (${#FAILED_PRS[@]}):${NC} ${FAILED_PRS[*]}"
90+
fi
91+
92+
# Exit with appropriate code
93+
if [ ${#CONFLICT_PRS[@]} -gt 0 ] || [ ${#FAILED_PRS[@]} -gt 0 ]; then
94+
exit 1
95+
fi
96+
97+
echo ""
98+
echo -e "${GREEN}All PRs synced successfully!${NC}"
99+

0 commit comments

Comments
 (0)