Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 06e8d9d

Browse files
committed
Change to just state ignore
1 parent e0c87a6 commit 06e8d9d

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

upload/helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,17 @@ def insert_commit(commitid, branch, pr, repository, owner, parent_commit_id=None
495495
"state": "pending",
496496
},
497497
)
498+
499+
edited = False
500+
if parent_commit_id and commit.parent_commit_id is None:
501+
commit.parent_commit_id = parent_commit_id
502+
edited = True
503+
if branch and commit.branch != branch:
504+
# A branch head may have been moved; this allows commits to be "moved"
505+
commit.branch = branch
506+
edited = True
507+
if edited:
508+
commit.save(update_fields=["parent_commit_id", "state", "branch"])
498509
return commit
499510

500511

upload/tests/test_upload.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,54 @@ def test_insert_commit(self):
627627
assert commit.merged == False
628628
assert commit.parent_commit_id is None
629629

630+
with self.subTest("commit already in database"):
631+
G(
632+
Commit,
633+
commitid="1c78206f1a46dc6db8412a491fc770eb7d0f8a47",
634+
branch="apples",
635+
pullid="456",
636+
repository=repo,
637+
parent_commit_id=None,
638+
)
639+
# parent_commit_id and branch should be updated
640+
insert_commit(
641+
"1c78206f1a46dc6db8412a491fc770eb7d0f8a47",
642+
"oranges",
643+
"123",
644+
repo,
645+
org,
646+
parent_commit_id="different_parent_commit",
647+
)
648+
649+
commit = Commit.objects.get(
650+
commitid="1c78206f1a46dc6db8412a491fc770eb7d0f8a47"
651+
)
652+
assert commit.repository == repo
653+
assert commit.branch == "oranges"
654+
assert commit.pullid == 456
655+
assert commit.merged is None
656+
assert commit.parent_commit_id == "different_parent_commit"
657+
658+
with self.subTest("parent provided"):
659+
parent = G(Commit)
660+
insert_commit(
661+
"8458a8c72aafb5fb4c5cd58f467a2f71298f1b61",
662+
"test",
663+
None,
664+
repo,
665+
org,
666+
parent_commit_id=parent.commitid,
667+
)
668+
669+
commit = Commit.objects.get(
670+
commitid="8458a8c72aafb5fb4c5cd58f467a2f71298f1b61"
671+
)
672+
assert commit.repository == repo
673+
assert commit.branch == "test"
674+
assert commit.pullid is None
675+
assert commit.merged is None
676+
assert commit.parent_commit_id == parent.commitid
677+
630678
def test_parse_request_headers(self):
631679
with self.subTest("Invalid content disposition"):
632680
with self.assertRaises(ValidationError):

0 commit comments

Comments
 (0)