Skip to content

Commit a1632b4

Browse files
authored
Merge pull request #1955 from ehuss/fix-missing-repo
Fix missing repo in CommitBase
2 parents bc39521 + 8ee1570 commit a1632b4

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/github.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ pub struct CommitBase {
12191219
pub sha: String,
12201220
#[serde(rename = "ref")]
12211221
pub git_ref: String,
1222-
pub repo: Repository,
1222+
pub repo: Option<Repository>,
12231223
}
12241224

12251225
pub fn parse_diff(diff: &str) -> Vec<FileDiff> {

src/handlers/rendered_link.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ async fn add_rendered_link(
4848
.iter()
4949
.any(|tf| f.filename.starts_with(tf))
5050
})
51-
.map(|file| {
52-
let head = e.issue.head.as_ref().unwrap();
53-
let base = e.issue.base.as_ref().unwrap();
51+
.and_then(|file| {
52+
let head = e.issue.head.as_ref()?;
53+
let base = e.issue.base.as_ref()?;
5454

5555
// This URL should be stable while the PR is open, even if the
5656
// user pushes new commits.
@@ -68,12 +68,12 @@ async fn add_rendered_link(
6868
// - if merged: `https://github.com/octocat/REPO/blob/master/FILEPATH`
6969
// - if open: `https://github.com/Bob/REPO/blob/patch-1/FILEPATH`
7070
// - if closed: `https://github.com/octocat/REPO/blob/SHA/FILEPATH`
71-
format!(
71+
Some(format!(
7272
"[Rendered](https://github.com/{}/blob/{}/{})",
7373
if e.issue.merged || e.action == IssuesAction::Closed {
7474
&e.repository.full_name
7575
} else {
76-
&head.repo.full_name
76+
&head.repo.as_ref()?.full_name
7777
},
7878
if e.issue.merged {
7979
&base.git_ref
@@ -83,7 +83,7 @@ async fn add_rendered_link(
8383
&head.git_ref
8484
},
8585
file.filename
86-
)
86+
))
8787
});
8888

8989
let new_body: Cow<'_, str> = if !e.issue.body.contains("[Rendered]") {

src/handlers/validate_config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ pub(super) async fn parse_input(
4242
log::error!("expected head commit in {event:?}");
4343
return Ok(None);
4444
};
45+
let Some(repo) = &pr_source.repo else {
46+
log::warn!("repo is not available in {event:?}");
47+
return Ok(None);
48+
};
4549
let triagebot_content = match ctx
4650
.github
47-
.raw_file(&pr_source.repo.full_name, &pr_source.sha, CONFIG_FILE_NAME)
51+
.raw_file(&repo.full_name, &pr_source.sha, CONFIG_FILE_NAME)
4852
.await
4953
{
5054
Ok(Some(c)) => c,
@@ -66,7 +70,7 @@ pub(super) async fn parse_input(
6670
let (line, col) = translate_position(&triagebot_content, span.start);
6771
let url = format!(
6872
"https://github.com/{}/blob/{}/{CONFIG_FILE_NAME}#L{line}",
69-
pr_source.repo.full_name, pr_source.sha
73+
repo.full_name, pr_source.sha
7074
);
7175
format!(" at position [{line}:{col}]({url})",)
7276
}

0 commit comments

Comments
 (0)