Skip to content

Commit af6173b

Browse files
feat: use user id instead of username
1 parent debf50e commit af6173b

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/bors/handlers/trybuild.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ async fn check_try_permissions<Client: RepositoryClient>(
262262
) -> anyhow::Result<bool> {
263263
let result = if !repo
264264
.permissions_resolver
265-
.has_permission(&author.username, PermissionType::Try)
265+
.has_permission(&author.id, PermissionType::Try)
266266
.await
267267
{
268268
tracing::info!("Permission denied");

src/github/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl Display for GithubRepoName {
4646

4747
#[derive(Debug, PartialEq)]
4848
pub struct GithubUser {
49+
pub id: u64,
4950
pub username: String,
5051
pub html_url: Url,
5152
}

src/github/webhook.rs

+1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ fn parse_comment_from_pr_review(
282282

283283
fn parse_user(user: Author) -> GithubUser {
284284
GithubUser {
285+
id: user.id.0,
285286
username: user.login,
286287
html_url: user.html_url,
287288
}

src/permissions.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub enum PermissionType {
1414
/// Decides if a GitHub user can perform various actions using the bot.
1515
#[async_trait]
1616
pub trait PermissionResolver {
17-
async fn has_permission(&self, username: &str, permission: PermissionType) -> bool;
17+
async fn has_permission(&self, user_id: &u64, permission: PermissionType) -> bool;
1818
async fn reload(&self);
1919
}
2020

@@ -46,11 +46,11 @@ impl TeamApiPermissionResolver {
4646

4747
#[async_trait]
4848
impl PermissionResolver for TeamApiPermissionResolver {
49-
async fn has_permission(&self, username: &str, permission: PermissionType) -> bool {
49+
async fn has_permission(&self, user_id: &u64, permission: PermissionType) -> bool {
5050
self.permissions
5151
.lock()
5252
.await
53-
.has_permission(username, permission)
53+
.has_permission(user_id, permission)
5454
}
5555

5656
async fn reload(&self) {
@@ -59,15 +59,15 @@ impl PermissionResolver for TeamApiPermissionResolver {
5959
}
6060

6161
pub struct UserPermissions {
62-
review_users: HashSet<String>,
63-
try_users: HashSet<String>,
62+
review_users: HashSet<u64>,
63+
try_users: HashSet<u64>,
6464
}
6565

6666
impl UserPermissions {
67-
fn has_permission(&self, username: &str, permission: PermissionType) -> bool {
67+
fn has_permission(&self, user_id: &u64, permission: PermissionType) -> bool {
6868
match permission {
69-
PermissionType::Review => self.review_users.contains(username),
70-
PermissionType::Try => self.try_users.contains(username),
69+
PermissionType::Review => self.review_users.contains(user_id),
70+
PermissionType::Try => self.try_users.contains(user_id),
7171
}
7272
}
7373
}
@@ -90,14 +90,14 @@ async fn load_permissions(repo: &GithubRepoName) -> anyhow::Result<UserPermissio
9090

9191
#[derive(serde::Deserialize)]
9292
struct UserPermissionsResponse {
93-
github_users: HashSet<String>,
93+
github_ids: HashSet<u64>,
9494
}
9595

9696
/// Loads users that are allowed to perform try/review from the Rust Team API.
9797
async fn load_users_from_team_api(
9898
repository_name: &str,
9999
permission: PermissionType,
100-
) -> anyhow::Result<HashSet<String>> {
100+
) -> anyhow::Result<HashSet<u64>> {
101101
let permission = match permission {
102102
PermissionType::Review => "review",
103103
PermissionType::Try => "try",
@@ -112,5 +112,5 @@ async fn load_users_from_team_api(
112112
.json::<UserPermissionsResponse>()
113113
.await
114114
.map_err(|error| anyhow::anyhow!("Cannot deserialize users from team API: {error:?}"))?;
115-
Ok(users.github_users)
115+
Ok(users.github_ids)
116116
}

0 commit comments

Comments
 (0)