1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00
nu_scripts/sourced/gitlab/gitlab.nu
Auca Coyan bc6273d971
🐛 fix a couple of parser errors (#782)
This is some legwork to the CI
- [x] fix one `get-row.nu` before 0.60, just because it was easy
- [x] `modules/formats/to-ini.nu`
- [x] `modules/git/git-v2.nu`
- [x] `modules/git/git.nu`
- [x] `modules/log/log.nu`
- [x] `modules/weather/weatherdark.nu`
- [x] `sourced/api_wrappers/worlframalpha.nu`
- [x] `sourced/cool-oneliners/pwd-short.nu`
- [x] `sourced/github/branch-protections/branch-protections.nu`
- [x] `sourced/gitlab/gitlab.nu`
- [x] `sourced/misc/nu_defs.nu`
- [x] `sourced/update-path.nu`
- [x] `sourced/webscraping/shell_starts.nu`
I moved some auto-generated commands:
- [x] `ack` 
- [x] `as`
- [x] `curl`
- [x] `fsarprc`
- [x] `fsarpri`
- [x] `godoc`
- [x] `mysql` 
- [x] and `xgettext` 
to custom, so we keep the modifications.
I had to comment some of the flags because the parser is not able to
parse some flags. Those are explained in comments
2024-03-10 14:05:01 -05:00

39 lines
No EOL
1.3 KiB
Text

#!/usr/bin/env nu
let base_url = ""
let page_size = 100
let projects = $"($base_url)/api/v4/projects/"
def call-gitlab [
...args: string
--query: string
] {
http get -H [Authorization $"Bearer ($env.GITLAB_TOKEN)"] $"($projects)($args|str join)?($query)"
}
# Search files on your GitLab server
def main [
--base_url: string # base url of your GitLab instance
--file: string # file (or path to file if in a subfolder) you want to scan
--phrase: string # phrase you want to search for
--branch: string # branch to scan
] {
# /projects endpoint can return up to $page_size items which is why we need multiple calls to retrieve full list
let num_of_pages = ((call-gitlab --query 'page=1&per_page=1&order_by=id&simple=true'|get id.0|into int) / $page_size|math round)
seq 1 $num_of_pages|par-each {|page|
call-gitlab --query $"page=($page)&per_page=($page_size)"|select name id
}
|flatten
|par-each {|repo|
let payload = (call-gitlab $repo.id '/repository/files/' $file --query $"ref=($branch)")
if ($payload|columns|find message|is-empty) {
$payload
|get content
|decode base64
|lines
|find $phrase
|if ($in|length) > 0 {
echo $"($file) in ($repo.name) repo contains ($phrase) phrase"
}
}
}
}