From e45a3fde99d03f3cb8efbe4837d85fe5b8c6465a Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Mon, 13 Nov 2023 17:39:36 +0000 Subject: [PATCH] CI: fix fmt & remove actions-rs/cargo@v1 (#58) --- .github/workflows/ci.yml | 28 ++++++++++------------------ src/main.rs | 6 +++++- src/providers/gitlab.rs | 74 ++++++++++++++++++++++++++++++++++++++++---------------------------------- 3 files changed, 55 insertions(+), 53 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ead4831..e46b646 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,56 +7,48 @@ jobs: 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 diff --git a/src/main.rs b/src/main.rs index fd9d34e..bbb7da7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -411,7 +411,11 @@ impl thrussh::server: 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 diff --git a/src/providers/gitlab.rs b/src/providers/gitlab.rs index c9290f1..919f79e 100644 --- a/src/providers/gitlab.rs +++ b/src/providers/gitlab.rs @@ -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 @@ impl Gitlab { }) } - pub fn build_client_with_token(&self, token_field: &str, token: &str) -> anyhow::Result { + pub fn build_client_with_token( + &self, + token_field: &str, + token: &str, + ) -> anyhow::Result { let mut headers = header::HeaderMap::new(); headers.insert( header::HeaderName::from_str(token_field)?, @@ -76,38 +82,37 @@ impl super::UserProvider for Gitlab { if username == "gitlab-ci-token" || username == "personal-token" { // we're purposely not using `self.client` here as we don't // want to use our admin token for this request but still want to use any ssl cert provided. - 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 @@ impl super::PackageProvider for Gitlab { 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 @@ impl super::PackageProvider for Gitlab { } } - let res: Vec = res.json::>() - .await? - .into_iter() - .filter(|release| release.package_type == "generic") - .collect(); + let res: Vec<_> = res + .json::>() + .await? + .into_iter() + .filter(|release| release.package_type == "generic") + .collect(); for release in res { let this = Arc::clone(&self); -- libgit2 1.7.2