Skip to content

Commit 22eb576

Browse files
authored
Merge pull request #339 from Kobzol/verifier-generalize
Allow using survey verifier for more survey kinds
2 parents e477612 + b98b591 commit 22eb576

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

verifier/src/api.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ impl Client {
2828
.inner
2929
.get("https://api.surveyhero.com/v1/surveys")
3030
.basic_auth(&self.username, Some(&self.password))
31-
.send()?
32-
.error_for_status()?;
31+
.send()?;
32+
let status = response.status();
33+
if !status.is_success() {
34+
let text = response.text()?;
35+
return Err(anyhow::anyhow!(
36+
"HTTP error status {status} while fetching surveys:\n{text}"
37+
));
38+
}
3339
let surveys: Surveys = response.json()?;
3440
Ok(surveys.surveys)
3541
}

verifier/src/main.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@ fn main() -> anyhow::Result<()> {
1515
let args = Args::parse();
1616
let online_data = fetch_surveyhero_data(args.cmd.shared())?;
1717

18-
let base_path = PathBuf::from(format!(
19-
"../surveys/{}-annual-survey",
20-
args.cmd.shared().year
21-
));
22-
let mut pairs = vec![(base_path.join("questions.md"), online_data.main)];
23-
for (language, questions) in online_data.secondary_languages {
24-
pairs.push((
25-
base_path
26-
.join("translations")
27-
.join(language)
28-
.with_extension("md"),
29-
questions,
30-
));
31-
}
18+
let base_path = PathBuf::from(format!("../surveys/{}", args.cmd.shared().path));
19+
let pairs = if base_path.is_dir() {
20+
let mut pairs = vec![(base_path.join("questions.md"), online_data.main)];
21+
for (language, questions) in online_data.secondary_languages {
22+
pairs.push((
23+
base_path
24+
.join("translations")
25+
.join(language)
26+
.with_extension("md"),
27+
questions,
28+
));
29+
}
30+
pairs
31+
} else {
32+
vec![(base_path, online_data.main)]
33+
};
3234

3335
match args.cmd {
3436
VerifierCmd::Check { .. } => {
@@ -318,9 +320,9 @@ struct SharedArgs {
318320
/// Name of the survey.
319321
#[clap(long)]
320322
survey_name: String,
321-
/// Year of the survey. Corresponds to `surveys/<year>-annual-survey` directory.
323+
/// Survey path. Corresponds to a Markdown file or a directory at `surveys/<path>`.
322324
#[clap(long)]
323-
year: u32,
325+
path: String,
324326
}
325327

326328
#[derive(clap::Parser, Clone)]

0 commit comments

Comments
 (0)