Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 18 additions & 52 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,62 +205,28 @@ pub static PATH_NON_PRISTINE: Lazy<Vec<PathBuf>> = Lazy::new(|| match var(&*PATH
});
pub static DIRENV_DIFF: Lazy<Option<String>> = Lazy::new(|| var("DIRENV_DIFF").ok());
pub static GITHUB_TOKEN: Lazy<Option<String>> = Lazy::new(|| {
let token = var("MISE_GITHUB_TOKEN")
var("MISE_GITHUB_TOKEN")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use them often but I feel this is an area where unit tests might be better than e2e. You'd need to refactor it into a function somehow

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that said if it's too much of a pain don't worry about it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll write the test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the tests, but not really sure if they're good. Could you take a look?

.or_else(|_| var("GITHUB_API_TOKEN"))
.or_else(|_| var("GITHUB_TOKEN"))
.ok()
.and_then(|v| if v.is_empty() { None } else { Some(v) });

// set or unset the token for plugins+ubi
if let Some(token) = token.as_ref() {
set_var("MISE_GITHUB_TOKEN", token);
set_var("GITHUB_TOKEN", token);
set_var("GITHUB_API_TOKEN", token);
} else {
remove_var("MISE_GITHUB_TOKEN");
remove_var("GITHUB_TOKEN");
remove_var("GITHUB_API_TOKEN");
}

token
.and_then(|v| if v.is_empty() { None } else { Some(v) })
});
pub static MISE_GITHUB_ENTERPRISE_TOKEN: Lazy<Option<String>> = Lazy::new(|| {
var("MISE_GITHUB_ENTERPRISE_TOKEN")
.ok()
.and_then(|v| if v.trim().is_empty() { None } else { Some(v) })
});
pub static GITLAB_TOKEN: Lazy<Option<String>> = Lazy::new(|| {
var("MISE_GITLAB_TOKEN")
.or_else(|_| var("GITLAB_API_TOKEN"))
.ok()
.and_then(|v| if v.is_empty() { None } else { Some(v) })
});
pub static MISE_GITLAB_ENTERPRISE_TOKEN: Lazy<Option<String>> = Lazy::new(|| {
var("MISE_GITLAB_ENTERPRISE_TOKEN")
.ok()
.and_then(|v| if v.trim().is_empty() { None } else { Some(v) })
});
pub static MISE_GITHUB_ENTERPRISE_TOKEN: Lazy<Option<String>> =
Lazy::new(|| match var("MISE_GITHUB_ENTERPRISE_TOKEN") {
Ok(v) if v.trim() != "" => {
set_var("MISE_GITHUB_ENTERPRISE_TOKEN", &v);
Some(v)
}
_ => {
remove_var("MISE_GITHUB_ENTERPRISE_TOKEN");
None
}
});
pub static GITLAB_TOKEN: Lazy<Option<String>> =
Lazy::new(
|| match var("MISE_GITLAB_TOKEN").or_else(|_| var("GITLAB_TOKEN")) {
Ok(v) if v.trim() != "" => {
set_var("MISE_GITLAB_TOKEN", &v);
set_var("GITLAB_TOKEN", &v);
Some(v)
}
_ => {
remove_var("MISE_GITLAB_TOKEN");
remove_var("GITLAB_TOKEN");
None
}
},
);
pub static MISE_GITLAB_ENTERPRISE_TOKEN: Lazy<Option<String>> =
Lazy::new(|| match var("MISE_GITLAB_ENTERPRISE_TOKEN") {
Ok(v) if v.trim() != "" => {
set_var("MISE_GITLAB_ENTERPRISE_TOKEN", &v);
Some(v)
}
_ => {
remove_var("MISE_GITLAB_ENTERPRISE_TOKEN");
None
}
});

pub static TEST_TRANCHE: Lazy<usize> = Lazy::new(|| var_u8("TEST_TRANCHE") as usize);
pub static TEST_TRANCHE_COUNT: Lazy<usize> = Lazy::new(|| var_u8("TEST_TRANCHE_COUNT") as usize);
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/asdf_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,10 @@ fn build_script_man(name: &str, plugin_path: &Path) -> ScriptManager {
.with_env("MISE_PLUGIN_PATH", plugin_path)
.with_env("MISE_SHIMS_DIR", *dirs::SHIMS);
if let Some(token) = &*env::GITHUB_TOKEN {
// asdf plugins often use GITHUB_API_TOKEN as the env var for GitHub API token
sm = sm.with_env("GITHUB_API_TOKEN", token.to_string());
sm = sm
.with_env("GITHUB_TOKEN", token.to_string())
// asdf plugins often use GITHUB_API_TOKEN as the env var for GitHub API token
.with_env("GITHUB_API_TOKEN", token.to_string());
}
sm
}
Loading