forked from rust-lang/triagebot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import pull request assignment into triagebot
General overview at: rust-lang#1753 - Added a new DB table with the fields to track how many PRs are assigned to a contributor - Initial DB table population with a one-off job, manually run.
- Loading branch information
Showing
7 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
query PullRequestsOpen ($repo_owner: String!, $repo_name: String!, $after: String) { | ||
repository(owner: $repo_owner, name: $repo_name) { | ||
pullRequests(first: 100, after: $after, states:OPEN, labels: ["S-waiting-on-review","T-compiler"]) { | ||
pageInfo { | ||
hasNextPage | ||
endCursor | ||
} | ||
nodes { | ||
number | ||
updatedAt | ||
createdAt | ||
assignees(first: 10) { | ||
nodes { | ||
login | ||
id | ||
} | ||
} | ||
labels(first:5, orderBy:{field:NAME, direction:DESC}) { | ||
nodes { | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::github::retrieve_pull_requests; | ||
use crate::jobs::Job; | ||
use anyhow::Context as _; | ||
use async_trait::async_trait; | ||
use tokio_postgres::Client as DbClient; | ||
|
||
pub struct PullRequestAssignmentUpdate; | ||
|
||
#[async_trait] | ||
impl Job for PullRequestAssignmentUpdate { | ||
fn name(&self) -> &'static str { | ||
"pull_request_assignment_update" | ||
} | ||
|
||
async fn run(&self, ctx: &super::Context, _metadata: &serde_json::Value) -> anyhow::Result<()> { | ||
let db = ctx.db.get().await; | ||
let gh = &ctx.github; | ||
|
||
tracing::trace!("starting pull_request_assignment_update"); | ||
|
||
// delete everything before populating | ||
init_table(&db).await?; | ||
|
||
let rust_repo = gh.repository("rust-lang/rust").await?; | ||
let prs = retrieve_pull_requests(&rust_repo, &gh).await?; | ||
|
||
// populate the table | ||
for (assignees, pr_num) in prs { | ||
for assignee in assignees { | ||
let assignee_id = assignee.id.expect("checked"); | ||
ensure_team_member(&db, assignee_id, &assignee.login).await?; | ||
create_team_member_workqueue(&db, assignee_id, pr_num).await?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
/// Truncate the review prefs table | ||
async fn init_table(db: &DbClient) -> anyhow::Result<u64> { | ||
let res = db.execute("TRUNCATE review_prefs;", &[]).await?; | ||
Ok(res) | ||
} | ||
|
||
/// Add a new user (if not existing) | ||
async fn ensure_team_member(db: &DbClient, user_id: i64, username: &str) -> anyhow::Result<u64> { | ||
let q = " | ||
INSERT INTO users (user_id, username) VALUES ($1, $2) | ||
ON CONFLICT DO NOTHING"; | ||
let rec = db | ||
.execute(q, &[&user_id, &username]) | ||
.await | ||
.context("Insert user DB error")?; | ||
Ok(rec) | ||
} | ||
|
||
/// Create a team member work queue | ||
async fn create_team_member_workqueue( | ||
db: &DbClient, | ||
user_id: i64, | ||
pr: i32, | ||
) -> anyhow::Result<u64, anyhow::Error> { | ||
let q = "INSERT INTO review_prefs (user_id, assigned_prs) VALUES ($1, $2);"; | ||
db.execute(q, &[&user_id, &vec![pr], &pr]) | ||
.await | ||
.context("Insert DB error") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters