Skip to content

When looking at commits look at the ci repo #1380

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 1, 2022
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
28 changes: 14 additions & 14 deletions site/src/github.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod client;
pub mod comparison_summary;

use crate::api::github::{Commit, Issue};
use crate::api::github::Commit;
use crate::load::{SiteCtxt, TryCommit};

use serde::Deserialize;
Expand Down Expand Up @@ -101,9 +101,14 @@ pub async fn rollup_pr_number(
.then(|| issue.number))
}

pub async fn enqueue_sha(issue: Issue, ctxt: &SiteCtxt, commit: String) -> Result<(), String> {
let client = client::Client::from_ctxt(ctxt, issue.repository_url.clone());
let commit_response = client
pub async fn enqueue_sha(
ctxt: &SiteCtxt,
main_client: &client::Client,
ci_client: &client::Client,
pr_number: u32,
commit: String,
) -> Result<(), String> {
let commit_response = ci_client
.get_commit(&commit)
.await
.map_err(|e| e.to_string())?;
Expand All @@ -118,25 +123,20 @@ pub async fn enqueue_sha(issue: Issue, ctxt: &SiteCtxt, commit: String) -> Resul
let try_commit = TryCommit {
sha: commit_response.sha.clone(),
parent_sha: commit_response.parents[0].sha.clone(),
issue: issue.clone(),
};
let queued = {
let conn = ctxt.conn().await;
conn.pr_attach_commit(
issue.number,
&commit_response.sha,
&commit_response.parents[0].sha,
)
.await
conn.pr_attach_commit(pr_number, &try_commit.sha, &try_commit.parent_sha)
.await
};
if queued {
let msg = format!(
"Queued {} with parent {}, future [comparison URL]({}).",
commit_response.sha,
commit_response.parents[0].sha,
try_commit.sha,
try_commit.parent_sha,
try_commit.comparison_url(),
);
client.post_comment(issue.number, msg).await;
main_client.post_comment(pr_number, msg).await;
}
Ok(())
}
Expand Down
4 changes: 1 addition & 3 deletions site/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use chrono::{Duration, Utc};
use log::error;
use serde::{Deserialize, Serialize};

use crate::api::github;
use crate::db;
use collector::{category::Category, Bound, MasterCommit};
use database::Date;
Expand Down Expand Up @@ -60,11 +59,10 @@ impl MissingReason {
}
}

#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TryCommit {
pub sha: String,
pub parent_sha: String,
pub issue: github::Issue,
}

impl TryCommit {
Expand Down
31 changes: 22 additions & 9 deletions site/src/request_handlers/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,39 @@ async fn handle_issue(
issue: github::Issue,
comment: github::Comment,
) -> ServerResult<github::Response> {
let main_client = client::Client::from_ctxt(
&ctxt,
"https://api.github.com/repos/rust-lang/rust".to_owned(),
);
let ci_client = client::Client::from_ctxt(
&ctxt,
"https://api.github.com/repos/rust-lang-ci/rust".to_owned(),
);
if comment.body.contains(" homu: ") {
if let Some(sha) = parse_homu_comment(&comment.body).await {
enqueue_sha(issue, &ctxt, sha).await?;
enqueue_sha(&ctxt, &main_client, &ci_client, issue.number, sha).await?;
return Ok(github::Response);
}
}

if comment.body.contains("@rust-timer ") {
return handle_rust_timer(ctxt, comment, issue).await;
return handle_rust_timer(ctxt, &main_client, &ci_client, comment, issue).await;
}

Ok(github::Response)
}

async fn handle_rust_timer(
ctxt: Arc<SiteCtxt>,
main_client: &client::Client,
ci_client: &client::Client,
comment: github::Comment,
issue: github::Issue,
) -> ServerResult<github::Response> {
let main_repo_client = client::Client::from_ctxt(
&ctxt,
"https://api.github.com/repos/rust-lang/rust".to_owned(),
);
if comment.author_association != github::Association::Owner
&& !get_authorized_users().await?.contains(&comment.user.id)
{
main_repo_client
main_client
.post_comment(
issue.number,
"Insufficient permissions to issue commands to rust-timer.",
Expand All @@ -163,7 +169,7 @@ async fn handle_rust_timer(
let conn = ctxt.conn().await;
conn.queue_pr(issue.number, include, exclude, runs).await;
}
main_repo_client
main_client
.post_comment(
issue.number,
"Awaiting bors try build completion.
Expand All @@ -183,7 +189,14 @@ async fn handle_rust_timer(
let conn = ctxt.conn().await;
conn.queue_pr(issue.number, include, exclude, runs).await;
}
enqueue_sha(issue, &ctxt, commit.to_owned()).await?;
enqueue_sha(
&ctxt,
&main_client,
&ci_client,
issue.number,
commit.to_owned(),
)
.await?;
return Ok(github::Response);
}
}
Expand Down