Skip to content

Commit

Permalink
Fix new quest errors, fix Windows errors. Release v0.1.2 (#19)
Browse files Browse the repository at this point in the history
* Fix error when initializing quest. Improve time to show initial state

* Improve cross-platform handling of github token

* Show errors in filing issues/PRs

* Release 0.1.2
  • Loading branch information
willcrichton authored Sep 11, 2024
1 parent c065315 commit 2fd0c8c
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ We have prebuilt binaries for MacOS (x86-64 and ARM64), Linux (x86-64), and Wind

#### Windows

1. Download the installer (either `.msi` or `.exe) for your platform (arm64 for ARM chips, x64 otherwise).
1. Download the installer (either `.msi` or `.exe`) for your platform (arm64 for ARM chips, x64 otherwise).
2. Run the installer.
3. Launch RepoQuest, e.g. by searching for "RepoQuest" in your applications list.

Expand Down
2 changes: 1 addition & 1 deletion js/packages/repo-quest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "repo-quest",
"version": "0.1.1",
"version": "0.1.2",
"type": "module",
"depot": {
"platform": "browser",
Expand Down
53 changes: 45 additions & 8 deletions js/packages/repo-quest/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
events,
type QuestConfig,
type QuestState,
type Result,
type Stage,
type StageState,
type StateDescriptor,
Expand Down Expand Up @@ -88,6 +89,17 @@ let ErrorView: React.FC<{ message: string; action: string }> = ({
return null;
};

async function tryAwait<T>(
promise: Promise<Result<T, string>>,
action: string,
setMessage: (message: ErrorMessage) => void
) {
let result = await promise;
if (result.status === "error") {
setMessage({ action, message: result.error });
}
}

let GithubLoader = () => (
<Await promise={commands.getGithubToken()}>
{token =>
Expand All @@ -114,7 +126,7 @@ let GithubLoader = () => (
</div>
</>
) : (
<pre>ERROR: {token.value}</pre>
<ErrorView action="Loading Github token" message={token.value} />
)
}
</Await>
Expand All @@ -129,7 +141,10 @@ let LoaderEntry = () => {
<Await promise={promise}>
{quest_res =>
quest_res.status === "ok" ? (
<QuestView quest={quest_res.data} />
<QuestView
quest={quest_res.data[0]}
initialState={quest_res.data[1]}
/>
) : (
<InitForm />
)
Expand Down Expand Up @@ -163,7 +178,10 @@ let InitForm = () => {
<Await promise={commands.loadQuest(selected.dir)}>
{quest_res =>
quest_res.status === "ok" ? (
<QuestView quest={quest_res.data} />
<QuestView
quest={quest_res.data[0]}
initialState={quest_res.data[1]}
/>
) : (
<ErrorView action="Creating new quest" message={quest_res.error} />
)
Expand Down Expand Up @@ -229,7 +247,10 @@ let NewQuest = () => {
<Await promise={commands.newQuest(dir!, quest!)}>
{quest_res =>
quest_res.status === "ok" ? (
<QuestView quest={quest_res.data} />
<QuestView
quest={quest_res.data[0]}
initialState={quest_res.data[1]}
/>
) : (
<ErrorView action="Creating new quest" message={quest_res.error} />
)
Expand All @@ -238,9 +259,12 @@ let NewQuest = () => {
);
};

let QuestView: React.FC<{ quest: QuestConfig }> = ({ quest }) => {
let QuestView: React.FC<{
quest: QuestConfig;
initialState: StateDescriptor;
}> = ({ quest, initialState }) => {
let loader = useContext(Loader.context)!;
let [state, setState] = useState<StateDescriptor | undefined>(undefined);
let [state, setState] = useState<StateDescriptor | undefined>(initialState);
let setTitle = useContext(TitleContext)!;
useEffect(() => setTitle(quest.title), [quest.title]);

Expand Down Expand Up @@ -331,6 +355,7 @@ let StageView: React.FC<{
state: QuestState;
}> = ({ index, stage, state }) => {
let loader = useContext(Loader.context)!;
let setMessage = useContext(ErrorContext)!;
return (
<li>
<div>
Expand All @@ -342,7 +367,13 @@ let StageView: React.FC<{
<button
type="button"
onClick={() =>
loader.loadAwait(commands.fileFeatureAndIssue(index))
loader.loadAwait(
tryAwait(
commands.fileFeatureAndIssue(index),
"Filing issue or feature PR",
setMessage
)
)
}
>
{stage.stage["no-starter"]
Expand Down Expand Up @@ -372,7 +403,13 @@ let StageView: React.FC<{
<button
type="button"
onClick={() =>
loader.loadAwait(commands.fileSolution(index))
loader.loadAwait(
tryAwait(
commands.fileSolution(index),
"Filing solution PR",
setMessage
)
)
}
>
File reference solution
Expand Down
21 changes: 20 additions & 1 deletion rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rs/crates/repo-quest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "repo-quest"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
default-run = "repo-quest"

Expand All @@ -27,3 +27,4 @@ tauri-plugin-shell = "2.0.0-rc"
specta = "=2.0.0-rc.20"
specta-typescript = "0.0.7"
tauri-specta = { version = "=2.0.0-rc.19", features = ["derive", "typescript"] }
which = "6.0.3"
4 changes: 2 additions & 2 deletions rs/crates/repo-quest/Tauri.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
productName = "RepoQuest"
version = "0.1.1"
version = "0.1.2"
identifier = "com.repo-quest.app"

[build]
Expand All @@ -9,7 +9,7 @@ dev-url = "http://localhost:5173"
frontend-dist = "../../../js/packages/repo-quest/dist"

[app]
windows = [{title = "RepoQuest", width = 1200, height = 800}]
windows = [{title = "RepoQuest", width = 1000, height = 600}]

[bundle]
active = true
Expand Down
38 changes: 18 additions & 20 deletions rs/crates/repo-quest/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use regex::Regex;
use serde::{Deserialize, Serialize};
use serde_json::json;
use specta::Type;
use std::{env, fs, process::Command, sync::Arc, time::Duration};
use std::{fs, process::Command, sync::Arc, time::Duration};
use tokio::{time::timeout, try_join};
use tracing::warn;

Expand Down Expand Up @@ -52,7 +52,8 @@ impl GithubRepo {
}
}

pub async fn fetch(&self) -> Result<()> {
/// Returns true if repo
pub async fn fetch(&self) -> Result<bool> {
let (pr_handler, issue_handler) = (self.pr_handler(), self.issue_handler());
let res = try_join!(
pr_handler.list().state(octocrab::params::State::All).send(),
Expand All @@ -69,7 +70,7 @@ impl GithubRepo {
..
},
..
}) => return Ok(()),
}) => return Ok(false),
Err(e) => return Err(e.into()),
};
let (prs, mut issues) = (pr_page.take_items(), issue_page.take_items());
Expand All @@ -79,7 +80,8 @@ impl GithubRepo {

*self.prs.lock() = Some(prs);
*self.issues.lock() = Some(issues);
Ok(())

Ok(true)
}

pub fn remote(&self) -> String {
Expand Down Expand Up @@ -236,7 +238,7 @@ impl GithubRepo {
let is_reset = matches!(merge_type, MergeType::HardReset);
if is_reset {
body.push_str(r#"
Note: due to a merge conflict, this PR is a hard reset to the reference solution, and may have overwritten your previous changes."#);
}

Expand Down Expand Up @@ -409,22 +411,18 @@ fn read_github_token_from_fs() -> GithubToken {
}

fn generate_github_token_from_cli() -> GithubToken {
let shell = env::var("SHELL").unwrap_or_else(|_| "sh".into());
let which_status = Command::new(&shell).args(["-c", "which gh"]).status();
match which_status {
Ok(status) => {
if status.success() {
let token_output = token_try!(Command::new(shell)
.args(["-c", "gh auth token"])
.output()
.context("Failed to run `gh auth token`"));
let token = token_try!(String::from_utf8(token_output.stdout));
let token_clean = token.trim_end().to_string();
GithubToken::Found(token_clean)
} else {
GithubToken::NotFound
}
let gh_path_res = which::which("gh");
match gh_path_res {
Ok(gh_path) => {
let token_output = token_try!(Command::new(gh_path)
.args(["auth", "token"])
.output()
.context("Failed to run `gh auth token`"));
let token = token_try!(String::from_utf8(token_output.stdout));
let token_clean = token.trim_end().to_string();
GithubToken::Found(token_clean)
}
Err(which::Error::CannotFindBinaryPath) => GithubToken::NotFound,
Err(err) => GithubToken::Error(format!("{err:?}")),
}
}
Expand Down
21 changes: 15 additions & 6 deletions rs/crates/repo-quest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{env, path::PathBuf, sync::Arc};

use self::quest::{Quest, QuestConfig};
use github::GithubToken;
use quest::StateEvent;
use quest::{StateDescriptor, StateEvent};
use tauri::{AppHandle, Manager, State};
use tauri_specta::collect_events;

Expand Down Expand Up @@ -58,19 +58,28 @@ async fn load_quest_core(

#[tauri::command]
#[specta::specta]
async fn load_quest(dir: PathBuf, app: AppHandle) -> Result<QuestConfig, String> {
async fn load_quest(
dir: PathBuf,
app: AppHandle,
) -> Result<(QuestConfig, StateDescriptor), String> {
let config = fmt_err(QuestConfig::load(&dir))?;
load_quest_core(dir, &config, app).await?;
Ok(config)
let quest = load_quest_core(dir, &config, app).await?;
let state = fmt_err(quest.state_descriptor().await)?;
Ok((config, state))
}

#[tauri::command]
#[specta::specta]
async fn new_quest(dir: PathBuf, quest: String, app: AppHandle) -> Result<QuestConfig, String> {
async fn new_quest(
dir: PathBuf,
quest: String,
app: AppHandle,
) -> Result<(QuestConfig, StateDescriptor), String> {
let config = fmt_err(quest::load_config_from_remote("cognitive-engineering-lab", &quest).await)?;
let quest = load_quest_core(dir.join(quest), &config, app).await?;
fmt_err(quest.create_repo().await)?;
Ok(config)
let state = fmt_err(quest.state_descriptor().await)?;
Ok((config, state))
}

#[tauri::command]
Expand Down
Loading

0 comments on commit 2fd0c8c

Please sign in to comment.