Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion docs/dev-tools/backends/forgejo.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ The legacy `$1`/`${1}` hostname argument is deprecated. Use `MISE_CREDENTIAL_HOS
mise can read tokens from the [`fj` CLI](https://codeberg.org/forgejo-contrib/forgejo-cli) (`keys.json`) as a fallback. It checks:

1. `$XDG_DATA_HOME/forgejo-cli/keys.json` (defaults to `~/.local/share/forgejo-cli/keys.json`)
2. `~/Library/Application Support/Cyborus.forgejo-cli/keys.json` (macOS)
2. `~/Library/Application Support/forgejo-cli.forgejo-cli/keys.json` (macOS)
3. `~/Library/Application Support/Cyborus.forgejo-cli/keys.json` (legacy macOS location)

Disable this fallback with:

Expand Down
3 changes: 2 additions & 1 deletion settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,8 @@ description = "Read Forgejo tokens from the fj CLI config."
docs = """
When enabled, mise will read tokens from the fj CLI keys file
(`~/.local/share/forgejo-cli/keys.json` on Linux,
`~/Library/Application Support/Cyborus.forgejo-cli/keys.json` on macOS).
`~/Library/Application Support/forgejo-cli.forgejo-cli/keys.json` on macOS,
with the legacy `Cyborus.forgejo-cli` location as a fallback).
This is used as a fallback when no `FORGEJO_TOKEN` or `MISE_FORGEJO_TOKEN`
environment variable is set.

Expand Down
49 changes: 37 additions & 12 deletions src/forgejo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,29 @@ static FJ_HOSTS: Lazy<HashMap<String, String>> = Lazy::new(|| read_fj_hosts().un
fn fj_keys_path() -> Option<PathBuf> {
// Linux/XDG: $XDG_DATA_HOME/forgejo-cli/keys.json
let xdg_path = env::XDG_DATA_HOME.join("forgejo-cli/keys.json");
if xdg_path.exists() {
return Some(xdg_path);
}
let candidates = [xdg_path.clone()]
.into_iter()
.chain(fj_native_keys_paths())
.collect();
Some(tokens::first_existing_file(candidates, xdg_path))
}

#[cfg(target_os = "macos")]
{
let macos_path =
dirs::HOME.join("Library/Application Support/Cyborus.forgejo-cli/keys.json");
if macos_path.exists() {
return Some(macos_path);
}
}
#[cfg(target_os = "macos")]
fn fj_native_keys_paths() -> Vec<PathBuf> {
fj_macos_keys_paths(&dirs::HOME).into()
}

#[cfg(not(target_os = "macos"))]
fn fj_native_keys_paths() -> Vec<PathBuf> {
Vec::new()
}

Some(xdg_path)
#[cfg(any(target_os = "macos", test))]
fn fj_macos_keys_paths(home: &std::path::Path) -> [PathBuf; 2] {
[
home.join("Library/Application Support/forgejo-cli.forgejo-cli/keys.json"),
home.join("Library/Application Support/Cyborus.forgejo-cli/keys.json"),
]
}

fn read_fj_hosts() -> Option<HashMap<String, String>> {
Expand Down Expand Up @@ -430,6 +439,22 @@ something_else = "value"
assert!(result.is_empty());
}

#[test]
fn test_fj_macos_keys_paths_prefers_current_path() {
let paths = fj_macos_keys_paths(std::path::Path::new("/Users/test"));
assert_eq!(
paths,
[
PathBuf::from(
"/Users/test/Library/Application Support/forgejo-cli.forgejo-cli/keys.json"
),
PathBuf::from(
"/Users/test/Library/Application Support/Cyborus.forgejo-cli/keys.json"
),
]
);
}

// #10343: a first page made up entirely of prereleases must not yield "no
// versions found" -- the fallback (bounded) follows the Link header to a later
// page that has a stable release. Forgejo paginates with limit=100.
Expand Down