Skip to content

ref(integrations): Clarify which endpoints gets called#113196

Merged
armenzg merged 1 commit intomasterfrom
separate_function_names
Apr 16, 2026
Merged

ref(integrations): Clarify which endpoints gets called#113196
armenzg merged 1 commit intomasterfrom
separate_function_names

Conversation

@armenzg
Copy link
Copy Markdown
Member

@armenzg armenzg commented Apr 16, 2026

This makes it clear what endpoint is going to be called.

This makes it clear what endpoint is going to be called.
@armenzg armenzg self-assigned this Apr 16, 2026
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 16, 2026
"integration_id": data["integration_id"],
}

def compare_commits(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This function would call two different endpoints: compare/ and sometimes commit/.

In a sense, we're not doing any comparison of commits, thus, even making the name more confusing.

def eval_commits(client: Any) -> Sequence[Mapping[str, Any]]:
# use config name because that is kept in sync via webhooks
name = repo.config["name"]
if start_sha is None:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the difference between calling one endpoint vs the other one.

commits = client.compare_commits(name, start_sha, end_sha)
return self._format_commits(client, name, commits)

def _get_installation_and_client(self, repo: Repository) -> tuple[IntegrationInstallation, Any]:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We're adding two new functions and they will share this logic.

client = installation.get_client()
return installation, installation.get_client()

def fetch_recent_commits(self, repo: Repository, end_sha: str) -> Sequence[Mapping[str, Any]]:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This one focuses on getting the last 20 commits. Not an idempotent call.


try:
return eval_commits(client)
commits = client.compare_commits(name, start_sha, end_sha)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is an idempotent call. In the next PR I will be moving the caching logic here.

except Exception as e:
installation.raise_error(e)

def compare_commits(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is for backward compatibility.

if hasattr(provider, "fetch_commits_for_compare_range"):
repo_commits = provider.fetch_commits_for_compare_range(repo, start_sha, end_sha)
else:
repo_commits = provider.compare_commits(repo, start_sha, end_sha)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For backward compatibility.

@armenzg armenzg marked this pull request as ready for review April 16, 2026 18:07
@armenzg armenzg requested review from a team as code owners April 16, 2026 18:07
repo_commits = fetch_recent_commits(
repo=repo,
provider=provider,
is_integration_repo_provider=is_integration_repo_provider,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The fetch_recent_commits function is missing a lifecycle parameter, which prevents the compare_commits_cache_enabled metric from being recorded when start_sha is None.
Severity: LOW

Suggested Fix

Add a lifecycle parameter to the fetch_recent_commits function signature. Pass the lifecycle object to it from fetch_commits. Inside fetch_recent_commits, add the compare_commits_cache_enabled metric to the lifecycle to restore the previous telemetry behavior.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/sentry/tasks/commits.py#L288

Potential issue: A refactoring separated commit fetching logic into
`fetch_recent_commits` and `fetch_commits_for_compare_range`. When `start_sha` is
`None`, `fetch_commits` calls `fetch_recent_commits`. However, the `lifecycle` parameter
was not added to the new `fetch_recent_commits` function. Consequently, the
`compare_commits_cache_enabled` metric is no longer recorded for this code path. This is
a regression in observability and does not impact the core functionality of fetching
commits, nor does it cause crashes or incorrect application behavior.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is sort of an anti-pattern anyway. Function calls like this shouldn't necessarily be coupled to the metrics in the top-level tasks imo.

Comment on lines +89 to +90
commits = client.get_last_commits(name, end_sha)
return self._format_commits(client, name, commits[:20])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: could we update the client to take a pagination size of 20 vs retrieving 30 and trimming the number down? https://docs.github.com/en/rest/commits/commits?apiVersion=2026-03-10#list-commits-on-a-repository

*,
repo: Repository,
provider: Any,
is_integration_repo_provider: bool,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this be standardized across provider clients consistently? Mainly asking out of ignorance for GitLab and Bitbucket's APIs.

repo_commits = fetch_recent_commits(
repo=repo,
provider=provider,
is_integration_repo_provider=is_integration_repo_provider,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is sort of an anti-pattern anyway. Function calls like this shouldn't necessarily be coupled to the metrics in the top-level tasks imo.

@armenzg armenzg changed the title ref(integrations): Clarify getting commits vs comparing commits ref(integrations): Clarify which endpoints gets called Apr 16, 2026
@armenzg
Copy link
Copy Markdown
Member Author

armenzg commented Apr 16, 2026

@GabeVillalobos I will follow-up on your nits after this PR.

@armenzg armenzg merged commit 5907851 into master Apr 16, 2026
81 checks passed
@armenzg armenzg deleted the separate_function_names branch April 16, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants