Skip to content

Commit e3e605f

Browse files
committed
Make test and clippy pass
1 parent f6ce060 commit e3e605f

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/ghctl/repo/config.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use log::{debug, error, info, warn};
44
use octocrab::params::teams::Permission;
55
use octocrab::OctocrabBuilder;
66
use serde::{Deserialize, Serialize};
7-
use std::{collections::HashMap, hash::Hash};
7+
use std::collections::HashMap;
88

99
/// A struct that represents the ghctl configuration for a GitHub repository
1010
#[derive(Debug, Serialize, Deserialize)]
@@ -169,8 +169,7 @@ impl RepoConfig {
169169
pub async fn validate_and_prefetch(
170170
&self,
171171
access_token: &str,
172-
owner: &str,
173-
repo_name: &str,
172+
owner: &str
174173
) -> Result<(HashMap<String, u64>, HashMap<String, HashMap<String, u64>>)> {
175174
let mut users = HashMap::new();
176175

@@ -192,7 +191,7 @@ impl RepoConfig {
192191
if let Some(teams) = self.teams.as_ref() {
193192
let org = orgs_teams
194193
.entry(owner.to_string())
195-
.or_insert_with(|| HashMap::new());
194+
.or_insert_with(HashMap::new);
196195

197196
for team_slug in teams.keys() {
198197
debug!("Validating team {team_slug}");
@@ -203,7 +202,7 @@ impl RepoConfig {
203202
}
204203

205204
if let Some(environments) = self.environments.as_ref() {
206-
for (_environment_name, repo_environment) in environments {
205+
for repo_environment in environments.values() {
207206
if let Some(reviewers) = &repo_environment.reviewers {
208207
for reviewer in reviewers {
209208
match reviewer.split_once('/') {
@@ -213,7 +212,7 @@ impl RepoConfig {
213212
} else {
214213
let teams = orgs_teams
215214
.entry(org.to_string())
216-
.or_insert_with(|| HashMap::new());
215+
.or_insert_with(HashMap::new);
217216
if !teams.contains_key(team_slug) {
218217
debug!("Validating team {team_slug}");
219218
let team = octocrab.teams(org).get(team_slug).await?;
@@ -244,7 +243,7 @@ impl RepoConfig {
244243
repo_name: &String,
245244
) -> anyhow::Result<()> {
246245
let (users, orgs_teams) = self
247-
.validate_and_prefetch(access_token, owner, repo_name)
246+
.validate_and_prefetch(access_token, owner)
248247
.await?;
249248
debug!("Applying configuration");
250249
let octocrab = OctocrabBuilder::default()
@@ -516,7 +515,7 @@ mod tests {
516515
println!("repo_config: {:?}", repo_config);
517516

518517
let (users, teams) = repo_config
519-
.validate_and_prefetch(&github_token, "gitsudo-io", "gitsudo")
518+
.validate_and_prefetch(&github_token, "gitsudo-io")
520519
.await?;
521520
assert!(!users.is_empty());
522521
assert!(*users.get("aisrael").unwrap() == 89215);

src/github.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A collection of GitHub functions not provided by or building on top of the Octocrab library
22
33
use anyhow::Result;
4-
use log::{debug, error};
4+
use log::error;
55
use serde::{Deserialize, Serialize};
66

77
#[derive(Debug, Serialize, Deserialize)]
@@ -34,16 +34,18 @@ pub async fn get_user(access_token: &str, username: &str) -> Result<Account> {
3434
#[cfg(test)]
3535
mod tests {
3636
use super::*;
37-
use octocrab::OctocrabBuilder;
3837
use std::env;
3938

4039
#[tokio::test]
40+
#[ignore = "Don't run this test unless you have a valid GitHub token in the GITHUB_TOKEN environment variable"]
4141
async fn test_get_user() {
4242
env_logger::builder()
4343
.target(env_logger::Target::Stdout)
4444
.init();
4545

4646
let github_token = env::var("GITHUB_TOKEN").unwrap();
4747

48+
let account = get_user(&github_token, "aisrael").await.unwrap();
49+
assert!(account.id == 89215);
4850
}
4951
}

0 commit comments

Comments
 (0)