Skip to content

Commit b4682be

Browse files
committed
github: fix calling API erroring
for some reason github started blocking calls, maybe related to the http tls change? adding a user agent worked.
1 parent 018affd commit b4682be

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

crates/squawk_github/src/actions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use log::info;
2+
13
use crate::app;
4+
use crate::app::SQUAWK_USER_AGENT;
25
use crate::{Comment, DEFAULT_GITHUB_API_URL, GitHubApi, GithubError};
36

47
pub struct GitHub {
@@ -13,6 +16,7 @@ impl GitHub {
1316

1417
#[must_use]
1518
pub fn new_with_url(github_api_url: &str, github_token: &str) -> Self {
19+
info!("github user agent {SQUAWK_USER_AGENT}");
1620
GitHub {
1721
github_api_url: github_api_url.to_string(),
1822
github_token: github_token.to_string(),

crates/squawk_github/src/app.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ use crate::{Comment, DEFAULT_GITHUB_API_URL, GitHubApi, GithubError};
55
use jsonwebtoken::{Algorithm, EncodingKey, Header};
66

77
use log::info;
8-
use reqwest::header::{ACCEPT, AUTHORIZATION};
8+
use reqwest::header::{ACCEPT, AUTHORIZATION, USER_AGENT};
99
use serde::{Deserialize, Serialize};
1010
use serde_json::Value;
1111
use std::time::Duration;
1212
use std::time::{SystemTime, UNIX_EPOCH};
1313

14+
pub(crate) const SQUAWK_USER_AGENT: &str = "squawk/2.25.0";
15+
1416
#[derive(Debug, Serialize)]
1517
struct CommentBody {
1618
pub body: String,
@@ -43,6 +45,7 @@ fn create_access_token(
4345
))
4446
.header(AUTHORIZATION, format!("Bearer {jwt}"))
4547
.header(ACCEPT, "application/vnd.github.machine-man-preview+json")
48+
.header(USER_AGENT, SQUAWK_USER_AGENT)
4649
.send()?
4750
.error_for_status()?
4851
.json::<GithubAccessToken>()?)
@@ -70,6 +73,7 @@ pub(crate) fn create_comment(
7073
issue_number = comment.issue
7174
))
7275
.header(AUTHORIZATION, format!("Bearer {secret}"))
76+
.header(USER_AGENT, SQUAWK_USER_AGENT)
7377
.json(&comment_body)
7478
.send()?
7579
.error_for_status()?;
@@ -87,6 +91,7 @@ pub fn get_app_info(github_api_url: &str, jwt: &str) -> Result<GitHubAppInfo, Gi
8791
Ok(reqwest::blocking::Client::new()
8892
.get(&format!("{github_api_url}/app"))
8993
.header(AUTHORIZATION, format!("Bearer {jwt}"))
94+
.header(USER_AGENT, SQUAWK_USER_AGENT)
9095
.send()?
9196
.error_for_status()?
9297
.json::<GitHubAppInfo>()?)
@@ -176,6 +181,7 @@ pub(crate) fn list_comments(
176181
))
177182
.query(&[("per_page", 100)])
178183
.header(AUTHORIZATION, format!("Bearer {secret}",))
184+
.header(USER_AGENT, SQUAWK_USER_AGENT)
179185
.send()?
180186
.error_for_status()?
181187
.json::<Vec<Comment>>()?)
@@ -203,6 +209,7 @@ pub(crate) fn update_comment(
203209
"{github_api_url}/repos/{owner}/{repo}/issues/comments/{comment_id}",
204210
))
205211
.header(AUTHORIZATION, format!("Bearer {secret}"))
212+
.header(USER_AGENT, SQUAWK_USER_AGENT)
206213
.json(&CommentBody { body })
207214
.send()?
208215
.error_for_status()?;

s/update-version

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ main() {
3030
fastmod --accept-all '"version": ".*"' '"version": "'$NEW_VERSION'"' package.json
3131
fastmod --accept-all '"version": ".*"' '"version": "'$NEW_VERSION'"' squawk-vscode/package.json
3232
fastmod --accept-all -m '(pname = "squawk";.*?)version = ".*?"' '${1}version = "'$NEW_VERSION'"' flake.nix
33+
fastmod --accept-all 'pub(crate) const SQUAWK_USER_AGENT: &str = "squawk/.*"' 'pub(crate) const SQUAWK_USER_AGENT: &str = "squawk/'$NEW_VERSION'"' crates/squawk_github/src/app.rs
3334

3435
echo "Updating CHANGELOG.md..."
3536
CURRENT_DATE=$(date +"%Y-%m-%d")
3637
sed -i '' "s/^## \[Unreleased\]$/## [Unreleased]\n\n## v$NEW_VERSION - $CURRENT_DATE/" CHANGELOG.md
38+
39+
echo "Opening CHANGELOG.md for editing..."
40+
${EDITOR:-vi} CHANGELOG.md
3741
}
3842

3943

0 commit comments

Comments
 (0)