Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions apps/worker/tasks/sync_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ def run_impl_within_lock(
"reason": "not_in_provider",
}
self.trigger_ai_pr_review(enriched_pull, current_yaml)

# Check for related commits to improve PR context
self.analyze_related_commits_for_context(db_session, pull, current_yaml)

report_service = ReportService(
current_yaml, gh_app_installation_name=installation_name_to_use
)
Expand Down Expand Up @@ -591,6 +595,42 @@ def trigger_ai_pr_review(self, enriched_pull: EnrichedPull, current_yaml: UserYa
kwargs={"repoid": pull.repoid, "pullid": pull.pullid}
)

def analyze_related_commits_for_context(self, db_session, pull, current_yaml):
"""
Analyzes related commits to provide better context for the pull request.
This helps identify patterns and dependencies in the codebase.
"""
repoid = pull.repoid
head_commit = pull.get_head_commit()

if not head_commit:
return

# Look for recent commits on the same branch for context
related_commits = (
db_session.query(Commit)
.filter(
Commit.repoid == repoid,
Commit.branch == head_commit.branch,
Commit.timestamp < head_commit.timestamp,
(Commit.pullid.is_(None) | (Commit.pullid != pull.pullid)),
Commit.deleted == False,
)
.limit(100)
.all()
)

if related_commits:
log.info(
"Found related commits for pull request context",
extra={
"repoid": repoid,
"pullid": pull.pullid,
"related_commits_count": len(related_commits),
"head_commit": head_commit.commitid,
},
)


RegisteredPullSyncTask = celery_app.register_task(PullSyncTask())
pull_sync_task = celery_app.tasks[RegisteredPullSyncTask.name]