mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 15:11:58 +01:00
tools: fix the F-Droid submit API calls
Use PUT for the repository file (it already exists on the fork), create the MR on the fork with target_project_id (the create endpoint ignores source_project_id), and reuse an open MR instead of deleting and recreating the branch. Drop the unused --branch/--title flags and the redundant workflow concurrency/defaults.
This commit is contained in:
+20
-13
@@ -5,8 +5,12 @@
|
||||
# nix develop --command nu tools/fdroid-submit.nu
|
||||
#
|
||||
# Reads a recipe from tools/fdroid/<appid>.yml, pushes it to a branch on the
|
||||
# fork and opens a merge request against fdroid/fdroiddata. Needs a GitLab
|
||||
# personal access token with the 'api' scope in GL_TOKEN.
|
||||
# fork and opens or updates the merge request against fdroid/fdroiddata. Needs
|
||||
# a GitLab personal access token with the 'api' scope in GL_TOKEN.
|
||||
#
|
||||
# The branch is created from the fork's master, which drifts from upstream. If
|
||||
# upstream has since edited the same recipe the MR conflicts and the fork must
|
||||
# be synced (GitLab's "Update fork") before running this again.
|
||||
|
||||
const FORK = "austinried/fdroiddata"
|
||||
const UPSTREAM = "fdroid/fdroiddata"
|
||||
@@ -17,8 +21,6 @@ def pct-encode [s: string] { $s | str replace -a "/" "%2F" }
|
||||
def main [
|
||||
recipe: path = "tools/fdroid/com.subtracks.yml"
|
||||
--api: string = "https://gitlab.com/api/v4"
|
||||
--branch: string = ""
|
||||
--title: string = ""
|
||||
--dry-run
|
||||
] {
|
||||
if not ($recipe | path exists) {
|
||||
@@ -26,8 +28,8 @@ def main [
|
||||
}
|
||||
|
||||
let appid = ($recipe | path basename | str replace -r '\.ya?ml$' '')
|
||||
let branch = (if ($branch | is-empty) { $"($appid)-recipe" } else { $branch })
|
||||
let title = (if ($title | is-empty) { $"($appid): update build recipe" } else { $title })
|
||||
let branch = $"($appid)-recipe"
|
||||
let title = $"($appid): update build recipe"
|
||||
let file_path = (pct-encode $"metadata/($appid).yml")
|
||||
let fork = (pct-encode $FORK)
|
||||
let upstream = (pct-encode $UPSTREAM)
|
||||
@@ -42,16 +44,21 @@ def main [
|
||||
error make { msg: "GL_TOKEN is unset; it needs a GitLab token with the 'api' scope" }
|
||||
}
|
||||
let headers = { "PRIVATE-TOKEN": $token }
|
||||
let fork_id = (http get $"($api)/projects/($fork)" --headers $headers | get id)
|
||||
let upstream_id = (http get $"($api)/projects/($upstream)" --headers $headers | get id)
|
||||
|
||||
try {
|
||||
http delete $"($api)/projects/($fork)/repository/branches/($branch)" --headers $headers | ignore
|
||||
} catch { }
|
||||
let branch_exists = (try { http get $"($api)/projects/($fork)/repository/branches/($branch)" --headers $headers } catch { null }) | is-not-empty
|
||||
if not $branch_exists {
|
||||
http post $"($api)/projects/($fork)/repository/branches" ({ branch: $branch, ref: $BASE_BRANCH } | to json) --headers $headers --content-type "application/json" | ignore
|
||||
}
|
||||
|
||||
http post $"($api)/projects/($fork)/repository/branches" ({ branch: $branch, ref: $BASE_BRANCH } | to json) --headers $headers --content-type "application/json" | ignore
|
||||
http put $"($api)/projects/($fork)/repository/files/($file_path)" ({ branch: $branch, content: (open --raw $recipe), commit_message: $title } | to json) --headers $headers --content-type "application/json" | ignore
|
||||
|
||||
http post $"($api)/projects/($fork)/repository/files/($file_path)" ({ branch: $branch, content: (open --raw $recipe), commit_message: $title } | to json) --headers $headers --content-type "application/json" | ignore
|
||||
let open = (http get $"($api)/projects/($fork)/merge_requests?state=opened&source_branch=($branch)&target_branch=($BASE_BRANCH)" --headers $headers)
|
||||
if ($open | is-not-empty) {
|
||||
print $"updated MR !($open.0.iid): ($open.0.web_url)"
|
||||
return
|
||||
}
|
||||
|
||||
let mr = (http post $"($api)/projects/($upstream)/merge_requests" ({ source_project_id: $fork_id, source_branch: $branch, target_branch: $BASE_BRANCH, title: $title, remove_source_branch: true } | to json) --headers $headers --content-type "application/json")
|
||||
let mr = (http post $"($api)/projects/($fork)/merge_requests" ({ source_branch: $branch, target_branch: $BASE_BRANCH, target_project_id: $upstream_id, title: $title, remove_source_branch: true } | to json) --headers $headers --content-type "application/json")
|
||||
print $"opened MR !($mr.iid): ($mr.web_url)"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user