Skip to content

Commit a6e4fc0

Browse files
committed
Added gh_validation_id to report #20
1 parent 8411984 commit a6e4fc0

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ The code analysis is non-judgemental. It simply collects the facts such as what
1010
- [Quick start](#quick-start)
1111
- [Adding more commit emails](#adding-more-commit-emails)
1212
- [Adding more projects to your profile](#adding-more-projects-to-your-profile)
13+
- [Making your profile public](#making-your-profile-public)
1314
- [Using StackMuncher app on multiple machines](#using-stackmuncher-app-on-multiple-machines)
1415
- [Detailed usage instructions](#detailed-usage-instructions)
1516
- [Additional options](#additional-options)
1617
- [Processing settings](#processing-settings)
1718
- [Profile settings](#profile-settings)
1819
- [Debug settings](#debug-settings)
19-
- [Additional commands](#additional-commands)
20+
- [Additional info](#additional-info)
2021
- [Limitations](#limitations)
2122
- [Troubleshooting](#troubleshooting)
2223
- [Bug reports and contributions](#bug-reports-and-contributions)
@@ -225,7 +226,7 @@ We want to hear about as many issues users run into as possible. Copy-paste the
225226
* run `stackmuncher config` and check the output in `reports` folder - there should be at least 4 files:
226227
* _project_report.json_: includes all contributors
227228
* _combined_report.json_: a combined report for authors/committers from Git's `user.email` setting and from `--emails` param
228-
* _submitted_report.json_: a sanitized version of the combined report exactly as it was submitted to the Directory
229+
* _submission.json_: a sanitized version of the combined report exactly as it is submitted to the Directory
229230
* _contributor_xxxxxxxx.json_: cached reports for individual contributors
230231
231232
## Bug reports and contributions

stackmuncher/src/cmd_config.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,18 @@ pub(crate) async fn view_config(config: AppConfig) {
7777
.to_string_lossy()
7878
.to_string();
7979

80-
let (public_profile, github_validation) =
81-
match get_validated_gist(&config.gh_validation_id, &config.user_key_pair).await {
82-
Some(v) => (["https://stackmuncher.com/", &v.login].concat(), v.html_url),
83-
None => ("disabled".to_owned(), "not set".to_owned()),
84-
};
80+
// gh_validation_gist may already be in the config if --gist option was used and it was validated
81+
// otherwise we need to re-validate it and get the details from github
82+
let gh_validation_gist = match config.gh_validation_gist {
83+
Some(v) => Some(v),
84+
None => get_validated_gist(&config.gh_validation_id, &config.user_key_pair).await,
85+
};
86+
87+
// prepare user-friendly GH validation messages
88+
let (public_profile, github_validation) = match gh_validation_gist {
89+
Some(v) => (["https://stackmuncher.com/", &v.login].concat(), v.html_url),
90+
None => ("disabled".to_owned(), "not set".to_owned()),
91+
};
8592

8693
println!();
8794
println!(" Primary email: {}", config.primary_email.as_ref().unwrap_or(&"not set".to_owned()));

stackmuncher/src/cmd_munch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ pub(crate) async fn run(config: AppConfig) -> Result<(), ()> {
156156

157157
// add any personal details supplied via CLI or taken from the environment
158158
combined_report.primary_email = config.primary_email.clone();
159+
combined_report.gh_validation_id = config.gh_validation_id.clone();
159160

160161
// check if there is a already a cached contributor report
161162
// it would have to be a dry run (no submission) if it's the first time STM is run on this repo

stackmuncher/src/config.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,24 @@ pub(crate) struct AppConfig {
2828
pub primary_email: Option<String>,
2929
/// A 32-byte long hex string of the Gist ID with the validation string for the user GH account
3030
/// E.g. `fb8fc0f87ee78231f064131022c8154a`
31+
/// It is validated on change and then cached in config.json
3132
pub gh_validation_id: Option<String>,
32-
/// The URL is reconstructed from a Gist ID after validation.
33-
/// It may seize to exist or change the contents, but the URL itself is guaranteed to be valid
34-
pub gh_validation_url: Option<String>,
3533
/// Core config from stackmuncher_lib
3634
pub lib_config: Config,
3735
/// Extracted from the key file stored next to the config file
3836
pub user_key_pair: Ed25519KeyPair,
3937
/// The full path to the config file.
4038
pub config_file_path: PathBuf,
39+
/// A stash for validation Gist details to avoid going to GitHub twice
40+
/// Not cached and can only be present if --gist param was used to link to a new github a/c
41+
pub gh_validation_gist: Option<crate::cmd_config::Gist>,
4142
}
4243

4344
/// A container for storing some config info locally as a file.
4445
#[derive(Serialize, Deserialize, PartialEq)]
4546
struct AppConfigCache {
4647
pub primary_email: Option<String>,
47-
/// The URL is reconstructed from a Gist ID after validation.
48-
/// It may seize to exist or change the contents, but the URL itself is guaranteed to be valid
49-
pub gh_validation_url: Option<String>,
48+
pub gh_validation_id: Option<String>,
5049
pub git_identities: Vec<String>,
5150
}
5251

@@ -235,29 +234,30 @@ impl AppConfig {
235234
println!();
236235
}
237236

238-
// GitHub login validation - use the validated URL or None if --gist param was provided
237+
// GitHub login validation - use the validated ID or None if --gist param was provided
239238
// It means that the user requested a change of sorts.
240239
// Otherwise use what is in the cache without any validation.
241-
let gh_validation_url = if app_args.gh_validation_id.is_some() {
242-
// --gist was present - so something was requested
240+
let (gh_validation_id, gh_validation_gist) = if app_args.gh_validation_id.is_some() {
241+
// --gist was present - so a change was requested by the user
243242
match crate::cmd_config::get_validated_gist(&app_args.gh_validation_id, &user_key_pair).await {
244-
Some(gist) => Some(gist.html_url),
245-
None => None,
243+
// 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),
246246
}
247247
} else {
248248
// --gist was not present - use what's in cache
249-
app_config_cache.gh_validation_url.clone()
249+
(app_config_cache.gh_validation_id.clone(), None)
250250
};
251251

252252
let app_config = AppConfig {
253253
command: app_args.command,
254254
dryrun: app_args.dryrun,
255255
primary_email,
256-
gh_validation_id: app_args.gh_validation_id,
257-
gh_validation_url,
256+
gh_validation_id,
258257
lib_config: config,
259258
user_key_pair,
260259
config_file_path,
260+
gh_validation_gist,
261261
};
262262

263263
app_config_cache.save(&app_config);
@@ -505,7 +505,7 @@ impl AppConfigCache {
505505
// create a blank dummy to return in case of a problem
506506
let app_config_cache = AppConfigCache {
507507
primary_email: None,
508-
gh_validation_url: None,
508+
gh_validation_id: None,
509509
git_identities: Vec::new(),
510510
};
511511

@@ -557,7 +557,7 @@ impl AppConfigCache {
557557
// prepare the data to save
558558
let app_config_cache = AppConfigCache {
559559
primary_email: app_config.primary_email.clone(),
560-
gh_validation_url: app_config.gh_validation_url.clone(),
560+
gh_validation_id: app_config.gh_validation_id.clone(),
561561
git_identities: app_config.lib_config.git_identities.clone(),
562562
};
563563

stackmuncher_lib/src/report.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ pub struct Report {
5555
/// A unique name containing user name and project name when stored in S3, e.g. `rimutaka/stackmuncher.report`
5656
#[serde(skip_serializing_if = "String::is_empty", default = "String::new")]
5757
pub report_s3_name: String,
58+
/// A GH ownership validation Gist ID.
59+
/// E.g. fb8fc0f87ee78231f064131022c8154a from https://gist.github.com/rimutaka/fb8fc0f87ee78231f064131022c8154a
60+
/// The app validates it, but it has to be re-checked on the server on changes and possibly more often.
61+
#[serde(skip_serializing_if = "Option::is_none")]
62+
pub gh_validation_id: Option<String>,
5863
/// The very last commit at the time of the report generation.
5964
#[serde(skip_serializing_if = "Option::is_none")]
6065
pub report_commit_sha1: Option<String>,
@@ -512,6 +517,7 @@ impl Report {
512517
first_contributor_commit_date_epoch: None,
513518
owner_id: None,
514519
project_id: None,
520+
gh_validation_id: None,
515521
}
516522
}
517523

0 commit comments

Comments
 (0)