Skip to content
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

refactor get_changelog_info to use async including prs, contributors … #29

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

falcucci
Copy link
Owner

@falcucci falcucci commented Aug 8, 2023

…and labels

refactored the get_changelog_info function in github_graphql/mod.rs to use async instead of blocking. this refactor allows for improved performance and scalability when fetching pull request information.

diff --git a/src/github_graphql/mod.rs b/src/github_graphql/mod.rs
index fce1f915bb66..7b84ebf64d9a 100644
--- a/src/github_graphql/mod.rs
+++ b/src/github_graphql/mod.rs
@@ -122,13 +122,25 @@ fn get_labels(pr: &option<milestonequeryrepositorymilestonesnodespullrequestsnod
     .unwrap_or_else(vec::new)
 }

-pub fn format_pull_requests_to_md(pull_requests: &[pullrequest]) -> string {
+pub fn get_changelog_info(pull_requests: &[pullrequest]) -> (string, string, string) {
+  block_on(format_pull_requests_info(pull_requests))
+}
+
+pub async fn format_pull_requests_info(pull_requests: &[pullrequest]) -> (string, string, string) {
+  let pr_fut = format_pull_requests_to_md(pull_requests);
+  let contributors_fut = format_contributors_to_md(pull_requests);
+  let labels_fut = format_labels_to_md(pull_requests);
+  let (pr, contributors, labels) = join3(pr_fut, contributors_fut, labels_fut).await;
+  (pr, contributors, labels)
+}
+
+pub async fn format_pull_requests_to_md(pull_requests: &[pullrequest]) -> string {
   format_items_to_md(pull_requests, |pr| {
     format!("- [{}]({})\n", pr.title, format_url(pr.url.to_string()))
   })
 }

-pub fn format_contributors_to_md(pull_requests: &[pullrequest]) -> string {
+pub async fn format_contributors_to_md(pull_requests: &[pullrequest]) -> string {
   format_items_to_md(pull_requests, |pr| {
     format!(
       "- [@{}]({})\n",
@@ -138,7 +150,7 @@ pub fn format_contributors_to_md(pull_requests: &[pullrequest]) -> string {
   })
 }

-pub fn format_labels_to_md(pull_requests: &[pullrequest]) -> string {
+pub async fn format_labels_to_md(pull_requests: &[pullrequest]) -> string {
   format_items_to_md(pull_requests, |pr| {
     pr.labels
       .iter()

this commit refactors the get_changelog_info function to use async for improved performance and scalability when fetching pull request information.

…and labels

refactored the `get_changelog_info` function in `github_graphql/mod.rs` to use async instead of blocking. this refactor allows for improved performance and scalability when fetching pull request information.

```diff
diff --git a/src/github_graphql/mod.rs b/src/github_graphql/mod.rs
index fce1f915bb66..7b84ebf64d9a 100644
--- a/src/github_graphql/mod.rs
+++ b/src/github_graphql/mod.rs
@@ -122,13 +122,25 @@ fn get_labels(pr: &option<milestonequeryrepositorymilestonesnodespullrequestsnod
     .unwrap_or_else(vec::new)
 }

-pub fn format_pull_requests_to_md(pull_requests: &[pullrequest]) -> string {
+pub fn get_changelog_info(pull_requests: &[pullrequest]) -> (string, string, string) {
+  block_on(format_pull_requests_info(pull_requests))
+}
+
+pub async fn format_pull_requests_info(pull_requests: &[pullrequest]) -> (string, string, string) {
+  let pr_fut = format_pull_requests_to_md(pull_requests);
+  let contributors_fut = format_contributors_to_md(pull_requests);
+  let labels_fut = format_labels_to_md(pull_requests);
+  let (pr, contributors, labels) = join3(pr_fut, contributors_fut, labels_fut).await;
+  (pr, contributors, labels)
+}
+
+pub async fn format_pull_requests_to_md(pull_requests: &[pullrequest]) -> string {
   format_items_to_md(pull_requests, |pr| {
     format!("- [{}]({})\n", pr.title, format_url(pr.url.to_string()))
   })
 }

-pub fn format_contributors_to_md(pull_requests: &[pullrequest]) -> string {
+pub async fn format_contributors_to_md(pull_requests: &[pullrequest]) -> string {
   format_items_to_md(pull_requests, |pr| {
     format!(
       "- [@{}]({})\n",
@@ -138,7 +150,7 @@ pub fn format_contributors_to_md(pull_requests: &[pullrequest]) -> string {
   })
 }

-pub fn format_labels_to_md(pull_requests: &[pullrequest]) -> string {
+pub async fn format_labels_to_md(pull_requests: &[pullrequest]) -> string {
   format_items_to_md(pull_requests, |pr| {
     pr.labels
       .iter()
```

this commit refactors the `get_changelog_info` function to use async for improved performance and scalability when fetching pull request information.
@falcucci falcucci added this to the 2.0 milestone Aug 8, 2023
@falcucci falcucci self-assigned this Aug 8, 2023
@falcucci falcucci linked an issue Aug 8, 2023 that may be closed by this pull request
@falcucci falcucci merged commit 64278f0 into master Aug 8, 2023
@falcucci falcucci deleted the 28-run-parallel-functions-when-necessary branch August 8, 2023 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

run parallel functions when necessary
1 participant