3 files changed
+18
-16
src/account/signup/process.rs
+14
-12
@@ -96,7 +96,13 @@ pub async fn signup_with_github() -> Result<CommandResult> {
96
// Spin up a simple localhost server to listen for the GitHub OAuth callback
97
// setup_oauth_callback_server();
98
// Open the GitHub OAuth URL in the user's browser
99
- spinner_newline("Getting your GitHub information...".to_owned());
99
+ let mut spinner = Spinner::new(
100
+ spinners::Spinners::BouncingBall,
101
+ style("Getting your GitHub information...")
102
+ .green()
103
+ .bold()
104
+ .to_string(),
105
+ );
106
107
let rx = match open::that(build_github_oauth_url()) {
108
Ok(_) => {
@@ -116,6 +122,8 @@ pub async fn signup_with_github() -> Result<CommandResult> {
122
}
123
};
124
125
+ spinner.stop_and_persist("⌛", "Waiting for the authorization.".into());
126
+
127
debug!("Waiting for code from channel...");
128
129
match rx.recv() {
@@ -125,7 +133,7 @@ pub async fn signup_with_github() -> Result<CommandResult> {
133
}
134
Err(e) => {
135
let error = anyhow!("Failed to get code from channel: {e}");
128
- return Err(error);
136
+ Err(error)
137
}
138
}
139
}
@@ -146,7 +154,7 @@ fn handle_connection(mut stream: TcpStream, tx: Sender<String>) {
154
155
let code_regex = Regex::new(r"code=([^&]*)").unwrap();
156
149
- let (status_line, filename) = match code_regex.captures(&request_line) {
157
+ let (status_line, filename) = match code_regex.captures(request_line) {
158
Some(group) => {
159
let code = group.get(1).unwrap().as_str();
160
debug!("Code: {:#?}", code);
@@ -253,8 +261,10 @@ async fn get_github_data(token: String) -> Result<CommandResult> {
261
StatusCode::OK => {
262
spinner.stop_and_persist("✔", "Finished requesting GitHub token!".into());
263
debug!("Response: {:#?}", &response);
256
- let emails: Vec<GithubEmail> = response.json().await?;
264
+ let mut emails: Vec<GithubEmail> = response.json().await?;
265
debug!(&emails);
266
+ emails.retain(|e| !e.email.contains("@users.noreply.github.com"));
267
+
268
let email = select_github_emails(emails)?;
269
signup_with_email(Some(email.email)).await
270
}
@@ -277,14 +287,6 @@ fn select_github_emails(github_emails: Vec<GithubEmail>) -> Result<GithubEmail>
287
Ok(selection)
288
}
289
280
-fn spinner_newline(message: String) {
281
- Spinner::new(
282
- spinners::Spinners::BouncingBall,
283
- style(message).green().bold().to_string(),
284
- )
285
- .stop_with_newline();
286
-}
287
-
290
fn github_url_builder() -> URLBuilder {
291
let client_id = dotenv::var("GITHUB_OAUTH_CLIENT_ID").unwrap_or("development".to_owned());
292
let redirect_uri =
src/projects/crud/mod.rs
+1
-1
@@ -52,7 +52,7 @@ pub async fn create_project(project: ProjectCreate) -> Result<Project> {
52
match response.status() {
53
reqwest::StatusCode::CREATED => {
54
let project: Project = response.json().await?;
55
- println!("Project created: {:#?}", project);
55
+ println!("Project created: {project:#?}");
56
Ok(project)
57
}
58
_ => {
src/projects/mod.rs
+3
-3
@@ -62,7 +62,7 @@ pub async fn process(commands: Commands) -> Result<CommandResult> {
62
msg: format!("Creating a project {project_name}."),
63
}),
64
Err(e) => {
65
- println!("Error: {:#?}", e);
65
+ println!("Error: {e:#?}");
66
Ok(CommandResult {
67
spinner,
68
symbol: "❌".to_owned(),
@@ -80,7 +80,7 @@ pub async fn process(commands: Commands) -> Result<CommandResult> {
80
// Get all
81
match get_all().await {
82
Ok(projects) => {
83
- println!("Projects: {:#?}", projects);
83
+ println!("Projects: {projects:#?}");
84
println!(
85
"{0: <5} | {1: <20} | {2: <30} | {3: <30}",
86
"ID", "Name", "Created at", "Updated at"
@@ -98,7 +98,7 @@ pub async fn process(commands: Commands) -> Result<CommandResult> {
98
})
99
}
100
Err(e) => {
101
- println!("Error: {:#?}", e);
101
+ println!("Error: {e:#?}");
102
Ok(CommandResult {
103
spinner,
104
symbol: "❌".to_owned(),