Skip to content

Commit

Permalink
Add EOL arguments to republish
Browse files Browse the repository at this point in the history
This allows anyone with a republish token to EOL apps through the API.
  • Loading branch information
jameswestman authored and barthalion committed Oct 13, 2023
1 parent 6e1b8a1 commit 30759a9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ pub struct RepublishPathParams {
#[derive(Debug, Serialize, Deserialize)]
pub struct RepublishArgs {
app: String,
endoflife: Option<String>,
endoflife_rebase: Option<String>,
}

pub fn republish(
Expand All @@ -847,7 +849,12 @@ async fn republish_async(
req.has_token_repo(&params.repo)?;

let job = db
.start_republish_job(params.repo.clone(), args.app.clone())
.start_republish_job(
params.repo.clone(),
args.app.clone(),
args.endoflife.clone(),
args.endoflife_rebase.clone(),
)
.await?;
job_queue.do_send(ProcessJobs(Some(params.repo.clone())));

Expand Down
15 changes: 13 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,25 @@ impl Db {
.await
}

pub async fn start_republish_job(&self, repo: String, app: String) -> Result<Job, ApiError> {
pub async fn start_republish_job(
&self,
repo: String,
app: String,
endoflife: Option<String>,
endoflife_rebase: Option<String>,
) -> Result<Job, ApiError> {
self.run_in_transaction(move |conn| {
let job = diesel::insert_into(schema::jobs::table)
.values(NewJob {
kind: JobKind::Republish.to_db(),
start_after: None,
repo: Some(repo.clone()),
contents: json!(RepublishJob { app }).to_string(),
contents: json!(RepublishJob {
app,
endoflife,
endoflife_rebase
})
.to_string(),
})
.get_result::<Job>(conn)?;

Expand Down
14 changes: 14 additions & 0 deletions src/jobs/republish_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub struct RepublishJobInstance {
pub job_id: i32,
pub app_id: String,
pub repo: String,
pub endoflife: Option<String>,
pub endoflife_rebase: Option<String>,
}

impl RepublishJobInstance {
Expand All @@ -41,6 +43,8 @@ impl RepublishJobInstance {
job_id: job.id,
repo,
app_id: publish_job.app,
endoflife: publish_job.endoflife,
endoflife_rebase: publish_job.endoflife_rebase,
})
} else {
InvalidJobInstance::new(job, JobError::new("Can't parse republish job"))
Expand Down Expand Up @@ -147,6 +151,16 @@ impl JobInstance for RepublishJobInstance {
src_repo_arg.push(tmp_repo_dir.path());
cmd.arg(&src_repo_arg).arg(&repoconfig.path);

if let Some(endoflife) = &self.endoflife {
cmd.arg(format!("--end-of-life={endoflife}"));
};
if let Some(endoflife_rebase) = &self.endoflife_rebase {
cmd.arg(format!(
"--end-of-life-rebase={}={}",
self.app_id, endoflife_rebase
));
}

job_log_and_info!(
self.job_id,
conn,
Expand Down
2 changes: 2 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ pub struct PublishJob {
#[derive(Serialize, Deserialize, Debug)]
pub struct RepublishJob {
pub app: String,
pub endoflife: Option<String>,
pub endoflife_rebase: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down

0 comments on commit 30759a9

Please sign in to comment.