-
Notifications
You must be signed in to change notification settings - Fork 105
Rewrite goals ping job #2469
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
Rewrite goals ping job #2469
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be65c10
Rewrite goals ping job
nxsaken 55ce9a3
Add job to list
nxsaken 94c0b60
Change to meta channel
nxsaken a5ffdfb
Remove previous scheduling
nxsaken 71f372c
Query open goal tracking issues with the last comment metadata
nxsaken 6e61a9c
Improve scheduling and messaging, run job on Thursdays
nxsaken 3a832a6
Remove binary and zulip command
nxsaken 7699ccd
Do not mention author in the echoed comment
nxsaken 969ef64
Address feedback (document stuff, make names clearer, remove unused
nxsaken 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 was deleted.
Oops, something went wrong.
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,197 @@ | ||
| use anyhow::Context; | ||
|
|
||
| use crate::github::GithubClient; | ||
|
|
||
| const ORG: &str = "rust-lang"; | ||
| const REPO: &str = "rust-project-goals"; | ||
| const LABEL: &str = "C-tracking-issue"; | ||
|
|
||
| pub struct GoalIssue { | ||
| pub number: u64, | ||
| pub title: String, | ||
| pub assignees: Vec<String>, | ||
| pub created_at: chrono::DateTime<chrono::Utc>, | ||
| pub labels: Vec<String>, | ||
| pub last_comment: Option<LastGoalComment>, | ||
| } | ||
|
|
||
| pub struct LastGoalComment { | ||
| pub created_at: chrono::DateTime<chrono::Utc>, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize)] | ||
| struct GraphQlConnection { | ||
| nodes: Vec<Option<GraphQlIssue>>, | ||
| #[serde(rename = "pageInfo")] | ||
| page_info: GraphQlPageInfo, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize)] | ||
| struct GraphQlPageInfo { | ||
| #[serde(rename = "hasNextPage")] | ||
| has_next_page: bool, | ||
| #[serde(rename = "endCursor")] | ||
| end_cursor: Option<String>, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize)] | ||
| struct GraphQlIssue { | ||
| number: u64, | ||
| title: String, | ||
| #[serde(rename = "createdAt")] | ||
| created_at: chrono::DateTime<chrono::Utc>, | ||
| assignees: GraphQlNodes<GraphQlUser>, | ||
| labels: Option<GraphQlNodes<GraphQlLabel>>, | ||
| comments: GraphQlNodes<GraphQlComment>, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize)] | ||
| struct GraphQlNodes<T> { | ||
| nodes: Vec<Option<T>>, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize)] | ||
| struct GraphQlUser { | ||
| login: String, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize)] | ||
| struct GraphQlLabel { | ||
| name: String, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize)] | ||
| struct GraphQlComment { | ||
| #[serde(rename = "createdAt")] | ||
| created_at: chrono::DateTime<chrono::Utc>, | ||
| } | ||
|
|
||
| impl From<GraphQlIssue> for GoalIssue { | ||
| fn from(issue: GraphQlIssue) -> Self { | ||
| let assignees = issue | ||
| .assignees | ||
| .nodes | ||
| .into_iter() | ||
| .flatten() | ||
| .map(|assignee| assignee.login) | ||
| .collect(); | ||
|
|
||
| let labels = issue | ||
| .labels | ||
| .map(|labels| { | ||
| labels | ||
| .nodes | ||
| .into_iter() | ||
| .flatten() | ||
| .map(|label| label.name) | ||
| .collect() | ||
| }) | ||
| .unwrap_or_default(); | ||
|
|
||
| let last_comment = issue | ||
| .comments | ||
| .nodes | ||
| .into_iter() | ||
| .flatten() | ||
| .next() | ||
| .map(|comment| LastGoalComment { | ||
| created_at: comment.created_at, | ||
| }); | ||
|
|
||
| Self { | ||
| number: issue.number, | ||
| title: issue.title, | ||
| assignees, | ||
| created_at: issue.created_at, | ||
| labels, | ||
| last_comment, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl GithubClient { | ||
| /// Get every open tracking issue in `rust-lang/rust-project-goals`, | ||
| /// including the latest comment's date. | ||
| pub async fn open_goal_issues(&self) -> anyhow::Result<Vec<GoalIssue>> { | ||
| let mut cursor = None::<String>; | ||
| let mut issues = Vec::new(); | ||
|
|
||
| loop { | ||
| let mut response = self | ||
| .graphql_query( | ||
| r#" | ||
| query ( | ||
| $owner: String! | ||
| $repo: String! | ||
| $label: String! | ||
| $cursor: String | ||
| ) { | ||
| repository(owner: $owner, name: $repo) { | ||
| issues( | ||
| first: 100 | ||
| after: $cursor | ||
| states: [OPEN] | ||
| labels: [$label] | ||
| orderBy: { | ||
| field: CREATED_AT | ||
| direction: ASC | ||
| } | ||
| ) { | ||
| nodes { | ||
| number | ||
| title | ||
| createdAt | ||
| assignees(first: 100) { | ||
| nodes { | ||
| login | ||
| } | ||
| } | ||
| labels(first: 100) { | ||
| nodes { | ||
| name | ||
| } | ||
| } | ||
| comments(last: 1) { | ||
| nodes { | ||
| createdAt | ||
| } | ||
| } | ||
| } | ||
| pageInfo { | ||
| hasNextPage | ||
| endCursor | ||
| } | ||
| } | ||
| } | ||
| } | ||
| "#, | ||
| serde_json::json!({ | ||
| "owner": ORG, | ||
| "repo": REPO, | ||
| "label": LABEL, | ||
| "cursor": cursor.as_deref(), | ||
| }), | ||
| ) | ||
| .await | ||
| .context("failed to fetch goal issues")?; | ||
|
|
||
| let page = response | ||
| .pointer_mut("/data/repository/issues") | ||
| .context("data.repository.issues is missing from response")? | ||
| .take(); | ||
|
|
||
| let page: GraphQlConnection = | ||
| serde_json::from_value(page).context("failed to deserialize page")?; | ||
|
|
||
| issues.extend(page.nodes.into_iter().flatten().map(GoalIssue::from)); | ||
|
|
||
| if !page.page_info.has_next_page { | ||
| break; | ||
| } | ||
|
|
||
| cursor = page.page_info.end_cursor; | ||
| } | ||
|
|
||
| Ok(issues) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.