diff --git a/swh/web/api/views/origin.py b/swh/web/api/views/origin.py --- a/swh/web/api/views/origin.py +++ b/swh/web/api/views/origin.py @@ -20,10 +20,6 @@ :>json string origin_visits_url: link to in order to get information about the visits for that origin :>json string url: the origin canonical url - :>json string type: the type of software origin (deprecated value; - types are now associated to visits instead of origins) - :>json number id: the origin unique identifier (deprecated value; - you should only refer to origins based on their URL) ''' DOC_RETURN_ORIGIN_ARRAY = \ @@ -105,6 +101,9 @@ query_params={'origin_from': origin_from, 'origin_count': origin_count}, request=request) + for result in results: + if 'id' in result: + del result['id'] return response diff --git a/swh/web/browse/views/origin.py b/swh/web/browse/views/origin.py --- a/swh/web/browse/views/origin.py +++ b/swh/web/browse/views/origin.py @@ -119,7 +119,7 @@ view_name='browse-origin-visits') def origin_visits_browse(request, origin_url): """Django view that produces an HTML display of visits reporting - for a swh origin identified by its id or its url. + for a given origin. The url that points to it is :http:get:`/browse/origin/(origin_url)/visits/`. diff --git a/swh/web/common/origin_visits.py b/swh/web/common/origin_visits.py --- a/swh/web/common/origin_visits.py +++ b/swh/web/common/origin_visits.py @@ -24,10 +24,11 @@ following keys: * **date**: UTC visit date in ISO format, - * **origin**: the origin id + * **origin**: the origin url * **status**: the visit status, either **full**, **partial** or **ongoing** * **visit**: the visit id + * **type**: the visit type Raises: NotFoundExc: if the origin is not found @@ -94,13 +95,12 @@ Args: origin_info (dict): a dict filled with origin information - (id, url, type) visit_ts (int or str): an ISO date string or Unix timestamp to parse Returns: A dict containing the visit info as described below:: - {'origin': 2, + {'origin': 'https://forge.softwareheritage.org/source/swh-web/', 'date': '2017-10-08T11:54:25.582463+00:00', 'metadata': {}, 'visit': 25, @@ -110,39 +110,23 @@ visits = get_origin_visits(origin_info) if not visits: - if 'url' in origin_info: - message = ('No visit associated to origin with' - ' url %s!' % origin_info['url']) - else: - message = ('No visit associated to origin with' - ' id %s!' % origin_info['id']) - raise NotFoundExc(message) + raise NotFoundExc(('No visit associated to origin with' + ' url %s!' % origin_info['url'])) if snapshot_id: visit = [v for v in visits if v['snapshot'] == snapshot_id] if len(visit) == 0: - if 'type' in origin_info and 'url' in origin_info: - message = ('Visit for snapshot with id %s for origin with type' - ' url %s not found!' % - (snapshot_id, origin_info['url'])) - else: - message = ('Visit for snapshot with id %s for origin with' - ' id %s not found!' % - (snapshot_id, origin_info['id'])) - raise NotFoundExc(message) + raise NotFoundExc(('Visit for snapshot with id %s for origin with' + ' url %s not found!' % + (snapshot_id, origin_info['url']))) return visit[0] if visit_id: visit = [v for v in visits if v['visit'] == int(visit_id)] if len(visit) == 0: - if 'type' in origin_info and 'url' in origin_info: - message = ('Visit with id %s for origin with' - ' and url %s not found!' % - (visit_id, origin_info['url'])) - else: - message = ('Visit with id %s for origin with id %s' - ' not found!' % (visit_id, origin_info['id'])) - raise NotFoundExc(message) + raise NotFoundExc(('Visit with id %s for origin with' + ' url %s not found!' % + (visit_id, origin_info['url']))) return visit[0] if not visit_ts: @@ -170,11 +154,6 @@ visit = visits[visit_idx] return visit else: - if 'type' in origin_info and 'url' in origin_info: - message = ('Visit with timestamp %s for origin with ' - 'and url %s not found!' % - (visit_ts, origin_info['url'])) - else: - message = ('Visit with timestamp %s for origin with id %s ' - 'not found!' % (visit_ts, origin_info['id'])) - raise NotFoundExc(message) + raise NotFoundExc(('Visit with timestamp %s for origin with ' + 'url %s not found!' % + (visit_ts, origin_info['url']))) diff --git a/swh/web/tests/common/test_origin_visits.py b/swh/web/tests/common/test_origin_visits.py --- a/swh/web/tests/common/test_origin_visits.py +++ b/swh/web/tests/common/test_origin_visits.py @@ -42,7 +42,7 @@ origin_info = { 'id': 1, - 'type': 'git', + 'url': 'https://github.com/foo/bar', } @@ -55,8 +55,6 @@ mock_origin_visits = mocker.patch( 'swh.web.common.origin_visits.get_origin_visits') origin_info = { - 'id': 2, - 'type': 'git', 'url': 'https://github.com/foo/bar', } visits = [ @@ -64,31 +62,36 @@ 'status': 'full', 'date': '2015-07-09T21:09:24+00:00', 'visit': 1, - 'origin': origin_info['id'] + 'origin': 'https://github.com/foo/bar', + 'type': 'git', }, { 'status': 'full', 'date': '2016-02-23T18:05:23.312045+00:00', 'visit': 2, - 'origin': origin_info['id'] + 'origin': 'https://github.com/foo/bar', + 'type': 'git', }, { 'status': 'full', 'date': '2016-03-28T01:35:06.554111+00:00', 'visit': 3, - 'origin': origin_info['id'] + 'origin': 'https://github.com/foo/bar', + 'type': 'git', }, { 'status': 'full', 'date': '2016-06-18T01:22:24.808485+00:00', 'visit': 4, - 'origin': origin_info['id'] + 'origin': 'https://github.com/foo/bar', + 'type': 'git', }, { 'status': 'full', 'date': '2016-08-14T12:10:00.536702+00:00', 'visit': 5, - 'origin': origin_info['id'] + 'origin': 'https://github.com/foo/bar', + 'type': 'git', } ] mock_origin_visits.return_value = visits