Skip to content

Commit a7c38e0

Browse files
committed
feat: collectionSlug support for activity-types + contributor dependency pipes (IN-1195)
- activityTypes_by_project.pipe: branch segmentId scoping to support collectionSlug alongside project, fixing the activity-type/platform filter dropdown on collection pages (was previously project-only, causing the dropdown to silently show no options). - collection_contributor_dependency.pipe: new dedicated pipe for the Contributor Dependency widget on collection pages, composing collection_contributors_leaderboard instead of the project-only contributors_leaderboard pipe. Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
1 parent 938f542 commit a7c38e0

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

services/libs/tinybird/pipes/activityTypes_by_project.pipe

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
DESCRIPTION >
2-
- `activityTypes_by_project.pipe` returns activity types that actually exist for a given project.
2+
- `activityTypes_by_project.pipe` returns activity types that actually exist for a given project, or
3+
across every project in a collection.
34
- Unlike `activityTypes_filtered` which returns all possible activity types, this pipe only returns types with actual activities in the project.
45
- Useful for populating dropdowns, filters, or analytics that should only show activity types with data.
56
- Parameters:
6-
- `project`: **Required** string for project slug (e.g., 'k8s', 'tensorflow'). Passed to `segments_filtered`.
7+
- `project`: String for project slug (e.g., 'k8s', 'tensorflow'). Passed to `segments_filtered`. Required unless `collectionSlug` is given.
8+
- `collectionSlug`: Collection slug (e.g., 'cncf') - inherited from `segments_filtered_by_collection`. Required unless `project` is given.
79
- `repos`: Optional array of repository URLs for filtering (e.g., ['https://github.com/kubernetes/kubernetes']). Filters activities by repository.
810
- `includeCodeContributions`: Optional boolean to include code contribution activities. Defaults to 1. Set to 0 to exclude. Passed to `activityTypes_filtered`.
911
- `includeCollaborations`: Optional boolean to include or exclude collaboration activities. Defaults to 0. Passed to `activityTypes_filtered`.
@@ -18,7 +20,10 @@ SQL >
1820
FROM activityRelations_bucket_routing a
1921
INNER JOIN activityTypes at ON a.type = at.activityType AND a.platform = at.platform
2022
WHERE
21-
a.segmentId = (SELECT segmentId FROM segments_filtered)
23+
{% if defined(collectionSlug) %}
24+
a.segmentId IN (SELECT segmentId FROM segments_filtered_by_collection)
25+
{% else %} a.segmentId = (SELECT segmentId FROM segments_filtered)
26+
{% end %}
2227
{% if defined(repos) %} AND a.channel IN (SELECT channel FROM repos_to_channels) {% end %}
2328
AND (a.type, a.platform) IN (SELECT activityType, platform FROM activityTypes_filtered)
2429
ORDER BY activityType, platform
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
DESCRIPTION >
2+
- `collection_contributor_dependency.pipe` serves the contributor dependency widget for a
3+
collection's Contributors tab - identifies contributors whose combined contributions reach or
4+
exceed 51% of total collection activity (bus factor analysis), aggregated across every project
5+
in the collection.
6+
- Collection-scoped counterpart to `contributor_dependency.pipe` - separate because that pipe
7+
references `contributors_leaderboard` (project-only) by name, and the collection-scale
8+
replacement for that table is `collection_contributors_leaderboard` (a differently-shaped
9+
pipe - see its own DESCRIPTION for why a naive collectionSlug branch on the single-project
10+
leaderboard pipe isn't used there either).
11+
- Combines data from `collection_contributors_leaderboard` and `active_contributors` (both
12+
already collectionSlug-aware) to provide dependency risk assessment at collection scale.
13+
- Parameters:
14+
- `collectionSlug`: Required collection slug (e.g., 'cncf') - inherited from `segments_filtered_by_collection`.
15+
- `repos`: Optional array of repository URLs for filtering (inherited from `segments_filtered_by_collection`)
16+
- `startDate`: Optional DateTime filter for activities after timestamp (e.g., '2024-01-01 00:00:00')
17+
- `endDate`: Optional DateTime filter for activities before timestamp (e.g., '2024-12-31 23:59:59')
18+
- `platform`: Optional string filter for source platform (e.g., 'github', 'discord', 'slack')
19+
- `activity_type`: Optional string filter for single activity type (e.g., 'authored-commit')
20+
- `includeCollaborations`: Optional boolean, defaults to false - same toggle as the single-project pipe.
21+
- `limit`: Optional integer, defaults to 100 - number of top contributors to rank before finding the 51% cutoff.
22+
- Response: `id`, `displayName`, `githubHandleArray`, `contributionCount`, `contributionPercentage`, `roles`, `contributionPercentageRunningTotal`, `totalContributorCount`
23+
24+
TAGS "Insights, Widget", "Collection", "Contributors"
25+
26+
NODE collection_contributions_percentage_running_total
27+
SQL >
28+
%
29+
SELECT t.*, active_contributors.contributorCount as "totalContributorCount"
30+
FROM
31+
(
32+
SELECT
33+
id,
34+
displayName,
35+
githubHandleArray,
36+
contributionCount,
37+
contributionPercentage,
38+
roles,
39+
sum(contributionPercentage) OVER (
40+
ORDER BY contributionPercentage DESC, id
41+
) AS contributionPercentageRunningTotal
42+
FROM collection_contributors_leaderboard
43+
) t
44+
cross join active_contributors
45+
WHERE
46+
contributionPercentageRunningTotal <= 51
47+
OR (contributionPercentageRunningTotal - contributionPercentage < 51)
48+
ORDER BY contributionPercentageRunningTotal ASC

0 commit comments

Comments
 (0)