-
Notifications
You must be signed in to change notification settings - Fork 105
Remove our cynic dependency
#2471
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,188 @@ | ||
| use anyhow::Context as _; | ||
| use serde::Deserialize; | ||
|
|
||
| use crate::github::GithubClient; | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct QueryResponse { | ||
| pub repository: Option<Repository>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct Repository { | ||
| pub pull_requests: PullRequestConnection, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct PullRequestConnection { | ||
| pub page_info: PageInfo, | ||
| pub nodes: Vec<PullRequest>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct PageInfo { | ||
| pub has_next_page: bool, | ||
| pub end_cursor: Option<String>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct PullRequest { | ||
| pub number: i32, | ||
| pub author: Option<Actor>, | ||
| pub created_at: chrono::DateTime<chrono::Utc>, | ||
| pub url: String, | ||
| pub title: String, | ||
| pub is_draft: bool, | ||
| pub labels: Option<Connection<Label>>, | ||
| pub assignees: Connection<User>, | ||
| pub comments: ConnectionWithCount<IssueComment>, | ||
| pub latest_reviews: Option<ConnectionWithCount<PullRequestReview>>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| pub struct Connection<T> { | ||
| pub nodes: Vec<T>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ConnectionWithCount<T> { | ||
| pub total_count: i32, | ||
| pub nodes: Vec<T>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| pub struct Actor { | ||
| pub login: String, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| pub struct Label { | ||
| pub name: String, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct User { | ||
| pub login: String, | ||
| pub database_id: Option<i32>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct IssueComment { | ||
| pub author: Option<Actor>, | ||
| pub created_at: chrono::DateTime<chrono::Utc>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Debug)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct PullRequestReview { | ||
| pub author: Option<Actor>, | ||
| pub created_at: chrono::DateTime<chrono::Utc>, | ||
| } | ||
|
|
||
| impl GithubClient { | ||
| pub async fn least_recently_reviewed_prs( | ||
| &self, | ||
| owner: &str, | ||
| name: &str, | ||
| ) -> anyhow::Result<Vec<PullRequest>> { | ||
| let mut prs = Vec::new(); | ||
| let mut after = Option::<String>::None; | ||
|
|
||
| loop { | ||
| let mut data = self | ||
| .graphql_query( | ||
| r#" | ||
| query LeastRecentlyReviewedPullRequests( | ||
| $repository_owner: String!, | ||
| $repository_name: String!, | ||
| $after: String | ||
| ) { | ||
| repository(owner: $repository_owner, name: $repository_name) { | ||
| pullRequests( | ||
| states: [OPEN], | ||
| first: 100, | ||
| after: $after, | ||
| labels: ["S-waiting-on-review"], | ||
| orderBy: { direction: ASC, field: UPDATED_AT } | ||
| ) { | ||
| totalCount | ||
| pageInfo { | ||
| hasNextPage | ||
| endCursor | ||
| } | ||
| nodes { | ||
| number | ||
| author { | ||
| login | ||
| } | ||
| createdAt | ||
| url | ||
| title | ||
| isDraft | ||
| labels(first: 100) { | ||
| nodes { | ||
| name | ||
| } | ||
| } | ||
| assignees(first: 100) { | ||
| nodes { | ||
| login | ||
| databaseId | ||
| } | ||
| } | ||
| comments(first: 100, orderBy: { direction: DESC, field: UPDATED_AT }) { | ||
| totalCount | ||
| nodes { | ||
| author { | ||
| login | ||
| } | ||
| createdAt | ||
| } | ||
| } | ||
| latestReviews(last: 20) { | ||
| totalCount | ||
| nodes { | ||
| author { | ||
| login | ||
| } | ||
| createdAt | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| "#, | ||
| serde_json::json!({ | ||
| "repository_owner": owner.to_string(), | ||
| "repository_name": name.to_string(), | ||
| "after": after, | ||
| }), | ||
| ) | ||
| .await | ||
| .context("failed to query the least recently reviewed prs")?; | ||
|
|
||
| let response: QueryResponse = | ||
| serde_json::from_value(data["data"].take()).context("failed to deserialize")?; | ||
|
|
||
| let repository = response.repository.context("No repository.")?; | ||
| prs.extend(repository.pull_requests.nodes); | ||
|
|
||
| let page_info = repository.pull_requests.page_info; | ||
| if !page_info.has_next_page || page_info.end_cursor.is_none() { | ||
| break; | ||
| } | ||
| after = page_info.end_cursor; | ||
| } | ||
|
|
||
| Ok(prs) | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good case for the local GH database mirror, to avoid these kinds of remote GH queries :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by local gh db? do you mean that to cache results of this query? This specific query is run when I prepare the weekly triage agenda, I need fresh data everytime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant https://rust-lang.zulipchat.com/#narrow/channel/224082-triagebot/topic/Integrating.20a.20GitHub.20mirror.20.2B.20dashboard.20in.20triagebot/with/612107852, if we had the GitHub mirror in the triagebot DB, this could just be an SQL query (potentially with a force-refresh before running the data if up-to-date state is required).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the "force-refresh" part is def. needed for my queries :)