diff --git a/main/fixtures/repos.json b/main/fixtures/repos.json index 088750ce..4b315de0 100644 --- a/main/fixtures/repos.json +++ b/main/fixtures/repos.json @@ -11,6 +11,18 @@ "testing": true } }, + { + "pk": 15, + "model": "main.repo", + "fields": { + "bugs_category": 33, + "staging": true, + "name": "Extra-Staging", + "bugs_project": 5, + "svn_root": "packages", + "testing": false + } + }, { "pk": 1, "model": "main.repo", @@ -118,5 +130,17 @@ "svn_root": "packages", "testing": true } + }, + { + "pk": 16, + "model": "main.repo", + "fields": { + "bugs_category": 10, + "staging": true, + "name": "Core-Staging", + "bugs_project": 1, + "svn_root": "packages", + "testing": false + } } ] diff --git a/packages/management/commands/populate_signoffs.py b/packages/management/commands/populate_signoffs.py index f104f4af..25dc6a90 100644 --- a/packages/management/commands/populate_signoffs.py +++ b/packages/management/commands/populate_signoffs.py @@ -52,7 +52,7 @@ def create_specification(package, log, finder): return spec -def get_last_log(repo, pkgbase): +def get_tag_info(repo, pkgbase, version): # Gitlab requires the path to the gitlab repo to be html encoded and project name encoded in a different special way pkgrepo = urllib.parse.quote_plus(f'{settings.GITLAB_PACKAGE_REPO}/') + gitlab_project_name_to_path(pkgbase) url = f'https://{settings.GITLAB_INSTANCE}/api/v4/projects/{pkgrepo}/repository/tags' @@ -65,8 +65,12 @@ def get_last_log(repo, pkgbase): return None tags = r.json() + + # filter out unrelated tags + tags = [tag for tag in tags if tag["name"] == version] + if len(tags) == 0: - logger.error("No tags found for pkgbase %s (%s)", pkgbase, repo) + logger.error("No tags found for pkgbase %s (%s) version %s", pkgbase, repo, version) return None tag = tags[0] @@ -89,7 +93,7 @@ def add_signoff_comments(): if not group.default_spec: continue - log = get_last_log(group.repo, group.pkgbase) + log = get_tag_info(group.repo, group.pkgbase, group.version) if log is None: continue diff --git a/packages/tests/test_populate_signoffs.py b/packages/tests/test_populate_signoffs.py index 8e767de0..db55d2ba 100644 --- a/packages/tests/test_populate_signoffs.py +++ b/packages/tests/test_populate_signoffs.py @@ -26,9 +26,9 @@ def tearDown(self): self.package.delete() def test_basic(self): - with mock.patch('packages.management.commands.populate_signoffs.get_last_log') as get_last_log: + with mock.patch('packages.management.commands.populate_signoffs.get_tag_info') as get_tag_info: comment = 'upgpkg: 0.1-1: rebuild' - get_last_log.return_value = {'message': f'{comment}\n', 'author': 'foo@archlinux.org'} + get_tag_info.return_value = {'message': f'{comment}\n', 'author': 'foo@archlinux.org'} call_command('populate_signoffs') signoff_spec = SignoffSpecification.objects.first() @@ -36,8 +36,8 @@ def test_basic(self): assert signoff_spec.pkgbase == self.package.pkgbase def test_invalid(self): - with mock.patch('packages.management.commands.populate_signoffs.get_last_log') as get_last_log: - get_last_log.return_value = None + with mock.patch('packages.management.commands.populate_signoffs.get_tag_info') as get_tag_info: + get_tag_info.return_value = None call_command('populate_signoffs') assert SignoffSpecification.objects.count() == 0