mirror of https://github.com/artifacthub/hub.git
Add subscriptions and webhooks stats to pkg details (#1274)
Related to #1247 Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
This commit is contained in:
parent
20c6540ae1
commit
daafabc5ae
|
|
@ -77,7 +77,11 @@ begin
|
|||
where pm.package_id = v_package_id
|
||||
),
|
||||
'recommendations', s.recommendations,
|
||||
'repository', (select get_repository_summary(r.repository_id))
|
||||
'repository', (select get_repository_summary(r.repository_id)),
|
||||
'stats', json_build_object(
|
||||
'subscriptions', (select count(*) from subscription where package_id = v_package_id),
|
||||
'webhooks', (select count(*) from webhook__package where package_id = v_package_id)
|
||||
)
|
||||
))
|
||||
from package p
|
||||
join snapshot s using (package_id)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ select plan(5);
|
|||
\set maintainer2ID '00000000-0000-0000-0000-000000000002'
|
||||
\set image1ID '00000000-0000-0000-0000-000000000001'
|
||||
\set image2ID '00000000-0000-0000-0000-000000000002'
|
||||
\set webhook1ID '00000000-0000-0000-0000-000000000001'
|
||||
|
||||
-- No packages at this point
|
||||
select is_empty(
|
||||
|
|
@ -205,6 +206,12 @@ insert into snapshot (
|
|||
'{"key": "value"}',
|
||||
'2020-06-16 11:20:34+02'
|
||||
);
|
||||
insert into subscription (user_id, package_id, event_kind_id)
|
||||
values (:'user1ID', :'package1ID', 0);
|
||||
insert into webhook (webhook_id, name, url, user_id)
|
||||
values (:'webhook1ID', 'webhook1', 'http://webhook1.url', :'user1ID');
|
||||
insert into webhook__event_kind (webhook_id, event_kind_id) values (:'webhook1ID', 0);
|
||||
insert into webhook__package (webhook_id, package_id) values (:'webhook1ID', :'package2ID');
|
||||
|
||||
-- Run some tests
|
||||
select is(
|
||||
|
|
@ -321,6 +328,10 @@ select is(
|
|||
"verified_publisher": false,
|
||||
"official": false,
|
||||
"user_alias": "user1"
|
||||
},
|
||||
"stats": {
|
||||
"subscriptions": 1,
|
||||
"webhooks": 0
|
||||
}
|
||||
}'::jsonb,
|
||||
'Last package1 version is returned as a json object'
|
||||
|
|
@ -440,6 +451,10 @@ select is(
|
|||
"verified_publisher": false,
|
||||
"official": false,
|
||||
"user_alias": "user1"
|
||||
},
|
||||
"stats": {
|
||||
"subscriptions": 1,
|
||||
"webhooks": 0
|
||||
}
|
||||
}'::jsonb,
|
||||
'Last package1 version is returned as a json object'
|
||||
|
|
@ -530,6 +545,10 @@ select is(
|
|||
"verified_publisher": false,
|
||||
"official": false,
|
||||
"user_alias": "user1"
|
||||
},
|
||||
"stats": {
|
||||
"subscriptions": 1,
|
||||
"webhooks": 0
|
||||
}
|
||||
}'::jsonb,
|
||||
'Requested package version is returned as a json object'
|
||||
|
|
@ -573,6 +592,10 @@ select is(
|
|||
"official": false,
|
||||
"organization_name": "org1",
|
||||
"organization_display_name": "Organization 1"
|
||||
},
|
||||
"stats": {
|
||||
"subscriptions": 0,
|
||||
"webhooks": 1
|
||||
}
|
||||
}'::jsonb,
|
||||
'Last package2 version is returned as a json object'
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ type Package struct {
|
|||
Recommendations []*Recommendation `json:"recommendations"`
|
||||
Repository *Repository `json:"repository"`
|
||||
TS int64 `json:"ts,omitempty"`
|
||||
Stats *PackageStats `json:"stats"`
|
||||
}
|
||||
|
||||
// PackageManager describes the methods a PackageManager implementation must
|
||||
|
|
@ -146,6 +147,12 @@ type PackageMetadata struct {
|
|||
Recommendations []*Recommendation `yaml:"recommendations"`
|
||||
}
|
||||
|
||||
// PackageStats represents some statistics about a package.
|
||||
type PackageStats struct {
|
||||
Subscriptions int `json:"subscriptions"`
|
||||
Webhooks int `json:"webhooks"`
|
||||
}
|
||||
|
||||
// Recommendation represents some information about a recommended package.
|
||||
type Recommendation struct {
|
||||
URL string `json:"url" yaml:"url"`
|
||||
|
|
|
|||
|
|
@ -134,6 +134,10 @@ func TestGet(t *testing.T) {
|
|||
OrganizationName: "org1",
|
||||
OrganizationDisplayName: "Organization 1",
|
||||
},
|
||||
Stats: &hub.PackageStats{
|
||||
Subscriptions: 1,
|
||||
Webhooks: 1,
|
||||
},
|
||||
}
|
||||
|
||||
db := &tests.DBMock{}
|
||||
|
|
@ -225,6 +229,10 @@ func TestGet(t *testing.T) {
|
|||
"user_alias": "user1",
|
||||
"organization_name": "org1",
|
||||
"organization_display_name": "Organization 1"
|
||||
},
|
||||
"stats": {
|
||||
"subscriptions": 1,
|
||||
"webhooks": 1
|
||||
}
|
||||
}
|
||||
`), nil)
|
||||
|
|
|
|||
Loading…
Reference in New Issue