-
-
Notifications
You must be signed in to change notification settings - Fork 147
devel: import bumpbuddy out of date information #598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jelly
wants to merge
2
commits into
archlinux:master
Choose a base branch
from
jelly:bump-buddy-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| #!/usr/bin/python | ||
|
|
||
|
|
||
| """ | ||
| read_bumpbuddy_status | ||
|
|
||
| Usage: ./manage.py read_bumpbuddy_status | ||
| """ | ||
|
|
||
|
|
||
| import logging | ||
| from urllib.parse import quote as urlquote | ||
|
|
||
| import requests | ||
| from django.conf import settings | ||
| from django.core.cache import cache | ||
| from django.core.management.base import BaseCommand | ||
| 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 | ||
|
|
||
| logger = logging.getLogger("command") | ||
| logger.setLevel(logging.WARNING) | ||
|
|
||
|
|
||
| alpm = AlpmAPI() | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| def process_package(self, pkgdata): | ||
| pkgbase = pkgdata['pkgbase'] | ||
| version = pkgdata['local_version'] | ||
| upstream_version = pkgdata['upstream_version'] | ||
| logger.debug("Import new out of date package '%s'", pkgbase) | ||
|
|
||
| packages = Package.objects.filter(pkgbase=pkgbase) | ||
| found_packages = list(packages) | ||
|
|
||
| if len(found_packages) == 0: | ||
| logger.error("no matching packages found for pkgbase='%s'", pkgbase) | ||
| return | ||
|
|
||
| # already flagged | ||
| not_flagged_packages = [pkg for pkg in found_packages if pkg.flag_date is None] | ||
| if len(not_flagged_packages) == 0: | ||
| return | ||
|
|
||
| ood_packages = [pkg for pkg in not_flagged_packages if alpm.vercmp(upstream_version, pkg.pkgver) > 0] | ||
| if len(ood_packages) == 0: | ||
| logger.debug("package is not out of date for pkgbase='%s'", pkgbase) | ||
| return | ||
|
|
||
| pkg = ood_packages[0] | ||
|
|
||
| # find a common version if there is one available to store | ||
| versions = {(pkg.pkgver, pkg.pkgrel, pkg.epoch) for pkg in ood_packages} | ||
| if len(versions) == 1: | ||
| version = versions.pop() | ||
| else: | ||
| version = ('', '', 0) | ||
|
|
||
| current_time = now() | ||
| # Compatibility for old json output without issue | ||
| if 'issue' in pkgdata: | ||
| 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." | ||
|
|
||
| for pkg in ood_packages: | ||
| pkg.flag_date = current_time | ||
| pkg.save() | ||
|
|
||
| flag_request = FlagRequest(created=current_time, | ||
| user_email="[email protected]", | ||
| message=message, | ||
| ip_address="0.0.0.0", | ||
| pkgbase=pkg.pkgbase, | ||
| repo=pkg.repo, | ||
| pkgver=version[0], | ||
| pkgrel=version[1], | ||
| epoch=version[2], | ||
| num_packages=len(ood_packages)) | ||
|
|
||
| return flag_request | ||
|
|
||
| def handle(self, *args, **options): | ||
| v = int(options.get('verbosity', 0)) | ||
| if v == 0: | ||
| logger.level = logging.ERROR | ||
| elif v == 1: | ||
| logger.level = logging.INFO | ||
| elif v >= 2: | ||
| logger.level = logging.DEBUG | ||
|
|
||
| url = getattr(settings, "BUMPBUDDY_URL", None) | ||
| assert url is not None, "BUMPBUDDY_URL not configured" | ||
|
|
||
| headers = {} | ||
| last_modified = cache.get('bumpbuddy:last-modified') | ||
| if last_modified: | ||
| logger.debug('Setting If-Modified-Since header') | ||
| headers = {'If-Modified-Since': last_modified} | ||
|
|
||
| req = requests.get(url, headers) | ||
| if req.status_code == 304: | ||
| logger.debug('The rebuilderd data has not been updated since we last checked it') | ||
| return | ||
|
|
||
| if req.status_code != 200: | ||
| logger.error("Issues retrieving bumpbuddy data: '%s'", req.status_code) | ||
| return | ||
|
|
||
| last_modified = req.headers.get('last-modified') | ||
| if last_modified: | ||
| cache.set('bumpbuddy:last-modified', last_modified, 3600) # cache one hour | ||
|
|
||
| flagged_packages = [] | ||
| for pkgdata in req.json().values(): | ||
| package = self.process_package(pkgdata) | ||
| if package is not None: | ||
| flagged_packages.append(package) | ||
|
|
||
| if flagged_packages: | ||
| logger.info("Imported %d new out of date packages", len(flagged_packages)) | ||
| FlagRequest.objects.bulk_create(flagged_packages) | ||
|
|
||
|
|
||
| # vim: set ts=4 sw=4 et: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| }) | ||
|
|
||
| flag_requests = FlagRequest.objects.all() | ||
| assert len(flag_requests) == 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
issueproperty, so I'd suggest just to add a second test testing how process_package or the web code reacts to the missingissueproperty.There was a problem hiding this comment.
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 :)