Skip to content

Commit 727b532

Browse files
Merge pull request #1380 from rylev/get-commits-from-ci
When looking at commits look at the ci repo
2 parents 4fc90bd + 64e6496 commit 727b532

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

site/src/github.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod client;
22
pub mod comparison_summary;
33

4-
use crate::api::github::{Commit, Issue};
4+
use crate::api::github::Commit;
55
use crate::load::{SiteCtxt, TryCommit};
66

77
use serde::Deserialize;
@@ -101,9 +101,14 @@ pub async fn rollup_pr_number(
101101
.then(|| issue.number))
102102
}
103103

104-
pub async fn enqueue_sha(issue: Issue, ctxt: &SiteCtxt, commit: String) -> Result<(), String> {
105-
let client = client::Client::from_ctxt(ctxt, issue.repository_url.clone());
106-
let commit_response = client
104+
pub async fn enqueue_sha(
105+
ctxt: &SiteCtxt,
106+
main_client: &client::Client,
107+
ci_client: &client::Client,
108+
pr_number: u32,
109+
commit: String,
110+
) -> Result<(), String> {
111+
let commit_response = ci_client
107112
.get_commit(&commit)
108113
.await
109114
.map_err(|e| e.to_string())?;
@@ -118,25 +123,20 @@ pub async fn enqueue_sha(issue: Issue, ctxt: &SiteCtxt, commit: String) -> Resul
118123
let try_commit = TryCommit {
119124
sha: commit_response.sha.clone(),
120125
parent_sha: commit_response.parents[0].sha.clone(),
121-
issue: issue.clone(),
122126
};
123127
let queued = {
124128
let conn = ctxt.conn().await;
125-
conn.pr_attach_commit(
126-
issue.number,
127-
&commit_response.sha,
128-
&commit_response.parents[0].sha,
129-
)
130-
.await
129+
conn.pr_attach_commit(pr_number, &try_commit.sha, &try_commit.parent_sha)
130+
.await
131131
};
132132
if queued {
133133
let msg = format!(
134134
"Queued {} with parent {}, future [comparison URL]({}).",
135-
commit_response.sha,
136-
commit_response.parents[0].sha,
135+
try_commit.sha,
136+
try_commit.parent_sha,
137137
try_commit.comparison_url(),
138138
);
139-
client.post_comment(issue.number, msg).await;
139+
main_client.post_comment(pr_number, msg).await;
140140
}
141141
Ok(())
142142
}

site/src/load.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use chrono::{Duration, Utc};
1010
use log::error;
1111
use serde::{Deserialize, Serialize};
1212

13-
use crate::api::github;
1413
use crate::db;
1514
use collector::{category::Category, Bound, MasterCommit};
1615
use database::Date;
@@ -60,11 +59,10 @@ impl MissingReason {
6059
}
6160
}
6261

63-
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)]
62+
#[derive(Clone, Debug, PartialEq, Eq)]
6463
pub struct TryCommit {
6564
pub sha: String,
6665
pub parent_sha: String,
67-
pub issue: github::Issue,
6866
}
6967

7068
impl TryCommit {

site/src/request_handlers/github.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,33 +120,39 @@ async fn handle_issue(
120120
issue: github::Issue,
121121
comment: github::Comment,
122122
) -> ServerResult<github::Response> {
123+
let main_client = client::Client::from_ctxt(
124+
&ctxt,
125+
"https://api.github.com/repos/rust-lang/rust".to_owned(),
126+
);
127+
let ci_client = client::Client::from_ctxt(
128+
&ctxt,
129+
"https://api.github.com/repos/rust-lang-ci/rust".to_owned(),
130+
);
123131
if comment.body.contains(" homu: ") {
124132
if let Some(sha) = parse_homu_comment(&comment.body).await {
125-
enqueue_sha(issue, &ctxt, sha).await?;
133+
enqueue_sha(&ctxt, &main_client, &ci_client, issue.number, sha).await?;
126134
return Ok(github::Response);
127135
}
128136
}
129137

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

134142
Ok(github::Response)
135143
}
136144

137145
async fn handle_rust_timer(
138146
ctxt: Arc<SiteCtxt>,
147+
main_client: &client::Client,
148+
ci_client: &client::Client,
139149
comment: github::Comment,
140150
issue: github::Issue,
141151
) -> ServerResult<github::Response> {
142-
let main_repo_client = client::Client::from_ctxt(
143-
&ctxt,
144-
"https://api.github.com/repos/rust-lang/rust".to_owned(),
145-
);
146152
if comment.author_association != github::Association::Owner
147153
&& !get_authorized_users().await?.contains(&comment.user.id)
148154
{
149-
main_repo_client
155+
main_client
150156
.post_comment(
151157
issue.number,
152158
"Insufficient permissions to issue commands to rust-timer.",
@@ -163,7 +169,7 @@ async fn handle_rust_timer(
163169
let conn = ctxt.conn().await;
164170
conn.queue_pr(issue.number, include, exclude, runs).await;
165171
}
166-
main_repo_client
172+
main_client
167173
.post_comment(
168174
issue.number,
169175
"Awaiting bors try build completion.
@@ -183,7 +189,14 @@ async fn handle_rust_timer(
183189
let conn = ctxt.conn().await;
184190
conn.queue_pr(issue.number, include, exclude, runs).await;
185191
}
186-
enqueue_sha(issue, &ctxt, commit.to_owned()).await?;
192+
enqueue_sha(
193+
&ctxt,
194+
&main_client,
195+
&ci_client,
196+
issue.number,
197+
commit.to_owned(),
198+
)
199+
.await?;
187200
return Ok(github::Response);
188201
}
189202
}

0 commit comments

Comments
 (0)