Skip to content
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

Enhance commit retrieval with branch & tag prefix support #3518

Merged
merged 2 commits into from
Aug 27, 2024

Conversation

marcsanmi
Copy link
Contributor

@marcsanmi marcsanmi commented Aug 26, 2024

GitHub's API documentation states:

ref string Required
The commit reference. Can be a commit SHA, branch name (heads/BRANCH_NAME), or tag name (tags/TAG_NAME)."

This PR enhances our commit retrieval to align with this specification:

  • Implements logic to try different prefixes (none, heads/, tags/) when fetching commits
  • Introduces gitHubCommitGetter interface for better abstraction
  • Adds unit tests to cover multiple scenarios

@marcsanmi marcsanmi requested a review from a team as a code owner August 26, 2024 07:51
@CLAassistant
Copy link

CLAassistant commented Aug 26, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@kolesnikovae kolesnikovae left a comment

Choose a reason for hiding this comment

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

Nice work! I've added a couple of comments re error handling. Otherwise, it looks good to me 👍🏻

pkg/querier/vcs/service.go Outdated Show resolved Hide resolved
pkg/querier/vcs/service.go Outdated Show resolved Hide resolved
@marcsanmi marcsanmi requested a review from kolesnikovae August 26, 2024 12:14
@marcsanmi marcsanmi force-pushed the prefix-git-ref-with-tags-head branch from ffe2521 to 1c36f1b Compare August 26, 2024 12:27
Copy link
Collaborator

@kolesnikovae kolesnikovae left a comment

Choose a reason for hiding this comment

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

LGTM!

pkg/querier/vcs/client/github.go Outdated Show resolved Hide resolved
@marcsanmi marcsanmi requested a review from kolesnikovae August 27, 2024 07:12
@marcsanmi marcsanmi force-pushed the prefix-git-ref-with-tags-head branch from bf7d9b8 to dd0342a Compare August 27, 2024 07:36
Copy link
Contributor

@bryanhuhta bryanhuhta left a comment

Choose a reason for hiding this comment

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

:shipit:

Comment on lines +211 to +215
refFormats := []string{
ref, // Try as a commit hash
"heads/" + ref, // Try as a branch
"tags/" + ref, // Try as a tag
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Eventually I think we will want to try be smarter about using the SHA, heads, or tags ref. Someone could theoretically have the same name for a branch and tag.

I don't think we should address this here, as this PR is enough of an improvement already, but it is something to think of for the future.

@marcsanmi marcsanmi merged commit 366d582 into main Aug 27, 2024
18 checks passed
@marcsanmi marcsanmi deleted the prefix-git-ref-with-tags-head branch August 27, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants