Skip to content

Commit 804314e

Browse files
committed
adjust auth header value
GH REST API doesn't send to be recognizing the token in field test.
1 parent 2c2a3a1 commit 804314e

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

cpp-linter/src/rest_api/github/mod.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,9 @@ impl RestApiClient for GithubApiClient {
100100
"Accept",
101101
HeaderValue::from_str("application/vnd.github.raw+json")?,
102102
);
103-
headers.insert(
104-
"User-Agent",
105-
HeaderValue::from_str("cpp-linter/cpp_linter_rs")?,
106-
);
107-
// headers.insert("User-Agent", USER_AGENT.parse().unwrap());
108103
if let Ok(token) = env::var("GITHUB_TOKEN") {
109-
let mut val = HeaderValue::from_str(token.as_str())?;
104+
log::debug!("Using auth token from GITHUB_TOKEN environment variable");
105+
let mut val = HeaderValue::from_str(format!("token {token}").as_str())?;
110106
val.set_sensitive(true);
111107
headers.insert(AUTHORIZATION, val);
112108
}

cpp-linter/src/rest_api/github/specific_api.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
clang_tools::{clang_format::summarize_style, ReviewComments},
1616
cli::FeedbackInput,
1717
common_fs::FileObj,
18-
rest_api::{RestApiRateLimitHeaders, COMMENT_MARKER},
18+
rest_api::{RestApiRateLimitHeaders, COMMENT_MARKER, USER_AGENT},
1919
};
2020

2121
use super::{
@@ -58,6 +58,7 @@ impl GithubApiClient {
5858
Ok(GithubApiClient {
5959
client: Client::builder()
6060
.default_headers(Self::make_headers()?)
61+
.user_agent(USER_AGENT)
6162
.build()
6263
.with_context(|| "Failed to create a session client for REST API calls")?,
6364
pull_request,

cpp-linter/src/rest_api/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use crate::common_fs::{FileFilter, FileObj};
2323

2424
pub static COMMENT_MARKER: &str = "<!-- cpp linter action -->\n";
2525
pub static USER_OUTREACH: &str = "\n\nHave any feedback or feature suggestions? [Share it here.](https://github.com/cpp-linter/cpp-linter-action/issues)";
26+
pub static USER_AGENT: &str =
27+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0";
2628

2729
/// A structure to contain the different forms of headers that
2830
/// describe a REST API's rate limit status.

0 commit comments

Comments
 (0)