-
Notifications
You must be signed in to change notification settings - Fork 106
Add automatic release of inactive claimed assignments #2430
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
Open
Urgau
wants to merge
6
commits into
rust-lang:main
Choose a base branch
from
Urgau:assign-auto-release
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed9ea91
Fix GraphQlError de-serialization for mixed path types
Urgau 7db764c
IssueData::load_raw
Urgau dbc0580
Add ASSIGN_KEY for the IssueBody key
Urgau f283386
Add issues_assigned query
Urgau 8b7d7a4
Add closing_issues_references query
Urgau 23b6994
Add release inactive assignments cronjob
Urgau 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
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,95 @@ | ||
| use anyhow::Context as _; | ||
| use chrono::{DateTime, Utc}; | ||
|
|
||
| use crate::github::{GithubClient, IssueNumber, PullRequestNumber}; | ||
|
|
||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct PullRequestWithClosingIssuesReferences { | ||
| pub number: PullRequestNumber, | ||
| pub updated_at: DateTime<Utc>, | ||
| pub closing_issues_references: Vec<ClosingIssueReference>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ClosingIssueReference { | ||
| pub number: IssueNumber, | ||
| } | ||
|
|
||
| impl GithubClient { | ||
| pub async fn closing_issues_references( | ||
| &self, | ||
| owner: &str, | ||
| repo: &str, | ||
| ) -> anyhow::Result<Vec<PullRequestWithClosingIssuesReferences>> { | ||
| fn page_info(data: &serde_json::Value) -> (bool, Option<String>) { | ||
| let has_next = data["pageInfo"]["hasNextPage"].as_bool().unwrap_or(false); | ||
| let end_cursor = data["pageInfo"]["endCursor"] | ||
| .as_str() | ||
| .map(|s| s.to_string()); | ||
| (has_next, end_cursor) | ||
| } | ||
|
|
||
| let mut prs_cursor: Option<String> = None; | ||
| let mut prs = Vec::<PullRequestWithClosingIssuesReferences>::new(); | ||
|
|
||
| loop { | ||
| let mut data = self | ||
| .graphql_query( | ||
| r##" | ||
| query ($owner: String!, $repo: String!, $after: String) { | ||
| repository(owner: $owner, name: $repo) { | ||
| pullRequests(first: 100, after: $after, states: OPEN) { | ||
| pageInfo { | ||
| hasNextPage | ||
| endCursor | ||
| } | ||
| nodes { | ||
| number | ||
| updatedAt | ||
| closingIssuesReferences(first: 10) { | ||
| nodes { | ||
| number | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| "##, | ||
| serde_json::json!({ | ||
| "owner": owner, | ||
| "repo": repo, | ||
| "after": prs_cursor.as_deref(), | ||
| }), | ||
| ) | ||
| .await | ||
| .context("failed to fetch opened issues")?; | ||
|
|
||
| let mut value = data["data"]["repository"]["pullRequests"].take(); | ||
|
|
||
| for val in value["nodes"].as_array_mut().context("no issues nodes")? { | ||
| prs.push(PullRequestWithClosingIssuesReferences { | ||
| number: val["number"].as_u64().context("no issue number")?, | ||
| updated_at: serde_json::from_value(val["updatedAt"].take())?, | ||
| closing_issues_references: serde_json::from_value( | ||
| val["closingIssuesReferences"]["nodes"].take(), | ||
| )?, | ||
| }); | ||
| } | ||
|
|
||
| let (has_next, new_end_cursor) = page_info(&value); | ||
|
|
||
| if new_end_cursor.is_some() { | ||
| prs_cursor = new_end_cursor; | ||
| } | ||
|
|
||
| if !has_next { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| use anyhow::Context as _; | ||
| use chrono::{DateTime, Utc}; | ||
|
|
||
| use crate::github::{GithubClient, IssueNumber}; | ||
|
|
||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct GitHubIssueAssigned { | ||
| pub number: IssueNumber, | ||
| pub updated_at: DateTime<Utc>, | ||
| pub assignees: Vec<GitHubAssignee>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct GitHubAssignee { | ||
| pub login: String, | ||
| #[serde(alias = "databaseId")] | ||
| pub id: u64, | ||
| } | ||
|
|
||
| impl GithubClient { | ||
| pub async fn issues_assigned( | ||
| &self, | ||
| owner: &str, | ||
| repo: &str, | ||
| ) -> anyhow::Result<Vec<GitHubIssueAssigned>> { | ||
| fn page_info(data: &serde_json::Value) -> (bool, Option<String>) { | ||
| let has_next = data["pageInfo"]["hasNextPage"].as_bool().unwrap_or(false); | ||
| let end_cursor = data["pageInfo"]["endCursor"] | ||
| .as_str() | ||
| .map(|s| s.to_string()); | ||
| (has_next, end_cursor) | ||
| } | ||
|
|
||
| let mut issues_cursor: Option<String> = None; | ||
| let mut issues = Vec::<GitHubIssueAssigned>::new(); | ||
|
|
||
| loop { | ||
| let mut data = self | ||
| .graphql_query( | ||
| r##" | ||
| query( | ||
| $owner: String!, | ||
| $repo: String!, | ||
| $after: String | ||
| ) { | ||
| repository(owner: $owner, name: $repo) { | ||
| issues( | ||
| first: 100, | ||
| after: $after, | ||
| filterBy: { | ||
| states: [OPEN], | ||
| assignee: "*" | ||
| } | ||
| ) { | ||
| pageInfo { | ||
| hasNextPage | ||
| endCursor | ||
| } | ||
| nodes { | ||
| number | ||
| updatedAt | ||
| assignees(first: 5) { | ||
| nodes { | ||
| login | ||
| databaseId | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| "##, | ||
| serde_json::json!({ | ||
| "owner": owner, | ||
| "repo": repo, | ||
| "after": issues_cursor.as_deref(), | ||
| }), | ||
| ) | ||
| .await | ||
| .context("failed to fetch opened issues")?; | ||
|
|
||
| let mut value = data["data"]["repository"]["issues"].take(); | ||
|
|
||
| for val in value["nodes"].as_array_mut().context("no issues nodes")? { | ||
| issues.push(GitHubIssueAssigned { | ||
| number: val["number"].as_u64().context("no issue number")?, | ||
| updated_at: serde_json::from_value(val["updatedAt"].take())?, | ||
| assignees: serde_json::from_value(val["assignees"]["nodes"].take())?, | ||
| }); | ||
| } | ||
|
|
||
| let (has_next, new_end_cursor) = page_info(&value); | ||
|
|
||
| if new_end_cursor.is_some() { | ||
| issues_cursor = new_end_cursor; | ||
| } | ||
|
|
||
| if !has_next { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| Ok(issues) | ||
| } | ||
| } |
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
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
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.
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.
Jobs are not handlers, and even though I know that there are some jobs inside the handlers module currently, I don't find that very readable. What do you think about having a separate module (directory) for jobs?
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.
Conceptually I like the idea, but when the handler and the job is so tightly integrated into each other I think it's better to have them close to each other.