CI: fix fmt & remove actions-rs/cargo@v1 (#58)
Diff
src/main.rs | 6 +++++-
.github/workflows/ci.yml | 28 ++++++++++++----------------
src/providers/gitlab.rs | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
3 files changed, 55 insertions(+), 53 deletions(-)
@@ -411,7 +411,11 @@
info!(
"Successfully authenticated for GitLab user `{}` by {}",
&user.username,
if by_ssh_key { "SSH Key" } else { "Build or Personal Token" },
if by_ssh_key {
"SSH Key"
} else {
"Build or Personal Token"
},
);
self.user = Some(Arc::new(user));
self.finished_auth(Auth::Accept).await
@@ -7,56 +7,48 @@
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check
- run: cargo check
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
- run: cargo test
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
components: rustfmt
- run: cargo fmt -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
components: clippy
- run: cargo clippy -- -D warnings
@@ -1,7 +1,9 @@
#![allow(clippy::module_name_repetitions)]
use crate::config::GitlabConfig;
use crate::providers::{Release, User};
use crate::{
config::GitlabConfig,
providers::{Release, User},
};
use async_trait::async_trait;
use futures::{stream::FuturesUnordered, StreamExt, TryStreamExt};
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
@@ -47,7 +49,11 @@
})
}
pub fn build_client_with_token(&self, token_field: &str, token: &str) -> anyhow::Result<reqwest::Client> {
pub fn build_client_with_token(
&self,
token_field: &str,
token: &str,
) -> anyhow::Result<reqwest::Client> {
let mut headers = header::HeaderMap::new();
headers.insert(
header::HeaderName::from_str(token_field)?,
@@ -76,38 +82,37 @@
if username == "gitlab-ci-token" || username == "personal-token" {
let client = self.build_client_with_token(if username == "gitlab-ci-token" { "JOB-TOKEN" } else { "PRIVATE-TOKEN" }, password);
let client = self.build_client_with_token(
if username == "gitlab-ci-token" {
"JOB-TOKEN"
} else {
"PRIVATE-TOKEN"
},
password,
);
if username == "gitlab-ci-token" {
let res: GitlabJobResponse = handle_error(
client?
.get(self.base_url.join("job/")?)
.send()
.await?,
)
.await?
.json()
.await?;
let res: GitlabJobResponse =
handle_error(client?.get(self.base_url.join("job/")?).send().await?)
.await?
.json()
.await?;
Ok(Some(User {
id: res.user.id,
username: res.user.username,
..Default::default()
id: res.user.id,
username: res.user.username,
..Default::default()
}))
} else {
let res: GitlabUserResponse = handle_error(
client?
.get(self.base_url.join("user/")?)
.send()
.await?,
)
.await?
.json()
.await?;
let res: GitlabUserResponse =
handle_error(client?.get(self.base_url.join("user/")?).send().await?)
.await?
.json()
.await?;
Ok(Some(User {
id: res.id,
username: res.username,
token: Some(password.to_string()),
id: res.id,
username: res.username,
token: Some(password.to_string()),
}))
}
} else {
@@ -188,7 +193,7 @@
let client = match &do_as.token {
None => self.client.clone(),
Some(token) => self.build_client_with_token("PRIVATE-TOKEN", token)?
Some(token) => self.build_client_with_token("PRIVATE-TOKEN", token)?,
};
let client = Arc::new(client);
@@ -203,11 +208,12 @@
}
}
let res: Vec<GitlabPackageResponse> = res.json::<Vec<GitlabPackageResponse>>()
.await?
.into_iter()
.filter(|release| release.package_type == "generic")
.collect();
let res: Vec<_> = res
.json::<Vec<GitlabPackageResponse>>()
.await?
.into_iter()
.filter(|release| release.package_type == "generic")
.collect();
for release in res {
let this = Arc::clone(&self);