Merge ~pappacena/launchpad:forked-repo-owner-default into launchpad:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: 59de4d866dfefce283c01145a09feae3348d14a5
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/launchpad:forked-repo-owner-default
Merge into: launchpad:master
Diff against target: 50 lines (+23/-0)
2 files modified
lib/lp/code/model/gitrepository.py (+7/-0)
lib/lp/code/model/tests/test_gitrepository.py (+16/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+392381@code.launchpad.net

Commit message

Setting forked repo as owner-default if no other repo is set that way.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Needs Information
59de4d8... by Thiago F. Pappacena

Marking repository as owner-default when forking, not confirming

Revision history for this message
Thiago F. Pappacena (pappacena) :
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/code/model/gitrepository.py b/lib/lp/code/model/gitrepository.py
2index 44b9315..f7a2a0b 100644
3--- a/lib/lp/code/model/gitrepository.py
4+++ b/lib/lp/code/model/gitrepository.py
5@@ -1772,6 +1772,13 @@ class GitRepositorySet:
6 date_created=UTC_NOW, description=origin.description,
7 with_hosting=True, async_hosting=True,
8 status=GitRepositoryStatus.CREATING)
9+ try:
10+ # Try to set the new repo as owner-default.
11+ repository.setOwnerDefault(True)
12+ except GitDefaultConflict:
13+ # If there is already a owner-default for this owner/target,
14+ # just move on.
15+ pass
16 return repository
17
18 def getByPath(self, user, path):
19diff --git a/lib/lp/code/model/tests/test_gitrepository.py b/lib/lp/code/model/tests/test_gitrepository.py
20index 6f65250..7d7464e 100644
21--- a/lib/lp/code/model/tests/test_gitrepository.py
22+++ b/lib/lp/code/model/tests/test_gitrepository.py
23@@ -2750,6 +2750,21 @@ class TestGitRepositoryFork(TestCaseWithFactory):
24 repo, another_person, another_team)
25 self.assertEqual(another_team, forked_repo.owner)
26 self.assertEqual(another_person, forked_repo.registrant)
27+ self.assertTrue(forked_repo.owner_default)
28+ self.assertEqual(1, self.hosting_fixture.create.call_count)
29+
30+ def test_fork_not_owner_default(self):
31+ repo = self.factory.makeGitRepository()
32+ # The person forking the repo already has another repo which is the
33+ # owner-default for that owner & target.
34+ previous_repo = self.factory.makeGitRepository(target=repo.target)
35+ previous_repo.setOwnerDefault(True)
36+
37+ forked_repo = getUtility(IGitRepositorySet).fork(
38+ repo, previous_repo.owner, previous_repo.owner)
39+ self.assertEqual(previous_repo.owner, forked_repo.owner)
40+ self.assertEqual(previous_repo.owner, forked_repo.registrant)
41+ self.assertFalse(forked_repo.owner_default)
42 self.assertEqual(1, self.hosting_fixture.create.call_count)
43
44 def test_fork_same_name(self):
45@@ -2762,6 +2777,7 @@ class TestGitRepositoryFork(TestCaseWithFactory):
46
47 forked_repo = getUtility(IGitRepositorySet).fork(repo, person, person)
48 self.assertEqual(forked_repo.target, repo.target)
49+ self.assertTrue(forked_repo.owner_default)
50 self.assertEqual(forked_repo.name, "%s-1" % same_name_repo.name)
51
52