Skip to content

Commit d8d9cac

Browse files
autofix-ci[bot]roele
authored andcommitted
[autofix.ci] apply automated fixes
1 parent 722e45c commit d8d9cac

File tree

3 files changed

+25
-36
lines changed

3 files changed

+25
-36
lines changed

src/github.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,23 @@ fn cache_dir() -> PathBuf {
198198
fn get_headers<U: IntoUrl>(url: U) -> HeaderMap {
199199
let mut headers = HeaderMap::new();
200200
let url = url.into_url().unwrap();
201+
let mut set_headers = |token: &str| {
202+
headers.insert(
203+
"authorization",
204+
HeaderValue::from_str(format!("token {token}").as_str()).unwrap(),
205+
);
206+
headers.insert(
207+
"x-github-api-version",
208+
HeaderValue::from_static("2022-11-28"),
209+
);
210+
};
211+
201212
if url.host_str() == Some("api.github.com") {
202213
if let Some(token) = env::GITHUB_TOKEN.as_ref() {
203-
headers.insert(
204-
"authorization",
205-
HeaderValue::from_str(format!("token {token}").as_str()).unwrap(),
206-
);
207-
headers.insert(
208-
"x-github-api-version",
209-
HeaderValue::from_static("2022-11-28"),
210-
);
211-
}
212-
} else {
213-
if let Some(token) = env::MISE_GITHUB_ENTERPRISE_TOKEN.as_ref() {
214-
headers.insert(
215-
"authorization",
216-
HeaderValue::from_str(format!("token {token}").as_str()).unwrap(),
217-
);
218-
headers.insert(
219-
"x-github-api-version",
220-
HeaderValue::from_static("2022-11-28"),
221-
);
214+
set_headers(token);
222215
}
216+
} else if let Some(token) = env::MISE_GITHUB_ENTERPRISE_TOKEN.as_ref() {
217+
set_headers(token);
223218
}
224219

225220
headers

src/gitlab.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,18 @@ fn cache_dir() -> PathBuf {
225225
fn get_headers<U: IntoUrl>(url: U) -> HeaderMap {
226226
let mut headers = HeaderMap::new();
227227
let url = url.into_url().unwrap();
228+
let mut set_headers = |token: &str| {
229+
headers.insert(
230+
"Authorization",
231+
HeaderValue::from_str(format!("Bearer {token}").as_str()).unwrap(),
232+
);
233+
};
228234
if url.host_str() == Some("gitlab.com") {
229235
if let Some(token) = env::GITLAB_TOKEN.as_ref() {
230-
headers.insert(
231-
"Authorization",
232-
HeaderValue::from_str(format!("Bearer {token}").as_str()).unwrap(),
233-
);
234-
}
235-
} else {
236-
if let Some(token) = env::MISE_GITLAB_ENTERPRISE_TOKEN.as_ref() {
237-
headers.insert(
238-
"Authorization",
239-
HeaderValue::from_str(format!("Bearer {token}").as_str()).unwrap(),
240-
);
236+
set_headers(token);
241237
}
238+
} else if let Some(token) = env::MISE_GITLAB_ENTERPRISE_TOKEN.as_ref() {
239+
set_headers(token);
242240
}
243241
headers
244242
}

src/http.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ impl Client {
7070
let get = |url: Url| async move {
7171
debug!("GET {}", &url);
7272
let mut req = self.reqwest.get(url.clone());
73-
for (key, value) in headers.iter() {
74-
req = req.header(key, value);
75-
}
73+
req = req.headers(headers.clone());
7674
let resp = req.send().await?;
7775
debug!("GET {url} {}", resp.status());
7876
display_github_rate_limit(&resp);
@@ -113,9 +111,7 @@ impl Client {
113111
let head = |url: Url| async move {
114112
debug!("HEAD {}", &url);
115113
let mut req = self.reqwest.head(url.clone());
116-
for (key, value) in headers.iter() {
117-
req = req.header(key, value);
118-
}
114+
req = req.headers(headers.clone());
119115
let resp = req.send().await?;
120116
debug!("HEAD {url} {}", resp.status());
121117
display_github_rate_limit(&resp);

0 commit comments

Comments
 (0)