Skip to content

Commit aec8d5c

Browse files
committed
update format_pull_requests_to_md, format_contributors_to_md, and format_labels_to_md
updates the `format_pull_requests_to_md`, `format_contributors_to_md`, and `format_labels_to_md` functions in the `src/github_graphql/mod.rs` file. the changes include iterating over each pull request, contributor, and label to generate a markdown-formatted string which can then be used for displaying the data. the strings are then joined together before being returned.
1 parent f0ad263 commit aec8d5c

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/github_graphql/mod.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ pub fn format_pull_requests_to_md(
101101
pull_requests: &Result<std::vec::Vec<PullRequest>, std::boxed::Box<dyn std::error::Error>>,
102102
) -> String {
103103
match pull_requests {
104-
Ok(pull_requests) => {
105-
let mut pull_requests_md = String::new();
106-
pull_requests.iter().for_each(|pr| {
107-
pull_requests_md.push_str(&format!(
104+
Ok(pull_requests) => pull_requests
105+
.iter()
106+
.map(|pr| {
107+
format!(
108108
"- [{}]({})\n",
109109
pr.title,
110110
pr.url.to_string().replace("api.", "").replace("repos/", "")
111-
));
112-
});
113-
pull_requests_md.to_string()
114-
}
111+
)
112+
})
113+
.collect::<Vec<String>>()
114+
.join(""),
115115
Err(e) => format!("Error: {}", e),
116116
}
117117
}
@@ -120,21 +120,21 @@ pub fn format_contributors_to_md(
120120
pull_requests: &Result<std::vec::Vec<PullRequest>, std::boxed::Box<dyn std::error::Error>>,
121121
) -> String {
122122
match pull_requests {
123-
Ok(pull_requests) => {
124-
let mut contributors = String::new();
125-
pull_requests.iter().for_each(|pr| {
126-
contributors.push_str(&format!(
123+
Ok(pull_requests) => pull_requests
124+
.iter()
125+
.map(|pr| {
126+
format!(
127127
"- [{}]({})\n",
128128
pr.author.login,
129129
pr.author
130130
.url
131131
.to_string()
132132
.replace("api.", "")
133133
.replace("users/", "")
134-
));
135-
});
136-
contributors.to_string()
137-
}
134+
)
135+
})
136+
.collect::<Vec<String>>()
137+
.join(""),
138138
Err(e) => format!("Error: {}", e),
139139
}
140140
}
@@ -159,15 +159,16 @@ pub fn format_labels_to_md(
159159
pull_requests: &Result<std::vec::Vec<PullRequest>, std::boxed::Box<dyn std::error::Error>>,
160160
) -> String {
161161
match pull_requests {
162-
Ok(pull_requests) => {
163-
let mut labels = String::new();
164-
pull_requests.iter().for_each(|pr| {
165-
pr.labels.iter().for_each(|label| {
166-
labels.push_str(&format!("- {}\n", label.name,));
167-
});
168-
});
169-
labels.to_string()
170-
}
162+
Ok(pull_requests) => pull_requests
163+
.iter()
164+
.map(|pr| {
165+
pr.labels
166+
.iter()
167+
.map(|label| format!("- {}\n", label.name))
168+
.collect::<String>()
169+
})
170+
.collect::<Vec<String>>()
171+
.join(""),
171172
Err(e) => format!("Error: {}", e),
172173
}
173174
}

0 commit comments

Comments
 (0)