Merge ~nacc/git-ubuntu:importer-test-messages into git-ubuntu:master

Proposed by Nish Aravamudan
Status: Merged
Merged at revision: 79f54b6cd37029f646de8621d56acad5db869198
Proposed branch: ~nacc/git-ubuntu:importer-test-messages
Merge into: git-ubuntu:master
Diff against target: 243 lines (+162/-14)
2 files modified
gitubuntu/importer.py (+60/-13)
gitubuntu/test_importer.py (+102/-1)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Andreas Hasenack Approve
Review via email: mp+342967@code.launchpad.net

Commit message

Make jenkins happy

To post a comment you must log in.
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

+1

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:79f54b6cd37029f646de8621d56acad5db869198
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/392/
Executed test runs:
    SUCCESS: VM Setup
    SUCCESS: Build
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/392/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/gitubuntu/importer.py b/gitubuntu/importer.py
2index 42ab520..78fc3dc 100644
3--- a/gitubuntu/importer.py
4+++ b/gitubuntu/importer.py
5@@ -467,6 +467,52 @@ def get_changelog_for_commit(
6 changelog_entry_found = True
7 return changelog_entry
8
9+def get_import_commit_msg(
10+ repo,
11+ spi,
12+ namespace,
13+ tree_hash,
14+ changelog_parent_commit,
15+ upload_parent_commit,
16+ unapplied_parent_commit,
17+):
18+ if unapplied_parent_commit:
19+ import_type = 'patches-applied'
20+ target_head_name = spi.applied_head_name(namespace)
21+ else:
22+ import_type = 'patches-unapplied'
23+ target_head_name = spi.head_name(namespace)
24+
25+ # Do not show importer/ namespace to user
26+ _, _, pretty_head_name = target_head_name.partition('%s/' % namespace)
27+ changelog_entry = get_changelog_for_commit(
28+ repo,
29+ tree_hash,
30+ changelog_parent_commit
31+ )
32+
33+ msg = (
34+ b'Import %s version %b to %b\n\nImported using git-ubuntu import.' % (
35+ import_type.encode(),
36+ spi.version.encode(),
37+ pretty_head_name.encode(),
38+ )
39+ )
40+
41+ if any([changelog_parent_commit, upload_parent_commit, unapplied_parent_commit]):
42+ msg += b'\n'
43+
44+ if changelog_parent_commit is not None:
45+ msg += b'\nChangelog parent: %b' % changelog_parent_commit.encode()
46+ if upload_parent_commit is not None:
47+ msg += b'\nUpload parent: %b' % upload_parent_commit.encode()
48+ if unapplied_parent_commit is not None:
49+ msg += b'\nUnapplied parent: %b' % unapplied_parent_commit.encode()
50+
51+ msg += b'%b' % changelog_entry
52+
53+ return msg
54+
55 def _commit_import(
56 repo,
57 spi,
58@@ -514,9 +560,6 @@ def _commit_import(
59 tree_hash,
60 changelog_parent_commit
61 )
62- msg = (b'Import %s version %b to %b\n\nImported using git-ubuntu import.' %
63- (import_type.encode(), spi.version.encode(), pretty_head_name.encode())
64- )
65
66 parents = []
67
68@@ -526,26 +569,27 @@ def _commit_import(
69 target_head_name in repo.local_branch_names:
70 # No parents and not creating a new branch
71 tag = orphan_tag(spi.version, namespace)
72- else:
73- msg += b'\n'
74
75 if changelog_parent_commit is not None:
76 parents.append(changelog_parent_commit)
77- msg += b'\nChangelog parent: %b' % changelog_parent_commit.encode()
78 if upload_parent_commit is not None:
79 parents.append(upload_parent_commit)
80- msg += b'\nUpload parent: %b' % upload_parent_commit.encode()
81 if unapplied_parent_commit is not None:
82 parents.append(unapplied_parent_commit)
83- msg += b'\nUnapplied parent: %b' % unapplied_parent_commit.encode()
84-
85- msg += b'%b' % changelog_entry
86
87 commit_hash = repo.commit_tree_hash(
88 tree_hash,
89 parents,
90- msg,
91- environment_spi=spi
92+ get_import_commit_msg(
93+ repo=repo,
94+ spi=spi,
95+ namespace=namespace,
96+ tree_hash=tree_hash,
97+ changelog_parent_commit=changelog_parent_commit,
98+ upload_parent_commit=upload_parent_commit,
99+ unapplied_parent_commit=unapplied_parent_commit,
100+ ),
101+ environment_spi=spi,
102 )
103
104 repo.update_head_to_commit(target_head_name, commit_hash)
105@@ -1080,6 +1124,10 @@ def update_devel_branches(
106 repo.update_head_to_commit(ref, commit)
107
108
109+def get_import_tag_msg():
110+ return 'git-ubuntu import v%s' % VERSION
111+
112+
113 # imports a package based upon source package information
114 def import_unapplied_spi(
115 repo,
116@@ -1172,7 +1220,6 @@ def import_unapplied_spi(
117
118 unapplied_changelog_parent_commit = None
119 upload_parent_commit = None
120- unapplied_parent_commit = None
121
122 if spi.version in parent_overrides:
123 logging.debug(
124diff --git a/gitubuntu/test_importer.py b/gitubuntu/test_importer.py
125index 5ce59da..7fd5f45 100644
126--- a/gitubuntu/test_importer.py
127+++ b/gitubuntu/test_importer.py
128@@ -1,9 +1,19 @@
129-from unittest.mock import sentinel
130+from unittest.mock import (
131+ Mock,
132+ patch,
133+ sentinel,
134+)
135
136 import pytest
137
138+
139+import gitubuntu.repo_builder as repo_builder
140+import gitubuntu.source_builder as source_builder
141+
142 import gitubuntu.importer as target
143
144+from gitubuntu.test_git_repository import pygit2, repo
145+
146
147 @pytest.mark.parametrize('head_versions,expected', [
148 (
149@@ -47,3 +57,94 @@ def test_devel_branch_updates(head_versions, expected):
150 ['yakkety', 'xenial', 'trusty'],
151 )
152 assert set(result) == set(expected.items())
153+
154+
155+@patch('gitubuntu.importer.VERSION', '1.0')
156+def test_get_import_tag_msg():
157+ assert target.get_import_tag_msg() == 'git-ubuntu import v1.0'
158+
159+
160+@pytest.mark.parametrize(
161+ 'head_name_value, changelog_parent_commit, upload_parent_commit, unapplied_parent_commit, expected',
162+ [
163+ (
164+ 'importer/ubuntu/trusty',
165+ None,
166+ None,
167+ None,
168+ b'Import patches-unapplied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.',
169+ ),
170+ (
171+ 'importer/ubuntu/trusty',
172+ '123456',
173+ None,
174+ None,
175+ b'Import patches-unapplied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.\n\nChangelog parent: 123456',
176+ ),
177+ (
178+ 'importer/ubuntu/trusty',
179+ None,
180+ '123456',
181+ None,
182+ b'Import patches-unapplied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.\n\nUpload parent: 123456',
183+ ),
184+ (
185+ 'importer/ubuntu/trusty',
186+ None,
187+ None,
188+ '123456',
189+ b'Import patches-applied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.\n\nUnapplied parent: 123456',
190+ ),
191+ (
192+ 'importer/ubuntu/trusty',
193+ '123456',
194+ '789123',
195+ '456789',
196+ b'Import patches-applied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.\n\nChangelog parent: 123456\nUpload parent: 789123\nUnapplied parent: 456789'
197+ ),
198+ ],
199+)
200+def test_get_import_commit_msg(
201+ repo,
202+ head_name_value,
203+ changelog_parent_commit,
204+ upload_parent_commit,
205+ unapplied_parent_commit,
206+ expected,
207+):
208+ target.get_changelog_for_commit = Mock()
209+ target.get_changelog_for_commit.return_value = b''
210+
211+ publish_spec = source_builder.SourceSpec(
212+ version='1-1',
213+ native=False,
214+ )
215+ publish_source = source_builder.Source(publish_spec)
216+
217+ publish_oid = repo_builder.SourceTree(publish_source).write(repo.raw_repo)
218+ publish_tree_hash = str(
219+ repo.raw_repo.get(publish_oid).peel(pygit2.Tree).id
220+ )
221+
222+ with publish_source as dsc_path:
223+ spi = Mock()
224+ spi.dsc_pathname = dsc_path
225+ spi.distribution.name = 'Ubuntu'
226+ spi.version = publish_spec.version
227+ # avoid automatic parenting for head_name to make the assertion later
228+ # easier
229+ head_name = Mock(name='head_name')
230+ head_name.return_value = head_name_value
231+ spi.head_name = head_name
232+ spi.applied_head_name = head_name
233+ spi.date_published = '1970-01-01T00:00:00Z'
234+
235+ assert target.get_import_commit_msg(
236+ repo,
237+ spi,
238+ 'importer',
239+ publish_tree_hash,
240+ changelog_parent_commit,
241+ upload_parent_commit,
242+ unapplied_parent_commit,
243+ ) == expected

Subscribers

People subscribed via source and target branches