Skip to content

Commit d8a17dd

Browse files
Add meta.teams support
1 parent 9ef5c6b commit d8a17dd

File tree

4 files changed

+135
-5
lines changed

4 files changed

+135
-5
lines changed

flake-info/src/data/export.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub enum Derivation {
6868
package_license_set: Vec<String>,
6969
package_maintainers: Vec<Maintainer>,
7070
package_maintainers_set: Vec<String>,
71+
package_teams: Vec<Team>,
72+
package_teams_set: Vec<String>,
7173
package_description: Option<String>,
7274
package_longDescription: Option<String>,
7375
package_hydra: (),
@@ -157,6 +159,8 @@ impl TryFrom<(import::FlakeEntry, super::Flake)> for Derivation {
157159
package_description: description.clone(),
158160
package_maintainers: vec![maintainer.clone()],
159161
package_maintainers_set: maintainer.name.map_or(vec![], |n| vec![n]),
162+
package_teams: Vec::new(),
163+
package_teams_set: Vec::new(),
160164
package_longDescription: long_description,
161165
package_hydra: (),
162166
package_system: String::new(),
@@ -233,6 +237,19 @@ impl TryFrom<import::NixpkgsEntry> for Derivation {
233237
.flat_map(|m| m.name.to_owned())
234238
.collect();
235239

240+
let package_teams: Vec<Team> = package
241+
.meta
242+
.teams
243+
.map_or(Default::default(), Flatten::flatten)
244+
.into_iter()
245+
.map(Into::into)
246+
.collect();
247+
248+
let package_teams_set = package_teams
249+
.iter()
250+
.flat_map(|m| m.shortName.to_owned())
251+
.collect();
252+
236253
let long_description = package
237254
.meta
238255
.long_description
@@ -260,6 +277,8 @@ impl TryFrom<import::NixpkgsEntry> for Derivation {
260277
package_license_set,
261278
package_maintainers,
262279
package_maintainers_set,
280+
package_teams,
281+
package_teams_set,
263282
package_description: package.meta.description.clone(),
264283
package_longDescription: long_description,
265284
package_hydra: (),
@@ -348,6 +367,41 @@ impl From<super::Flake> for Maintainer {
348367
}
349368
}
350369

370+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
371+
pub struct Team {
372+
members: Option<OneOrMany<Maintainer>>,
373+
scope: Option<String>,
374+
shortName: Option<String>,
375+
githubTeams: Option<OneOrMany<String>>,
376+
}
377+
378+
impl From<import::Team> for Team {
379+
fn from(import: import::Team) -> Self {
380+
match import {
381+
import::Team::Full {
382+
members,
383+
scope,
384+
shortName,
385+
githubTeams,
386+
} => Team {
387+
members: Some(OneOrMany::Many(OneOrMany::into_list(members.unwrap())
388+
.into_iter()
389+
.map(Maintainer::from)
390+
.collect())),
391+
scope,
392+
shortName,
393+
githubTeams,
394+
},
395+
import::Team::Simple(shortName) => Team {
396+
short_name: Some(shortName),
397+
scope: None,
398+
members: None,
399+
githubTeams: None,
400+
},
401+
}
402+
}
403+
}
404+
351405
// ----- output type
352406

353407
/// Export type that brings together derivation and optional flake info

flake-info/src/data/import.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ pub enum NixpkgsEntry {
186186
pub struct Meta {
187187
pub license: Option<OneOrMany<StringOrStruct<License>>>,
188188
pub maintainers: Option<Flatten<Maintainer>>,
189+
pub teams: Option<Flatten<Team>>,
189190
pub homepage: Option<OneOrMany<String>>,
190191
pub platforms: Option<Platforms>,
191192
#[serde(rename = "badPlatforms")]
@@ -207,6 +208,18 @@ pub enum Maintainer {
207208
Simple(String),
208209
}
209210

211+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
212+
#[serde(untagged)]
213+
pub enum Team {
214+
Full {
215+
members: Option<OneOrMany<Maintainer>>,
216+
scope: Option<String>,
217+
shortName: Option<String>,
218+
githubTeams: Option<OneOrMany<String>>,
219+
},
220+
Simple(String),
221+
}
222+
210223
arg_enum! {
211224
/// The type of derivation (placed in packages.<system> or apps.<system>)
212225
/// Used to command the extraction script

flake-info/src/elastic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ lazy_static! {
126126
},
127127
},
128128
"package_maintainers_set": {"type": "keyword"},
129+
"package_teams": {
130+
"type": "nested",
131+
"properties": {
132+
"members": {"type": "keyword"},
133+
"githubTeams": {"type": "keyword"},
134+
},
135+
},
136+
"package_teams_set": {"type": "keyword"},
129137
"package_homepage": {
130138
"type": "keyword"
131139
},

frontend/src/Page/Packages.elm

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type alias ResultItemSource =
7373
, longDescription : Maybe String
7474
, licenses : List ResultPackageLicense
7575
, maintainers : List ResultPackageMaintainer
76+
, teams: List ResultPackageTeam
7677
, platforms : List String
7778
, position : Maybe String
7879
, homepage : List String
@@ -97,6 +98,14 @@ type alias ResultPackageMaintainer =
9798
}
9899

99100

101+
type alias ResultPackageTeam =
102+
{ members : Maybe (List ResultPackageMaintainer)
103+
, scope : Maybe String
104+
, shortName: Maybe String
105+
, githubTeams : Maybe (List String)
106+
}
107+
108+
100109
type alias ResultPackageHydra =
101110
{ build_id : Int
102111
, build_status : Int
@@ -120,6 +129,7 @@ type alias ResultAggregations =
120129
, package_platforms : Search.Aggregation
121130
, package_attr_set : Search.Aggregation
122131
, package_maintainers_set : Search.Aggregation
132+
, package_teams_set : Search.Aggregation
123133
, package_license_set : Search.Aggregation
124134
}
125135

@@ -129,6 +139,7 @@ type alias Aggregations =
129139
, package_platforms : Search.Aggregation
130140
, package_attr_set : Search.Aggregation
131141
, package_maintainers_set : Search.Aggregation
142+
, package_teams_set : Search.Aggregation
132143
, package_license_set : Search.Aggregation
133144
}
134145

@@ -137,6 +148,7 @@ type alias Buckets =
137148
{ packageSets : List String
138149
, licenses : List String
139150
, maintainers : List String
151+
, teams : List String
140152
, platforms : List String
141153
}
142154

@@ -146,6 +158,7 @@ emptyBuckets =
146158
{ packageSets = []
147159
, licenses = []
148160
, maintainers = []
161+
, teams = []
149162
, platforms = []
150163
}
151164

@@ -278,6 +291,11 @@ viewBuckets bucketsAsString result =
278291
(result.aggregations.package_maintainers_set.buckets |> sortBuckets)
279292
(createBucketsMsg .maintainers (\s v -> { s | maintainers = v }))
280293
selectedBucket.maintainers
294+
|> viewBucket
295+
"Teams"
296+
(result.aggregations.package_teams_set.buckets |> sortBuckets)
297+
(createBucketsMsg .teams (\s v -> { s | teams = v }))
298+
selectedBucket.teams
281299
|> viewBucket
282300
"Platforms"
283301
(result.aggregations.package_platforms.buckets |> sortBuckets |> filterPlatformsBucket)
@@ -462,6 +480,17 @@ viewResultItem nixosChannels channel showInstallDetails show item =
462480
)
463481
]
464482

483+
showTeam team =
484+
let
485+
maybe m d =
486+
Maybe.withDefault d m
487+
488+
showTeamEntry githubTeam =
489+
(a [ href ((String.append "https://github.com/orgs/NixOS/teams/") githubTeam) ] [ text githubTeam ])
490+
in
491+
li []
492+
(List.map showTeamEntry (maybe team.githubTeams []))
493+
465494
mailtoAllMaintainers maintainers =
466495
let
467496
maintainerMails =
@@ -487,7 +516,7 @@ viewResultItem nixosChannels channel showInstallDetails show item =
487516
Nothing ->
488517
li [] [ text platform ]
489518

490-
maintainersAndPlatforms =
519+
maintainersTeamsAndPlatforms =
491520
div []
492521
[ div []
493522
(List.append [ h4 [] [ text "Maintainers" ] ]
@@ -503,6 +532,16 @@ viewResultItem nixosChannels channel showInstallDetails show item =
503532
]
504533
)
505534
)
535+
, div []
536+
(if not (List.isEmpty item.source.teams) then
537+
(List.append [ h4 [] [ text "Teams" ] ]
538+
[ ul []
539+
(List.map showTeam item.source.teams)
540+
]
541+
)
542+
else
543+
[]
544+
)
506545
, div []
507546
(List.append [ h4 [] [ text "Platforms" ] ]
508547
(if List.isEmpty item.source.platforms then
@@ -748,7 +787,7 @@ viewResultItem nixosChannels channel showInstallDetails show item =
748787
Maybe.map Tuple.first item.source.flakeUrl
749788
]
750789
:: programs
751-
:: maintainersAndPlatforms
790+
:: maintainersTeamsAndPlatforms
752791
:: []
753792
)
754793
]
@@ -878,6 +917,7 @@ makeRequestBody query from size maybeBuckets sort =
878917
[ ( "package_attr_set", currentBuckets.packageSets )
879918
, ( "package_license_set", currentBuckets.licenses )
880919
, ( "package_maintainers_set", currentBuckets.maintainers )
920+
, ( "package_teams_set", currentBuckets.teams )
881921
, ( "package_platforms", currentBuckets.platforms )
882922
]
883923

@@ -931,6 +971,7 @@ makeRequestBody query from size maybeBuckets sort =
931971
[ "package_attr_set"
932972
, "package_license_set"
933973
, "package_maintainers_set"
974+
, "package_teams_set"
934975
, "package_platforms"
935976
]
936977
filterByBuckets
@@ -954,16 +995,18 @@ encodeBuckets options =
954995
[ ( "package_attr_set", Json.Encode.list Json.Encode.string options.packageSets )
955996
, ( "package_license_set", Json.Encode.list Json.Encode.string options.licenses )
956997
, ( "package_maintainers_set", Json.Encode.list Json.Encode.string options.maintainers )
998+
, ( "package_teams_set", Json.Encode.list Json.Encode.string options.teams )
957999
, ( "package_platforms", Json.Encode.list Json.Encode.string options.platforms )
9581000
]
9591001

9601002

9611003
decodeBuckets : Json.Decode.Decoder Buckets
9621004
decodeBuckets =
963-
Json.Decode.map4 Buckets
1005+
Json.Decode.map5 Buckets
9641006
(Json.Decode.field "package_attr_set" (Json.Decode.list Json.Decode.string))
9651007
(Json.Decode.field "package_license_set" (Json.Decode.list Json.Decode.string))
9661008
(Json.Decode.field "package_maintainers_set" (Json.Decode.list Json.Decode.string))
1009+
(Json.Decode.field "package_teams_set" (Json.Decode.list Json.Decode.string))
9671010
(Json.Decode.field "package_platforms" (Json.Decode.list Json.Decode.string))
9681011

9691012

@@ -980,6 +1023,7 @@ decodeResultItemSource =
9801023
|> Json.Decode.Pipeline.required "package_longDescription" (Json.Decode.nullable Json.Decode.string)
9811024
|> Json.Decode.Pipeline.required "package_license" (Json.Decode.list decodeResultPackageLicense)
9821025
|> Json.Decode.Pipeline.required "package_maintainers" (Json.Decode.list decodeResultPackageMaintainer)
1026+
|> Json.Decode.Pipeline.required "package_teams" (Json.Decode.list decodeResultPackageTeam)
9831027
|> Json.Decode.Pipeline.required "package_platforms" (Json.Decode.map filterPlatforms (Json.Decode.list Json.Decode.string))
9841028
|> Json.Decode.Pipeline.required "package_position" (Json.Decode.nullable Json.Decode.string)
9851029
|> Json.Decode.Pipeline.required "package_homepage" decodeHomepage
@@ -1089,6 +1133,15 @@ decodeResultPackageMaintainer =
10891133
(Json.Decode.field "github" (Json.Decode.nullable Json.Decode.string))
10901134

10911135

1136+
decodeResultPackageTeam : Json.Decode.Decoder ResultPackageTeam
1137+
decodeResultPackageTeam =
1138+
Json.Decode.map4 ResultPackageTeam
1139+
(Json.Decode.field "members" (Json.Decode.nullable (Json.Decode.list decodeResultPackageMaintainer)))
1140+
(Json.Decode.field "scope" (Json.Decode.nullable Json.Decode.string))
1141+
(Json.Decode.field "shortName" (Json.Decode.nullable Json.Decode.string))
1142+
(Json.Decode.field "githubTeams" (Json.Decode.nullable (Json.Decode.list Json.Decode.string)))
1143+
1144+
10921145
decodeResultPackageHydra : Json.Decode.Decoder ResultPackageHydra
10931146
decodeResultPackageHydra =
10941147
Json.Decode.succeed ResultPackageHydra
@@ -1111,19 +1164,21 @@ decodeResultPackageHydraPath =
11111164

11121165
decodeResultAggregations : Json.Decode.Decoder ResultAggregations
11131166
decodeResultAggregations =
1114-
Json.Decode.map5 ResultAggregations
1167+
Json.Decode.map6 ResultAggregations
11151168
(Json.Decode.field "all" decodeAggregations)
11161169
(Json.Decode.field "package_platforms" Search.decodeAggregation)
11171170
(Json.Decode.field "package_attr_set" Search.decodeAggregation)
11181171
(Json.Decode.field "package_maintainers_set" Search.decodeAggregation)
1172+
(Json.Decode.field "package_teams_set" Search.decodeAggregation)
11191173
(Json.Decode.field "package_license_set" Search.decodeAggregation)
11201174

11211175

11221176
decodeAggregations : Json.Decode.Decoder Aggregations
11231177
decodeAggregations =
1124-
Json.Decode.map5 Aggregations
1178+
Json.Decode.map6 Aggregations
11251179
(Json.Decode.field "doc_count" Json.Decode.int)
11261180
(Json.Decode.field "package_platforms" Search.decodeAggregation)
11271181
(Json.Decode.field "package_attr_set" Search.decodeAggregation)
11281182
(Json.Decode.field "package_maintainers_set" Search.decodeAggregation)
1183+
(Json.Decode.field "package_teams_set" Search.decodeAggregation)
11291184
(Json.Decode.field "package_license_set" Search.decodeAggregation)

0 commit comments

Comments
 (0)