@@ -18,7 +18,7 @@ use diesel::{
18
18
connection:: { AnsiTransactionManager , TransactionManager } ,
19
19
} ;
20
20
use serde:: { Deserialize , Serialize } ;
21
- use std:: { borrow :: Cow , collections:: BTreeMap } ;
21
+ use std:: collections:: BTreeMap ;
22
22
use tracing:: warn;
23
23
24
24
#[ derive( Debug , Copy , Clone , Serialize , Deserialize ) ]
@@ -55,7 +55,7 @@ async fn create_check_run(crab: octocrab::Octocrab, arch: String, git_sha: Strin
55
55
#[ allow( clippy:: too_many_arguments) ]
56
56
pub async fn pipeline_new (
57
57
pool : DbPool ,
58
- git_branch : Option < & str > ,
58
+ git_branch : & str ,
59
59
git_sha : Option < & str > ,
60
60
github_pr : Option < u64 > ,
61
61
packages : & str ,
@@ -97,27 +97,15 @@ pub async fn pipeline_new(
97
97
}
98
98
99
99
// 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 == '_' )
104
103
{
105
104
return Err ( anyhow ! ( "Invalid branch: {git_branch}" ) ) ;
106
105
}
107
106
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
-
119
107
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)
121
109
. await
122
110
. context ( "Failed to update ABBS tree" ) ?;
123
111
@@ -183,7 +171,7 @@ pub async fn pipeline_new(
183
171
let new_pipeline = NewPipeline {
184
172
packages : packages. to_string ( ) ,
185
173
archs : archs. join ( "," ) ,
186
- git_branch : local_branch . into_owned ( ) ,
174
+ git_branch : git_branch . to_string ( ) ,
187
175
git_sha : git_sha. clone ( ) ,
188
176
creation_time : chrono:: Utc :: now ( ) ,
189
177
source : source. to_string ( ) ,
@@ -286,7 +274,9 @@ pub async fn pipeline_new_pr(
286
274
( pr. head . ref_field . as_str ( ) , & pr. head . sha )
287
275
} ;
288
276
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
+ }
290
280
291
281
// find lines starting with #buildit
292
282
let packages = get_packages_from_pr ( & pr) ;
@@ -296,17 +286,9 @@ pub async fn pipeline_new_pr(
296
286
archs. to_string ( )
297
287
} else {
298
288
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
- } ;
307
289
308
290
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 )
310
292
. await
311
293
. context ( "Failed to update ABBS tree" ) ?;
312
294
// skip next git fetch in pipeline_new
@@ -320,7 +302,7 @@ pub async fn pipeline_new_pr(
320
302
321
303
pipeline_new (
322
304
pool,
323
- if fork { None } else { Some ( git_branch) } ,
305
+ git_branch,
324
306
Some ( git_sha) ,
325
307
Some ( pr. number ) ,
326
308
& packages. join ( "," ) ,
0 commit comments