Skip to content

Commit

Permalink
Add support for arbitrary quests
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Sep 19, 2024
1 parent c31ae94 commit e016b10
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
16 changes: 15 additions & 1 deletion js/packages/repo-quest/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,22 @@ let NewQuest = () => {
<option disabled={true} value="">
Choose a quest
</option>
<option value="rqst-async">rqst-async</option>
<option value="cognitive-engineering-lab/rqst-async">
cognitive-engineering-lab/rqst-async
</option>
</select>

<span className="separator">or</span>

<input
type="text"
placeholder="Enter a GitHub repo"
onChange={e => {
if (e.target.checkValidity()) setQuest(e.target.value);
else setQuest(undefined);
}}
pattern="[^\/]+\/.+"
/>
</td>
</tr>
<tr>
Expand Down
38 changes: 24 additions & 14 deletions js/packages/repo-quest/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ code, pre {
border-radius: 8px;
padding: 0.5rem 1rem;
margin: 2rem 0;

> div {
margin-bottom: 1rem;
}

.action {
font-weight: bold;
}
Expand Down Expand Up @@ -73,7 +73,7 @@ h1 {
}

.help {
display: inline-block;
display: inline-block;
border: 1px solid #ccc;
background: #fafafa;
padding: 3px 5px;
Expand Down Expand Up @@ -123,7 +123,7 @@ h1 {
100% {
transform: rotate(360deg);
}
}
}

.gh-links a:not(:first-child) {
margin-left: 0.5rem;
Expand All @@ -138,9 +138,9 @@ button, input[type=submit] {
appearance: none;
background: #eee;
border: 1px solid #aaa;
border-radius: 4px;
border-radius: 4px;
padding: 3px 5px;

&:not([disabled]) {
cursor: pointer;

Expand All @@ -157,31 +157,41 @@ button, input[type=submit] {

.controls {
display: flex;
gap: 1rem;
gap: 1rem;
}

.new-quest {
display: flex;
flex-direction: column;
gap: 1rem;
gap: 1rem;

table {
width: max-content;

td {
padding-bottom: 0.5rem;
}

td:first-child {
padding-right: 1rem;
}
&:first-child {
padding-right: 1rem;
}

input[type=text] {
border: 1px solid #ccc;
font-size: 80%;
width: 300px;

&:invalid {
box-shadow: 0 0 4px red;
}
}
}
}
}

.columns {
display: flex;
justify-content: space-between;
gap: 2rem;
gap: 2rem;
}

.meta {
Expand Down Expand Up @@ -212,7 +222,7 @@ button, input[type=submit] {
}

dialog {
z-index: 1000;
z-index: 1000;
max-width: 400px;
box-shadow: 4px 4px 8px #aaa;

Expand Down
3 changes: 2 additions & 1 deletion rs/crates/repo-quest/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ impl GithubRepo {
.owner(&self.user)
.private(true)
.send()
.await?;
.await
.with_context(|| format!("Failed to clone template repo {}/{}", base.user, base.name))?;

// There is some unknown delay between creating a repo from a template and its contents being added.
// We have to wait until that happens.
Expand Down
7 changes: 5 additions & 2 deletions rs/crates/repo-quest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ async fn new_quest(
quest: String,
app: AppHandle,
) -> Result<(QuestConfig, StateDescriptor), String> {
let config = fmt_err(QuestConfig::load_from_remote("cognitive-engineering-lab", &quest).await)?;
let quest = load_quest_core(dir.join(quest), &config, app).await?;
let (owner, repo) = quest
.split_once("/")
.ok_or_else(|| format!("Invalid quest name: {quest}"))?;
let config = fmt_err(QuestConfig::load_from_remote(owner, repo).await)?;
let quest = load_quest_core(dir.join(repo), &config, app).await?;
fmt_err(quest.create_repo().await)?;
let state = fmt_err(quest.state_descriptor().await)?;
Ok((config, state))
Expand Down
9 changes: 6 additions & 3 deletions rs/crates/repo-quest/src/quest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ impl QuestConfig {
async fn load_core<'a, Fut: Future<Output = Result<String>> + 'a>(
read: impl Fn(&'a str) -> Fut,
) -> Result<Self> {
let config_str = read("rqst.toml").await?;
let config_str = read("rqst.toml")
.await
.context("Quest is malformed, missing rqst.toml")?;
let mut config = toml::de::from_str::<QuestConfig>(&config_str)?;
let final_str_res = read("final.toml").await;
if let Ok(final_str) = final_str_res {
Expand All @@ -68,7 +70,7 @@ impl QuestConfig {
.arg(&arg)
.current_dir(dir)
.output()
.context("git failed")?;
.context("`git show` failed")?;
ensure!(
output.status.success(),
"`git show {arg}` exited with non-zero status code"
Expand All @@ -87,7 +89,8 @@ impl QuestConfig {
.path(path)
.r#ref("meta")
.send()
.await?;
.await
.context("Quest is malformed, missing the meta branch")?;
Ok(items.items[0].decoded_content().expect("Missing content"))
})
.await
Expand Down

0 comments on commit e016b10

Please sign in to comment.