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 assignments 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
11 changed files
with
313 additions
and
9 deletions.
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) { | ||
pageInfo { | ||
hasNextPage | ||
endCursor | ||
} | ||
nodes { | ||
number | ||
updatedAt | ||
createdAt | ||
assignees(first: 10) { | ||
nodes { | ||
login | ||
databaseId | ||
} | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# How to use GraphQL with Rust | ||
|
||
# GUI Clients (Electron apps) | ||
|
||
Use a client to experiment and build your GraphQL query/mutation. | ||
|
||
https://insomnia.rest/download | ||
|
||
https://docs.usebruno.com | ||
|
||
Once you're happy with the result, save your query in a `<query>.gql` file in this directory. It will serve as | ||
documentation on how to reproduce the Rust boilerplate. | ||
|
||
# Cynic CLI | ||
|
||
Introspect a schema and save it locally: | ||
|
||
```sh | ||
cynic introspect \ | ||
-H "User-Agent: cynic/3.4.3" \ | ||
-H "Authorization: Bearer [GITHUB_TOKEN]" \ | ||
"https://api.github.com/graphql" \ | ||
-o schemas/github.graphql | ||
``` | ||
|
||
Execute a GraphQL query/mutation and save locally the Rust boilerplate: | ||
|
||
``` sh | ||
cynic querygen --schema schemas/github.graphql --query query.gql | ||
``` | ||
|
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
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,72 @@ | ||
use std::collections::HashMap; | ||
|
||
use crate::db::notifications::record_username; | ||
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"); | ||
|
||
let rust_repo = gh.repository("rust-lang/rust").await?; | ||
let prs = retrieve_pull_requests(&rust_repo, &gh).await?; | ||
|
||
// delete all PR assignments before populating | ||
init_table(&db).await?; | ||
|
||
// aggregate by user first | ||
let aggregated = prs.into_iter().fold(HashMap::new(), |mut acc, (user, pr)| { | ||
let (_, prs) = acc | ||
.entry(user.id.unwrap()) | ||
.or_insert_with(|| (user, Vec::new())); | ||
prs.push(pr); | ||
acc | ||
}); | ||
|
||
// populate the table | ||
for (_user_id, (assignee, prs)) in &aggregated { | ||
let assignee_id = assignee.id.expect("checked"); | ||
let _ = record_username(&db, assignee_id, &assignee.login).await; | ||
create_team_member_workqueue(&db, assignee_id, &prs).await?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
/// Truncate the review prefs table | ||
async fn init_table(db: &DbClient) -> anyhow::Result<u64> { | ||
let res = db | ||
.execute("UPDATE review_prefs SET assigned_prs='{}';", &[]) | ||
.await?; | ||
Ok(res) | ||
} | ||
|
||
/// Create a team member work queue | ||
async fn create_team_member_workqueue( | ||
db: &DbClient, | ||
user_id: i64, | ||
prs: &Vec<i32>, | ||
) -> anyhow::Result<u64, anyhow::Error> { | ||
let q = " | ||
INSERT INTO review_prefs (user_id, assigned_prs) VALUES ($1, $2) | ||
ON CONFLICT (user_id) | ||
DO UPDATE SET assigned_prs = $2 | ||
WHERE review_prefs.user_id=$1"; | ||
db.execute(q, &[&user_id, prs]) | ||
.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
Oops, something went wrong.