mirror of https://github.com/sipwise/repoapi.git
This will allow us to have real info of the reviews we keep in the database Change-Id: Ic89189a2b71d34c1ee9abf23e167270a78eb25bemaster
parent
11bef4494c
commit
d2f948b1fe
@ -0,0 +1,24 @@
|
|||||||
|
- model: repoapi.gerritrepoinfo
|
||||||
|
pk: 47979
|
||||||
|
fields:
|
||||||
|
created: '2023-03-03 08:46:17'
|
||||||
|
gerrit_change: '67631'
|
||||||
|
modified: '2023-03-03 09:09:25'
|
||||||
|
param_ppa: gerrit_alessio_56718_bis_10_5_1,
|
||||||
|
projectname: templates
|
||||||
|
- model: repoapi.gerritrepoinfo
|
||||||
|
pk: 47877
|
||||||
|
fields:
|
||||||
|
created: '1977-01-01 00:00:00'
|
||||||
|
gerrit_change: '67510'
|
||||||
|
modified: '2023-03-02 16:24:25'
|
||||||
|
param_ppa: gerrit_alessio_56718_bis_11_1
|
||||||
|
projectname: sems-pbx
|
||||||
|
- model: repoapi.gerritrepoinfo
|
||||||
|
pk: 12
|
||||||
|
fields:
|
||||||
|
created: '1977-01-01 00:00:00'
|
||||||
|
gerrit_change: '13200'
|
||||||
|
modified: '2023-03-02 07:57:21'
|
||||||
|
param_ppa: gerrit_pu_collectd-abolition
|
||||||
|
projectname: unknown
|
@ -0,0 +1,42 @@
|
|||||||
|
# Copyright (C) 2023 The Sipwise Team - http://sipwise.com
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the Free
|
||||||
|
# Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
# more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along
|
||||||
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from gerrit.utils import get_change_info
|
||||||
|
from gerrit.utils import get_datetime
|
||||||
|
from repoapi.models.gri import GerritRepoInfo
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "gerrit actions"
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument("action", choices=["refresh"])
|
||||||
|
|
||||||
|
def refresh(self, *args, **options):
|
||||||
|
qs = GerritRepoInfo.objects.filter(created__date=date(1977, 1, 1))
|
||||||
|
for gri in qs.iterator():
|
||||||
|
info = get_change_info(gri.gerrit_change)
|
||||||
|
gri.created = get_datetime(info["created"])
|
||||||
|
gri.modified = get_datetime(info["updated"])
|
||||||
|
# don't update modified field on save
|
||||||
|
gri.update_modified = False
|
||||||
|
gri.save()
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
action = getattr(self, options["action"])
|
||||||
|
action(*args, **options)
|
@ -0,0 +1,68 @@
|
|||||||
|
# Copyright (C) 2023 The Sipwise Team - http://sipwise.com
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the Free
|
||||||
|
# Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
# more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along
|
||||||
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
import datetime
|
||||||
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.core.management import call_command
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from repoapi.models.gri import GerritRepoInfo
|
||||||
|
|
||||||
|
change_info = """
|
||||||
|
{
|
||||||
|
"id": "templates~mr10.5.1~I3a066ae039b06beb892a1f9e7b8dadf7aa476742",
|
||||||
|
"project": "templates",
|
||||||
|
"branch": "mr10.5.1",
|
||||||
|
"topic": "alessio_56718_bis_10_5_1",
|
||||||
|
"hashtags": [],
|
||||||
|
"change_id": "I3a066ae039b06beb892a1f9e7b8dadf7aa476742",
|
||||||
|
"subject": "MT#56718 Decrement counter of B in blind transfer",
|
||||||
|
"status": "NEW",
|
||||||
|
"created": "2023-03-03 08:45:06.000000000",
|
||||||
|
"updated": "2023-03-03 09:09:25.000000000",
|
||||||
|
"submit_type": "FAST_FORWARD_ONLY",
|
||||||
|
"mergeable": true,
|
||||||
|
"insertions": 104,
|
||||||
|
"deletions": 0,
|
||||||
|
"total_comment_count": 0,
|
||||||
|
"unresolved_comment_count": 0,
|
||||||
|
"has_review_started": true,
|
||||||
|
"_number": 67631,
|
||||||
|
"owner": {
|
||||||
|
"_account_id": 1000069
|
||||||
|
},
|
||||||
|
"requirements": []
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
value = json.loads(change_info)
|
||||||
|
|
||||||
|
|
||||||
|
class refreshTest(TestCase):
|
||||||
|
fixtures = ["test_gerrit_commands"]
|
||||||
|
|
||||||
|
@patch("gerrit.management.commands.gerrit.get_change_info")
|
||||||
|
def test_refresh(self, gci):
|
||||||
|
gci.return_value = value
|
||||||
|
qs = GerritRepoInfo.objects
|
||||||
|
self.assertEqual(qs.count(), 3)
|
||||||
|
qs_filter = qs.filter(created__date=datetime.date(1977, 1, 1))
|
||||||
|
self.assertEqual(qs_filter.count(), 2)
|
||||||
|
call_command("gerrit", "refresh")
|
||||||
|
self.assertEqual(qs.count(), 3)
|
||||||
|
self.assertEqual(qs_filter.count(), 0)
|
||||||
|
|
||||||
|
qs_filter = qs.filter(modified__time=datetime.time(9, 9, 25))
|
||||||
|
self.assertEqual(qs_filter.count(), 3)
|
Loading…
Reference in new issue