Skip to content

Commit 2c2a3a1

Browse files
committed
remove trailing '/' in endpoint url
1 parent ebe6b18 commit 2c2a3a1

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

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

+5-10
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,11 @@ impl RestApiClient for GithubApiClient {
265265
let sha = self.sha.clone().unwrap() + "/";
266266
let comments_url = self
267267
.api_url
268-
.join("repos/")
269-
.unwrap()
270-
.join(format!("{}/", repo).as_str())
271-
.unwrap()
272-
.join(if is_pr { "issues/" } else { "commits/" })
273-
.unwrap()
274-
.join(if is_pr { pr.as_str() } else { sha.as_str() })
275-
.unwrap()
276-
.join("comments/")
277-
.unwrap();
268+
.join("repos/")?
269+
.join(format!("{}/", repo).as_str())?
270+
.join(if is_pr { "issues/" } else { "commits/" })?
271+
.join(if is_pr { pr.as_str() } else { sha.as_str() })?
272+
.join("comments")?;
278273

279274
self.update_comment(
280275
comments_url,

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl GithubApiClient {
205205
})?,
206206
);
207207
let repo = format!(
208-
"repos/{}/comments/",
208+
"repos/{}/comments",
209209
// if we got here, then we know it is on a CI runner as self.repo should be known
210210
self.repo.as_ref().expect("Repo name unknown.")
211211
);
@@ -243,11 +243,14 @@ impl GithubApiClient {
243243
comment.user.login,
244244
comment.user.id,
245245
);
246-
let this_comment_url = base_comment_url
247-
.join(&comment.id.to_string())
248-
.with_context(|| {
249-
format!("Failed to parse URL for JSON comment.id: {}", comment.id)
250-
})?;
246+
let this_comment_url =
247+
Url::parse(format!("{base_comment_url}/{}", &comment.id).as_str())
248+
.with_context(|| {
249+
format!(
250+
"Failed to parse URL for JSON comment.id: {}",
251+
comment.id
252+
)
253+
})?;
251254
if delete || comment_url.is_some() {
252255
// if not updating: remove all outdated comments
253256
// if updating: remove all outdated comments except the last one

cpp-linter/tests/comments.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
106106
server
107107
.mock(
108108
"GET",
109-
format!("/repos/{REPO}/commits/{SHA}/comments/").as_str(),
109+
format!("/repos/{REPO}/commits/{SHA}/comments").as_str(),
110110
)
111111
.match_header("Accept", "application/vnd.github.raw+json")
112112
.match_header("Authorization", TOKEN)
@@ -123,7 +123,7 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
123123
.create(),
124124
);
125125
} else {
126-
let pr_endpoint = format!("/repos/{REPO}/issues/{PR}/comments/");
126+
let pr_endpoint = format!("/repos/{REPO}/issues/{PR}/comments");
127127
for pg in ["1", "2"] {
128128
let link = if pg == "1" {
129129
format!("<{}{pr_endpoint}?page=2>; rel=\"next\"", server.url())
@@ -190,7 +190,7 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
190190
.mock(
191191
"POST",
192192
format!(
193-
"/repos/{REPO}/{}/comments/",
193+
"/repos/{REPO}/{}/comments",
194194
if test_params.event_t == EventType::PullRequest {
195195
format!("issues/{PR}")
196196
} else {

0 commit comments

Comments
 (0)