Skip to content

Commit 8f7c4c5

Browse files
committed
controllers/krate/owners: Simplify add_team_owner() fn`
1 parent de0b0c7 commit 8f7c4c5

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

src/controllers/krate/owners.rs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -336,37 +336,32 @@ async fn add_team_owner(
336336
krate: &Crate,
337337
login: &str,
338338
) -> Result<NewOwnerInvite, OwnerAddError> {
339-
// Always recreate teams to get the most up-to-date GitHub ID
339+
// github:rust-lang:owners
340340
let mut chunks = login.split(':');
341-
let team = match chunks.next().unwrap() {
342-
// github:rust-lang:owners
343-
"github" => {
344-
// unwrap is documented above as part of the calling contract
345-
let org = chunks.next().unwrap();
346-
let team = chunks.next().ok_or_else(|| {
347-
bad_request(
348-
"missing github team argument; \
349-
format is github:org:team",
350-
)
351-
})?;
352-
Team::create_or_update_github_team(
353-
gh_client,
354-
conn,
355-
&login.to_lowercase(),
356-
org,
357-
team,
358-
req_user,
359-
)
360-
.await?
361-
}
362-
_ => {
363-
return Err(bad_request(
364-
"unknown organization handler, \
365-
only 'github:org:team' is supported",
366-
)
367-
.into());
368-
}
369-
};
341+
342+
let team_system = chunks.next().unwrap();
343+
if team_system != "github" {
344+
let error = "unknown organization handler, only 'github:org:team' is supported";
345+
return Err(bad_request(error).into());
346+
}
347+
348+
// unwrap is documented above as part of the calling contract
349+
let org = chunks.next().unwrap();
350+
let team = chunks.next().ok_or_else(|| {
351+
let error = "missing github team argument; format is github:org:team";
352+
bad_request(error)
353+
})?;
354+
355+
// Always recreate teams to get the most up-to-date GitHub ID
356+
let team = Team::create_or_update_github_team(
357+
gh_client,
358+
conn,
359+
&login.to_lowercase(),
360+
org,
361+
team,
362+
req_user,
363+
)
364+
.await?;
370365

371366
// Teams are added as owners immediately, since the above call ensures
372367
// the user is a team member.

0 commit comments

Comments
 (0)