Skip to content

Commit 3e79a27

Browse files
Merge pull request #179 from ehuss/fix-ci-json-response
Fix CI test error.
2 parents a8c2806 + 4cc2108 commit 3e79a27

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: CI
22
on:
33
pull_request:
44
push:
5+
permissions:
6+
contents: read
57
jobs:
68
test:
79
name: Test
@@ -23,4 +25,6 @@ jobs:
2325
- name: Build
2426
run: cargo test --no-run
2527
- name: Test
26-
run: cargo test
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
run: cargo test

src/github.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Context;
1+
use anyhow::{bail, Context};
22
use reqwest::{self, blocking::Client, blocking::Response};
33
use reqwest::header::{HeaderMap, InvalidHeaderValue, HeaderValue, USER_AGENT, AUTHORIZATION};
44
use serde::{Deserialize, Serialize};
@@ -63,7 +63,18 @@ pub(crate) fn get_commit(sha: &str) -> anyhow::Result<Commit> {
6363
let url = CommitDetailsUrl { sha }.url();
6464
let client = Client::builder().default_headers(headers()?).build()?;
6565
let response: Response = client.get(&url).send()?;
66-
let elem: GithubCommitComparison = response.json()?;
66+
let status = response.status();
67+
if !status.is_success() {
68+
bail!(
69+
"error: url <{}> response {}: {}",
70+
url,
71+
status,
72+
response.text().unwrap_or_else(|_| format!("<empty>"))
73+
);
74+
}
75+
let elem: GithubCommitComparison = response
76+
.json()
77+
.with_context(|| "failed to decode GitHub JSON response")?;
6778
elem.merge_base_commit.git_commit()
6879
}
6980

0 commit comments

Comments
 (0)