Skip to content

Commit 4ecb415

Browse files
Merge pull request #1469 from Mark-Simulacrum/fix-deser
Fix Repository deserialization in webhooks
2 parents 4ecb468 + c6dcf47 commit 4ecb415

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/actions.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ impl<'a> Action for Step<'a> {
7979
for Query { repos, queries } in &self.actions {
8080
for repo in repos {
8181
let repository = Repository {
82-
owner: repo.0.to_string(),
83-
name: repo.1.to_string(),
82+
full_name: format!("{}/{}", repo.0, repo.1),
8483
};
8584

8685
for QueryMap { name, kind, query } in queries {
@@ -97,7 +96,7 @@ impl<'a> Action for Step<'a> {
9796
title: issue.title.clone(),
9897
number: issue.number,
9998
html_url: issue.html_url.clone(),
100-
repo_name: repository.name.clone(),
99+
repo_name: repository.name().to_owned(),
101100
labels: issue
102101
.labels
103102
.iter()

src/github.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -759,16 +759,19 @@ pub struct IssueSearchResult {
759759

760760
#[derive(Debug, serde::Deserialize)]
761761
pub struct Repository {
762-
pub owner: String,
763-
pub name: String,
762+
pub full_name: String,
764763
}
765764

766765
impl Repository {
767766
const GITHUB_API_URL: &'static str = "https://api.github.com";
768767
const GITHUB_GRAPHQL_API_URL: &'static str = "https://api.github.com/graphql";
769768

770-
pub fn full_name(&self) -> String {
771-
return format!("{}/{}", self.owner, self.name);
769+
pub fn owner(&self) -> &str {
770+
self.full_name.split_once('/').unwrap().0
771+
}
772+
773+
pub fn name(&self) -> &str {
774+
self.full_name.split_once('/').unwrap().1
772775
}
773776

774777
pub async fn get_issues<'a>(
@@ -881,7 +884,7 @@ impl Repository {
881884
format!(
882885
"{}/repos/{}/{}?{}",
883886
Repository::GITHUB_API_URL,
884-
self.full_name(),
887+
self.full_name,
885888
endpoint,
886889
filters
887890
)
@@ -908,7 +911,7 @@ impl Repository {
908911
.iter()
909912
.map(|label| format!("-label:{}", label)),
910913
)
911-
.chain(std::iter::once(format!("repo:{}", self.full_name())))
914+
.chain(std::iter::once(format!("repo:{}", self.full_name)))
912915
.collect::<Vec<_>>()
913916
.join("+");
914917
format!(
@@ -968,10 +971,10 @@ pub enum Event {
968971
impl Event {
969972
pub fn repo_name(&self) -> String {
970973
match self {
971-
Event::Create(event) => event.repository.full_name(),
972-
Event::IssueComment(event) => event.repository.full_name(),
973-
Event::Issue(event) => event.repository.full_name(),
974-
Event::Push(event) => event.repository.full_name(),
974+
Event::Create(event) => event.repository.full_name.clone(),
975+
Event::IssueComment(event) => event.repository.full_name.clone(),
976+
Event::Issue(event) => event.repository.full_name.clone(),
977+
Event::Push(event) => event.repository.full_name.clone(),
975978
}
976979
}
977980

src/github/graphql.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,14 @@ impl IssuesQuery for LeastRecentlyReviewedPullRequests {
176176
) -> anyhow::Result<Vec<crate::actions::IssueDecorator>> {
177177
use cynic::QueryBuilder;
178178

179-
let repo_name = repo.name.clone();
180-
let repository_owner = repo.owner.clone();
181-
let repository_name = repo.name.clone();
179+
let repository_owner = repo.owner().to_owned();
180+
let repository_name = repo.name().to_owned();
182181

183182
let mut prs = vec![];
184183

185184
let mut args = queries::LeastRecentlyReviewedPullRequestsArguments {
186185
repository_owner,
187-
repository_name,
186+
repository_name: repository_name.clone(),
188187
after: None,
189188
};
190189
loop {
@@ -314,7 +313,7 @@ impl IssuesQuery for LeastRecentlyReviewedPullRequests {
314313
pr.number as u64,
315314
pr.title,
316315
pr.url.0,
317-
repo_name.clone(),
316+
repository_name.clone(),
318317
labels,
319318
assignees,
320319
))

0 commit comments

Comments
 (0)