Skip to content

Commit e049c33

Browse files
committed
Print public profile URL if available #20
1 parent a6e4fc0 commit e049c33

File tree

4 files changed

+25
-37
lines changed

4 files changed

+25
-37
lines changed

stackmuncher/src/cmd_munch.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,11 @@ pub(crate) async fn run(config: AppConfig) -> Result<(), ()> {
194194
}
195195
warn!("Skipping report submission: `--dryrun` flag.")
196196
} else {
197-
if let Some(current_identity) = &config.primary_email {
198-
if current_identity.is_empty() {
199-
info!("Skipping report submission: blank primary_email");
200-
// notify the user there was no profile update
201-
help::emit_no_primary_email_msg();
202-
} else {
203-
if first_run {
204-
info!("No report submission on the first run");
205-
help::emit_dryrun_msg(&sanitized_report_file_name.to_string_lossy());
206-
} else {
207-
submission_jobs.push(submit_report(combined_report.clone(), &config));
208-
}
209-
}
197+
if first_run {
198+
info!("No report submission on the first run");
199+
help::emit_dryrun_msg(&sanitized_report_file_name.to_string_lossy());
210200
} else {
211-
help::emit_no_primary_email_msg();
201+
submission_jobs.push(submit_report(combined_report.clone(), &config));
212202
}
213203
}
214204
}

stackmuncher/src/config.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ const CONFIG_FOLDER_NAME_WIN: &'static str = ".stm_config";
2525
pub(crate) struct AppConfig {
2626
pub command: AppArgCommands,
2727
pub dryrun: bool,
28+
// An empty string means NO CONTACT
2829
pub primary_email: Option<String>,
2930
/// A 32-byte long hex string of the Gist ID with the validation string for the user GH account
3031
/// E.g. `fb8fc0f87ee78231f064131022c8154a`
3132
/// It is validated on change and then cached in config.json
3233
pub gh_validation_id: Option<String>,
34+
/// GitHub login of the user. It is set after validating the a/c ownership and then cached in config.json
35+
pub gh_login: Option<String>,
3336
/// Core config from stackmuncher_lib
3437
pub lib_config: Config,
3538
/// Extracted from the key file stored next to the config file
@@ -44,8 +47,11 @@ pub(crate) struct AppConfig {
4447
/// A container for storing some config info locally as a file.
4548
#[derive(Serialize, Deserialize, PartialEq)]
4649
struct AppConfigCache {
50+
// An empty string means NO CONTACT
4751
pub primary_email: Option<String>,
4852
pub gh_validation_id: Option<String>,
53+
// It is a derivitive value. Used for displaying a profile URL only.
54+
pub gh_login: Option<String>,
4955
pub git_identities: Vec<String>,
5056
}
5157

@@ -171,7 +177,7 @@ impl AppConfig {
171177
if prim_email_arg.is_empty() {
172178
// reset the value to NULL if `--primary_email ""`
173179
debug!("Resetting primary_email to an empty string");
174-
println!("Your primary email address for notifications from the Directory was removed. Your profile will no longer be updated. You can still generate and view stack reports locally.");
180+
println!("Your primary email address for notifications from the Directory was removed.");
175181
println!();
176182
Some(String::new())
177183
} else {
@@ -199,7 +205,7 @@ impl AppConfig {
199205
println!("Missing preferred contact email. Your profile will not be updated. You can still generate and view your stack reports locally.");
200206
println!();
201207
println!(
202-
" Run `stackmuncher{} --primary_email [email protected]` to start updating your Directory profile.",
208+
" Run `stackmuncher{} --primary_email [email protected]` to set your preferred contact email for notifications about profile views and employer interest.",
203209
EXE_SUFFIX
204210
);
205211
println!();
@@ -237,16 +243,16 @@ impl AppConfig {
237243
// GitHub login validation - use the validated ID or None if --gist param was provided
238244
// It means that the user requested a change of sorts.
239245
// Otherwise use what is in the cache without any validation.
240-
let (gh_validation_id, gh_validation_gist) = if app_args.gh_validation_id.is_some() {
246+
let (gh_validation_id, gh_login, gh_validation_gist) = if app_args.gh_validation_id.is_some() {
241247
// --gist was present - so a change was requested by the user
242248
match crate::cmd_config::get_validated_gist(&app_args.gh_validation_id, &user_key_pair).await {
243249
// the gist struct will be needed to print config details later
244-
Some(gist) => (app_args.gh_validation_id.clone(), Some(gist)),
245-
None => (None, None),
250+
Some(gist) => (app_args.gh_validation_id.clone(), Some(gist.login.clone()), Some(gist)),
251+
None => (None, None, None),
246252
}
247253
} else {
248254
// --gist was not present - use what's in cache
249-
(app_config_cache.gh_validation_id.clone(), None)
255+
(app_config_cache.gh_validation_id.clone(), app_config_cache.gh_login.clone(), None)
250256
};
251257

252258
let app_config = AppConfig {
@@ -258,6 +264,7 @@ impl AppConfig {
258264
user_key_pair,
259265
config_file_path,
260266
gh_validation_gist,
267+
gh_login,
261268
};
262269

263270
app_config_cache.save(&app_config);
@@ -506,6 +513,7 @@ impl AppConfigCache {
506513
let app_config_cache = AppConfigCache {
507514
primary_email: None,
508515
gh_validation_id: None,
516+
gh_login: None,
509517
git_identities: Vec::new(),
510518
};
511519

@@ -559,6 +567,7 @@ impl AppConfigCache {
559567
primary_email: app_config.primary_email.clone(),
560568
gh_validation_id: app_config.gh_validation_id.clone(),
561569
git_identities: app_config.lib_config.git_identities.clone(),
570+
gh_login: app_config.gh_login.clone(),
562571
};
563572

564573
// proceed only if there were any changes to the config or if the config file doesn't exist to create a stub the user can edit

stackmuncher/src/help.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,6 @@ pub(crate) fn emit_gist_instructions(gist_content: &String) {
146146
eprintln!();
147147
}
148148

149-
/// Prints a message about a missing primary_email.
150-
pub(crate) fn emit_no_primary_email_msg() {
151-
eprintln!();
152-
eprintln!("A stack report was generated, but NOT submitted.");
153-
eprintln!();
154-
eprintln!(
155-
" Run `stackmuncher{exe_suffix} --primary_email [email protected]` to set your primary email and resume the updates.",
156-
exe_suffix = EXE_SUFFIX
157-
);
158-
eprintln!();
159-
eprintln!(
160-
" Your primary email can only be used to send you system updates and notifications about employer interest."
161-
);
162-
eprintln!();
163-
}
164-
165149
/// Prints out either Win or nix/Mac Welcome msg.
166150
pub(crate) fn emit_welcome_msg(config: AppConfig) {
167151
let pub_key = ReportSignature::get_public_key(&config.user_key_pair);

stackmuncher/src/submission.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ pub(crate) async fn submit_report(report: Report, config: &AppConfig) {
7171
if status.as_u16() == 200 && buf.is_empty() {
7272
debug!("Empty response body, 200 OK");
7373

74-
println!(" Directory profile: https://stackmuncher.com/?dev={}", report_sig.public_key.clone());
74+
// public profile is preferred, but not be enabled
75+
if let Some(gh_login) = &config.gh_login {
76+
println!(" Public profile: https://stackmuncher.com/{}", gh_login);
77+
} else {
78+
println!(" Directory profile: https://stackmuncher.com/?dev={}", report_sig.public_key);
79+
}
7580

7681
return;
7782
}

0 commit comments

Comments
 (0)