Skip to content

Commit

Permalink
Populate signoffs with a commit message of the tag in extra-testing, …
Browse files Browse the repository at this point in the history
…not the latest commit

Fixes #533
  • Loading branch information
lahwaacz authored and jelly committed Jan 11, 2025
1 parent 4210a46 commit 87a0d37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions packages/management/commands/populate_signoffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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]
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions packages/tests/test_populate_signoffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ 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': '[email protected]'}
get_tag_info.return_value = {'message': f'{comment}\n', 'author': '[email protected]'}
call_command('populate_signoffs')

signoff_spec = SignoffSpecification.objects.first()
assert signoff_spec.comments == comment
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

0 comments on commit 87a0d37

Please sign in to comment.