Skip to content

Commit de252f1

Browse files
xtexxMingcongBai
authored andcommitted
Revert "feat: support pipelines from fork PRs"
This reverts commit dc80447.
1 parent 51f2a52 commit de252f1

File tree

8 files changed

+51
-103
lines changed

8 files changed

+51
-103
lines changed

buildit-utils/src/github.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub async fn open_pr(
8989

9090
let _lock = ABBS_REPO_LOCK.lock().await;
9191

92-
update_abbs(&git_ref, &abbs_path, &git_ref, false).await?;
92+
update_abbs(&git_ref, &abbs_path, false).await?;
9393

9494
let abbs_path_clone = abbs_path.clone();
9595
let commits = task::spawn_blocking(move || get_commits(&abbs_path_clone))
@@ -332,7 +332,6 @@ fn get_commits(path: &Path) -> anyhow::Result<Vec<Commit>> {
332332
pub async fn update_abbs<P: AsRef<Path>>(
333333
git_ref: &str,
334334
abbs_path: P,
335-
local_branch: &str,
336335
skip_git_fetch: bool,
337336
) -> anyhow::Result<()> {
338337
info!("Running git checkout -b stable ...");
@@ -362,6 +361,27 @@ pub async fn update_abbs<P: AsRef<Path>>(
362361

363362
print_stdout_and_stderr(&output);
364363

364+
if skip_git_fetch {
365+
info!("Skippping git fetch ...")
366+
} else {
367+
info!("Running git fetch origin {git_ref} ...");
368+
369+
let output = process::Command::new("git")
370+
.arg("fetch")
371+
.arg("origin")
372+
.arg(git_ref)
373+
.current_dir(abbs_path)
374+
.output()
375+
.instrument(info_span!("git_fetch_origin"))
376+
.await?;
377+
378+
print_stdout_and_stderr(&output);
379+
380+
if !output.status.success() {
381+
bail!("Failed to fetch origin git-ref: {git_ref}");
382+
}
383+
}
384+
365385
info!("Running git reset origin/stable --hard ...");
366386

367387
let output = process::Command::new("git")
@@ -375,24 +395,24 @@ pub async fn update_abbs<P: AsRef<Path>>(
375395

376396
print_stdout_and_stderr(&output);
377397

378-
info!("Running git checkout -b {local_branch} ...");
398+
info!("Running git checkout -b {git_ref} ...");
379399

380400
let output = process::Command::new("git")
381401
.arg("checkout")
382402
.arg("-b")
383-
.arg(local_branch)
403+
.arg(git_ref)
384404
.current_dir(abbs_path)
385405
.output()
386406
.instrument(info_span!("git_checkout_branch"))
387407
.await?;
388408

389409
print_stdout_and_stderr(&output);
390410

391-
info!("Running git checkout {local_branch} ...");
411+
info!("Running git checkout {git_ref} ...");
392412

393413
let output = process::Command::new("git")
394414
.arg("checkout")
395-
.arg(local_branch)
415+
.arg(git_ref)
396416
.current_dir(abbs_path)
397417
.output()
398418
.instrument(info_span!("git_checkout_branch"))
@@ -401,28 +421,7 @@ pub async fn update_abbs<P: AsRef<Path>>(
401421
print_stdout_and_stderr(&output);
402422

403423
if !output.status.success() {
404-
bail!("Failed to checkout {local_branch}");
405-
}
406-
407-
if skip_git_fetch {
408-
info!("Skippping git fetch ...")
409-
} else {
410-
info!("Running git fetch origin {git_ref} ...");
411-
412-
let output = process::Command::new("git")
413-
.arg("fetch")
414-
.arg("origin")
415-
.arg(git_ref)
416-
.current_dir(abbs_path)
417-
.output()
418-
.instrument(info_span!("git_fetch_origin"))
419-
.await?;
420-
421-
print_stdout_and_stderr(&output);
422-
423-
if !output.status.success() {
424-
bail!("Failed to fetch origin git-ref: {git_ref}");
425-
}
424+
bail!("Failed to checkout {git_ref}");
426425
}
427426

428427
info!("Running git reset FETCH_HEAD --hard ...");

buildit-utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub async fn find_update_and_update_checksum(
8686
let _lock = ABBS_REPO_LOCK.lock().await;
8787

8888
// switch to stable branch
89-
update_abbs("stable", &abbs_path, "stable", false).await?;
89+
update_abbs("stable", &abbs_path, false).await?;
9090

9191
match manual_update {
9292
Some(version) => {

common/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ pub struct WorkerPollRequest {
1313
#[derive(Serialize, Deserialize, Debug)]
1414
pub struct WorkerPollResponse {
1515
pub job_id: i32,
16-
/// PR HEAD branch (for non-fork PRs only) or 'stable'.
17-
///
18-
/// Either github_pr or git_branch must be present.
19-
#[serde(default)]
20-
pub git_branch: Option<String>,
21-
#[serde(default)]
22-
pub github_pr: Option<u64>,
16+
pub git_branch: String,
2317
pub git_sha: String,
2418
pub packages: String,
2519
}

server/src/api.rs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use diesel::{
1818
connection::{AnsiTransactionManager, TransactionManager},
1919
};
2020
use serde::{Deserialize, Serialize};
21-
use std::{borrow::Cow, collections::BTreeMap};
21+
use std::collections::BTreeMap;
2222
use tracing::warn;
2323

2424
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
@@ -55,7 +55,7 @@ async fn create_check_run(crab: octocrab::Octocrab, arch: String, git_sha: Strin
5555
#[allow(clippy::too_many_arguments)]
5656
pub async fn pipeline_new(
5757
pool: DbPool,
58-
git_branch: Option<&str>,
58+
git_branch: &str,
5959
git_sha: Option<&str>,
6060
github_pr: Option<u64>,
6161
packages: &str,
@@ -97,27 +97,15 @@ pub async fn pipeline_new(
9797
}
9898

9999
// sanitize git_branch arg
100-
if let Some(git_branch) = git_branch
101-
&& !git_branch.chars().all(|ch| {
102-
ch.is_ascii_alphanumeric() || ch == '.' || ch == '-' || ch == '+' || ch == '_'
103-
})
100+
if !git_branch
101+
.chars()
102+
.all(|ch| ch.is_ascii_alphanumeric() || ch == '.' || ch == '-' || ch == '+' || ch == '_')
104103
{
105104
return Err(anyhow!("Invalid branch: {git_branch}"));
106105
}
107106

108-
let (git_ref, local_branch) = if let Some(git_branch) = git_branch {
109-
(Cow::Borrowed(git_branch), Cow::Borrowed(git_branch))
110-
} else if let Some(pr_number) = github_pr {
111-
(
112-
Cow::Owned(format!("refs/pull/{}/head", pr_number)),
113-
Cow::Owned(format!("pr{}", pr_number)),
114-
)
115-
} else {
116-
bail!("Either git_branch or github_pr must be set when creating new pipeline")
117-
};
118-
119107
let lock = ABBS_REPO_LOCK.lock().await;
120-
update_abbs(&local_branch, &ARGS.abbs_path, &git_ref, skip_git_fetch)
108+
update_abbs(git_branch, &ARGS.abbs_path, skip_git_fetch)
121109
.await
122110
.context("Failed to update ABBS tree")?;
123111

@@ -183,7 +171,7 @@ pub async fn pipeline_new(
183171
let new_pipeline = NewPipeline {
184172
packages: packages.to_string(),
185173
archs: archs.join(","),
186-
git_branch: local_branch.into_owned(),
174+
git_branch: git_branch.to_string(),
187175
git_sha: git_sha.clone(),
188176
creation_time: chrono::Utc::now(),
189177
source: source.to_string(),
@@ -286,7 +274,9 @@ pub async fn pipeline_new_pr(
286274
(pr.head.ref_field.as_str(), &pr.head.sha)
287275
};
288276

289-
let fork = pr.head.repo.as_ref().and_then(|x| x.fork).unwrap_or(false);
277+
if pr.head.repo.as_ref().and_then(|x| x.fork).unwrap_or(false) {
278+
return Err(anyhow!("Failed to create job: Pull request is a fork"));
279+
}
290280

291281
// find lines starting with #buildit
292282
let packages = get_packages_from_pr(&pr);
@@ -296,17 +286,9 @@ pub async fn pipeline_new_pr(
296286
archs.to_string()
297287
} else {
298288
let path = &ARGS.abbs_path;
299-
let (git_ref, local_branch) = if fork {
300-
(
301-
Cow::Owned(format!("refs/pull/{}/head", pr.number)),
302-
Cow::Owned(format!("pr{}", pr.number)),
303-
)
304-
} else {
305-
(Cow::Borrowed(git_branch), Cow::Borrowed(git_branch))
306-
};
307289

308290
let _lock = ABBS_REPO_LOCK.lock().await;
309-
update_abbs(&git_ref, &ARGS.abbs_path, &local_branch, false)
291+
update_abbs(git_branch, &ARGS.abbs_path, false)
310292
.await
311293
.context("Failed to update ABBS tree")?;
312294
// skip next git fetch in pipeline_new
@@ -320,7 +302,7 @@ pub async fn pipeline_new_pr(
320302

321303
pipeline_new(
322304
pool,
323-
if fork { None } else { Some(git_branch) },
305+
git_branch,
324306
Some(git_sha),
325307
Some(pr.number),
326308
&packages.join(","),

server/src/bot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ async fn pipeline_new_and_report(
167167
match wait_with_send_typing(
168168
pipeline_new(
169169
pool,
170-
Some(git_branch),
170+
git_branch,
171171
None,
172172
None,
173173
packages,

server/src/routes/pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub async fn pipeline_new(
3131
) -> Result<Json<PipelineNewResponse>, AnyhowError> {
3232
let (pipeline, _) = api::pipeline_new(
3333
pool,
34-
Some(&payload.git_branch),
34+
&payload.git_branch,
3535
None,
3636
None,
3737
&payload.packages,

server/src/routes/worker.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,21 +301,10 @@ pub async fn worker_poll(
301301
});
302302
}
303303

304-
// detect pipelines from fork repositories
305-
let gh_pr = pipeline.github_pr.map(|pr| pr as u64);
306-
let git_branch = if let Some(gh_pr) = gh_pr
307-
&& pipeline.git_branch == format!("pr{gh_pr}")
308-
{
309-
None
310-
} else {
311-
Some(pipeline.git_branch)
312-
};
313-
314304
// job allocated
315305
Ok(Json(Some(WorkerPollResponse {
316306
job_id: job.id,
317-
git_branch,
318-
github_pr: gh_pr,
307+
git_branch: pipeline.git_branch,
319308
git_sha: pipeline.git_sha,
320309
packages: job.packages,
321310
})))

worker/src/build.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use crate::{Args, get_memory_bytes};
2-
use anyhow::bail;
32
use chrono::Local;
43
use common::{JobOk, WorkerJobUpdateRequest, WorkerPollRequest, WorkerPollResponse};
54
use flume::Sender;
65
use futures_util::future::try_join3;
76
use log::{error, info, warn};
87
use std::{
9-
borrow::Cow,
108
path::Path,
119
process::{Output, Stdio},
1210
time::{Duration, Instant},
@@ -165,22 +163,8 @@ async fn build(
165163
let mut build_success = false;
166164
let mut logs = vec![];
167165

168-
let (git_ref, local_branch) = if let Some(branch) = &job.git_branch {
169-
(
170-
Cow::Borrowed(branch.as_str()),
171-
Cow::Borrowed(branch.as_str()),
172-
)
173-
} else if let Some(pr_num) = job.github_pr {
174-
(
175-
Cow::Owned(format!("refs/pull/{}/head", pr_num)),
176-
Cow::Owned(format!("pr{}", pr_num)),
177-
)
178-
} else {
179-
bail!("Job without either git_branch and github_pr")
180-
};
181-
182166
let mut output_path = args.ciel_path.clone();
183-
output_path.push(format!("OUTPUT-{}", local_branch));
167+
output_path.push(format!("OUTPUT-{}", job.git_branch));
184168

185169
// clear output directory
186170
if output_path.exists() {
@@ -193,7 +177,7 @@ async fn build(
193177
&[
194178
"fetch",
195179
"https://github.com/AOSC-Dev/aosc-os-abbs.git",
196-
&git_ref,
180+
&job.git_branch,
197181
],
198182
tree_path,
199183
&mut logs,
@@ -208,7 +192,7 @@ async fn build(
208192
// ensure branch exists
209193
get_output_logged(
210194
"git",
211-
&["checkout", "-b", &local_branch],
195+
&["checkout", "-b", &job.git_branch],
212196
tree_path,
213197
&mut logs,
214198
tx.clone(),
@@ -217,7 +201,7 @@ async fn build(
217201
// checkout to branch
218202
get_output_logged(
219203
"git",
220-
&["checkout", &local_branch],
204+
&["checkout", &job.git_branch],
221205
tree_path,
222206
&mut logs,
223207
tx.clone(),
@@ -310,12 +294,12 @@ async fn build(
310294
"-i",
311295
upload_ssh_key,
312296
"maintainers",
313-
&local_branch,
297+
&job.git_branch,
314298
];
315299
if !args.pushpkg_options.is_empty() {
316300
pushpkg_args.insert(0, &args.pushpkg_options);
317301
}
318-
if local_branch != "stable" {
302+
if &job.git_branch != "stable" {
319303
// allow force push if noarch and non stable
320304
pushpkg_args.insert(0, "--force-push-noarch-package");
321305
}
@@ -335,7 +319,7 @@ async fn build(
335319
let file_name = format!(
336320
"{}-{}-{}-{}-{}.txt",
337321
job.job_id,
338-
local_branch,
322+
job.git_branch,
339323
args.arch,
340324
gethostname::gethostname().to_string_lossy(),
341325
Local::now().format("%Y-%m-%d-%H:%M:%S")

0 commit comments

Comments
 (0)