Skip to content

Commit

Permalink
fix: update update_commit to support tokenless v3
Browse files Browse the repository at this point in the history
we used to prepend the slug to the branch name when detecting that the
commit is on a fork, but now we want the format of a forked branch to be
<username>:<branch name> so we try to extract the username from the
slug of the head of the PR that the commit is on

Signed-off-by: joseph-sentry <joseph.sawaya@sentry.io>
  • Loading branch information
joseph-sentry committed May 13, 2024
1 parent f2ce06f commit d719133
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion services/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,19 @@ async def update_commit_from_provider_info(repository_service, commit):
# so we append the branch name with the fork slug
branch_name = commit_updates["head"]["branch"]
# TODO: 'slug' is in a `.get` because currently only GitHub returns that info

if commit_updates["head"].get("slug") != commit_updates["base"].get("slug"):
branch_name = commit_updates["head"]["slug"] + ":" + branch_name
# get rid of repo name in head.slug
try:
username = commit_updates["head"]["slug"].split("/")[0]
branch_name = username + ":" + branch_name
except:
log.error(
"Error updating branch name for commit originating from fork",
extra=dict(repoid=commit.repoid, commit=commit.commitid),
)
commit.branch = branch_name

commit.merged = False
else:
possible_branches = await repository_service.get_best_effort_branches(
Expand Down
3 changes: 2 additions & 1 deletion services/tests/test_repository_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ async def test_update_commit_from_provider_info_pull_from_fork(
_report_json=None,
repository=possible_parent_commit.repository,
)
commit.branch = "main"
dbsession.add(possible_parent_commit)
dbsession.add(commit)
dbsession.flush()
Expand Down Expand Up @@ -993,7 +994,7 @@ async def test_update_commit_from_provider_info_pull_from_fork(
assert commit.pullid == 1
assert commit.totals is None
assert commit.report_json == {}
assert commit.branch == f"some-guy/{commit.repository.name}:main"
assert commit.branch == "main"
assert commit.parent_commit_id == possible_parent_commit.commitid
assert commit.state == "complete"
assert commit.author is not None
Expand Down

0 comments on commit d719133

Please sign in to comment.