Skip to content

Fix Repository deserialization in webhooks #1469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ impl<'a> Action for Step<'a> {
for Query { repos, queries } in &self.actions {
for repo in repos {
let repository = Repository {
owner: repo.0.to_string(),
name: repo.1.to_string(),
full_name: format!("{}/{}", repo.0, repo.1),
};

for QueryMap { name, kind, query } in queries {
Expand All @@ -97,7 +96,7 @@ impl<'a> Action for Step<'a> {
title: issue.title.clone(),
number: issue.number,
html_url: issue.html_url.clone(),
repo_name: repository.name.clone(),
repo_name: repository.name().to_owned(),
labels: issue
.labels
.iter()
Expand Down
23 changes: 13 additions & 10 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,16 +759,19 @@ pub struct IssueSearchResult {

#[derive(Debug, serde::Deserialize)]
pub struct Repository {
pub owner: String,
pub name: String,
pub full_name: String,
}

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

pub fn full_name(&self) -> String {
return format!("{}/{}", self.owner, self.name);
pub fn owner(&self) -> &str {
self.full_name.split_once('/').unwrap().0
}

pub fn name(&self) -> &str {
self.full_name.split_once('/').unwrap().1
}

pub async fn get_issues<'a>(
Expand Down Expand Up @@ -881,7 +884,7 @@ impl Repository {
format!(
"{}/repos/{}/{}?{}",
Repository::GITHUB_API_URL,
self.full_name(),
self.full_name,
endpoint,
filters
)
Expand All @@ -908,7 +911,7 @@ impl Repository {
.iter()
.map(|label| format!("-label:{}", label)),
)
.chain(std::iter::once(format!("repo:{}", self.full_name())))
.chain(std::iter::once(format!("repo:{}", self.full_name)))
.collect::<Vec<_>>()
.join("+");
format!(
Expand Down Expand Up @@ -968,10 +971,10 @@ pub enum Event {
impl Event {
pub fn repo_name(&self) -> String {
match self {
Event::Create(event) => event.repository.full_name(),
Event::IssueComment(event) => event.repository.full_name(),
Event::Issue(event) => event.repository.full_name(),
Event::Push(event) => event.repository.full_name(),
Event::Create(event) => event.repository.full_name.clone(),
Event::IssueComment(event) => event.repository.full_name.clone(),
Event::Issue(event) => event.repository.full_name.clone(),
Event::Push(event) => event.repository.full_name.clone(),
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/github/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,14 @@ impl IssuesQuery for LeastRecentlyReviewedPullRequests {
) -> anyhow::Result<Vec<crate::actions::IssueDecorator>> {
use cynic::QueryBuilder;

let repo_name = repo.name.clone();
let repository_owner = repo.owner.clone();
let repository_name = repo.name.clone();
let repository_owner = repo.owner().to_owned();
let repository_name = repo.name().to_owned();

let mut prs = vec![];

let mut args = queries::LeastRecentlyReviewedPullRequestsArguments {
repository_owner,
repository_name,
repository_name: repository_name.clone(),
after: None,
};
loop {
Expand Down Expand Up @@ -314,7 +313,7 @@ impl IssuesQuery for LeastRecentlyReviewedPullRequests {
pr.number as u64,
pr.title,
pr.url.0,
repo_name.clone(),
repository_name.clone(),
labels,
assignees,
))
Expand Down