1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 07:07:46 +00:00

refactor: (#418)

* refactor:  move in one commit

Eveything in modules should probably be changed to `exported` defs.
The idea is to move everything first to keep proper history.

* refactor: 📝 add modules readme (wip)

* refactor:  small move

* refactor: 📝 changed nestring, updated modules readme

* refactor: 📝 to document or not to document

* fix: 🐛 themes

replaced the template to use `main` and regenerated them
from lemnos themes.

* Revert "fix: 🐛 themes"

This reverts commit 4918d3633c8d2d81950a0ed0cfd9eb84241bc886.

* refactor:  introduce sourced

- Created a source `root` in which sourcable demos are stored.
  Some might get converted to modules later on.
- Moved some files to bin too.

* fix: 🐛 fehbg.nu

* fix: 🐛 modules/after.nu

* moved some other stuff around

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
Mel Massadian 2023-04-26 00:56:25 +02:00 committed by GitHub
parent 382696cd21
commit c47ccd42b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
128 changed files with 185 additions and 12 deletions

38
sourced/gitlab/gitlab.nu Normal file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env nu
let page_size = 100
let projects = $"($base_url)/api/v4/projects/"
def call-gitlab [
...args: string
--query: string
] {
fetch -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
|hash base64 --decode
|lines
|find $phrase
|if ($in|length) > 0 {
echo $"($file) in ($repo.name) repo contains ($phrase) phrase"
}
}
}
}