Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions devel/management/commands/read_bumpbuddy_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


import logging
from urllib.parse import quote as urlquote

import requests
from django.conf import settings
Expand All @@ -17,6 +18,7 @@
from django.utils.timezone import now

from main.models import Package
from main.utils import gitlab_project_name_to_path
from packages.alpm import AlpmAPI
from packages.models import FlagRequest

Expand Down Expand Up @@ -63,11 +65,16 @@ def process_package(self, pkgdata):
current_time = now()
# Compatibility for old json output without issue
if 'issue' in pkgdata:
issue_url = f"{settings.GITLAB_PACKAGES_REPO}/{pkgbase}/-/issues/{pkgdata['issue']}"
scm_pkgbase = urlquote(gitlab_project_name_to_path(pkgbase))
issue_url = f"{settings.GITLAB_PACKAGES_REPO}/{scm_pkgbase}/-/issues/{pkgdata['issue']}"
message = f"New version {pkgdata['upstream_version']} is available: {issue_url}"
else:
message = f"New version {pkgdata['upstream_version']} is available."
packages.update(flag_date=current_time)

for pkg in ood_packages:
pkg.flag_date = current_time
pkg.save()

flag_request = FlagRequest(created=current_time,
user_email="bumpbuddy@archlinux.org",
message=message,
Expand Down Expand Up @@ -114,9 +121,6 @@ def handle(self, *args, **options):

flagged_packages = []
for pkgdata in req.json().values():
if not pkgdata['out_of_date']:
continue

package = self.process_package(pkgdata)
if package is not None:
flagged_packages.append(package)
Expand Down
39 changes: 39 additions & 0 deletions devel/tests/test_read_bumpbuddy_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

from django.test import TransactionTestCase
from django.utils.timezone import now

from devel.management.commands.read_bumpbuddy_status import Command as BumpBuddyCommand
from main.models import Arch, Package, Repo
from packages.models import FlagRequest


class RetireUsertest(TransactionTestCase):
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json']

def setUp(self):
pass

def process_package(self, pkgdata):
cmd = BumpBuddyCommand()
cmd.process_package(pkgdata)

def test_ood_package(self):
arch = Arch.objects.get(name='x86_64')
extra = Repo.objects.get(name='Extra')
created = now()
pkg = Package.objects.create(arch=arch, repo=extra, pkgname='systemd',
pkgbase='systemd', pkgver=100,
pkgrel=1, pkgdesc='Linux kernel',
compressed_size=10, installed_size=20,
last_update=created, created=created)

self.process_package({
'pkgbase': 'systemd',
'local_version': 100,
'upstream_version': 100,
'out_of_date': False,
'issue': 12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some json elements to not carry any issue property, so I'd suggest just to add a second test testing how process_package or the web code reacts to the missing issue property.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are really wip, they need to be extended more :)

})

flag_requests = FlagRequest.objects.all()
assert len(flag_requests) == 0
Loading