Skip to content

Commit df24a4c

Browse files
Making job name a parameter, instead of having the pandas value hardcoded
1 parent 14e0417 commit df24a4c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/github.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ fn extract_run_id_from_detail_url(url: &str) -> Result<u64, PreviewerError> {
6060

6161
async fn run_id_from_commit(client: &Client,
6262
base_api_url: &str,
63-
commit_reference: &str) -> Result<u64,
64-
PreviewerError> {
63+
commit_reference: &str,
64+
job_name: &str) -> Result<u64,
65+
PreviewerError> {
6566
let url = format!("{base_api_url}commits/{commit_reference}/check-runs");
6667
let json_obj = fetch_json(client, &url).await?;
6768

6869
match json_obj["check_runs"]
6970
.as_array()
70-
.and_then(|jobs| jobs.iter().find(|job| job["name"] == "Doc Build and Upload")) {
71+
.and_then(|jobs| jobs.iter().find(|job| job["name"] == job_name)) {
7172
Some(job) => {
7273
if let Some(detail_url) = job["details_url"].as_str() {
7374
extract_run_id_from_detail_url(detail_url)
@@ -138,6 +139,7 @@ async fn download_artifact(client: &Client,
138139
pub async fn publish_artifact(client: &Client,
139140
base_api_url: &str,
140141
pull_request_number: u64,
142+
job_name: &str,
141143
target_dir: &Path,
142144
max_artifact_size: usize) -> Result<(),
143145
PreviewerError> {
@@ -151,7 +153,8 @@ pub async fn publish_artifact(client: &Client,
151153

152154
let run_id = run_id_from_commit(client,
153155
base_api_url,
154-
&last_commit).await?;
156+
&last_commit,
157+
job_name).await?;
155158
log::info!("[PR {}] Run id: {}", pull_request_number, run_id);
156159

157160
let artifact_url = artifact_url_from_run_id(client,

src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::path::Path;
2+
use serde_derive::Deserialize;
23
use actix_web::{post, App, HttpResponse, HttpServer, Responder,
34
web, rt, middleware::Logger};
45
use awc::Client;
@@ -10,17 +11,24 @@ mod cleanup;
1011
mod config;
1112
mod args;
1213

14+
#[derive(Deserialize)]
15+
struct PreviewParams {
16+
job: String,
17+
}
18+
1319
/// Handler of the HTTP server /preview/ endpoint.
1420
///
1521
/// This gets the parameters from the url and adds a job to the queue
1622
/// to be processed by the worker.
1723
#[post("/preview/{github_owner}/{github_repo}/{pull_request_number}/")]
1824
async fn preview_handler(params: web::Path<(String, String, u64)>,
25+
query_params: web::Query<PreviewParams>,
1926
client: web::Data<Client>,
2027
settings: web::Data<config::SettingsPerThread>) -> impl Responder {
2128
let github_owner = &params.0;
2229
let github_repo = &params.1;
2330
let pull_request_number = params.2;
31+
let job_name = &query_params.job;
2432

2533
if !settings.github_allowed_owners.is_empty()
2634
&& !settings.github_allowed_owners.contains(github_owner) {
@@ -51,6 +59,7 @@ async fn preview_handler(params: web::Path<(String, String, u64)>,
5159
match github::publish_artifact(&client,
5260
&base_api_url,
5361
pull_request_number,
62+
job_name,
5463
&target_dir,
5564
settings.max_artifact_size).await {
5665
Ok(_) => {

0 commit comments

Comments
 (0)