Skip to content

Commit

Permalink
Merge pull request #95 from Taywee/main
Browse files Browse the repository at this point in the history
fix action.nu for self-hosted forges
  • Loading branch information
fdncred authored Dec 25, 2024
2 parents 8f5c130 + 6d2e787 commit fbaf818
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
26 changes: 18 additions & 8 deletions action.nu
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,21 @@ export module plugin-list {
# converts repository url into raw download link for Cargo.toml
def "get-raw-toml-address" [
url: string, # github repository url (e.g. https://github.com/FMotalleb/nu_plugin_port_scan)
branch: string # branch name (e.g. main)
branch: string, # branch name (e.g. main)
software?: string
]: nothing -> record {
let url: record = ($url | url parse)

# Unspecified forge software is determined from the host.
let software = match $url.host {
'github.com' => 'github',
'gitlab.com' => 'gitlab',
'codeberg.org' => 'forgejo',
_ => $software
}
use utils "str explode"
match $url.host {
'github.com' => {
match $software {
'github' => {
if ( ($url.path | str explode '/' --trim-end | length) > 3 ) {
return ($url
| upsert host raw.githubusercontent.com
Expand All @@ -102,7 +111,7 @@ export module plugin-list {
| append Cargo.toml
| str join '/'))
},
'gitlab.com' => {
'gitlab' => {
return ($url
| upsert path ($url.path
| str explode '/' --trim-end
Expand All @@ -112,7 +121,7 @@ export module plugin-list {
| append Cargo.toml
| str join '/'))
},
'codeberg.org' => {
'forgejo' => {
return ($url
| update path {
split row "/"
Expand All @@ -137,10 +146,11 @@ export module plugin-list {

# download toml file from repository
def "get-toml" [
branch: string # branch name (e.g. main)
branch: string, # branch name (e.g. main)
software?: string
]: string -> record {
let git_repo = ($in | str replace --regex ".git$" "") # github repository url (e.g. https://github.com/FMotalleb/nu_plugin_port_scan)
let toml_file_address: string = (get-raw-toml-address $git_repo $branch | url join)
let toml_file_address: string = (get-raw-toml-address $git_repo $branch $software | url join)
try {
return (http get --raw $toml_file_address | from toml)
} catch {
Expand Down Expand Up @@ -244,7 +254,7 @@ export module plugin-list {
let item = $in
match $item.language {
"rust" => {
return ($item.repository.url | get-toml $item.repository.branch| map-toml-to-entry $item.repository.url)
return ($item.repository.url | get-toml $item.repository.branch ($item | get -i $.repository.software) | map-toml-to-entry $item.repository.url)
}
_ => {
return {}
Expand Down
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ plugins:
repository:
url: https://forge.axfive.net/Taylor/nu-plugin-bexpand
branch: main
software: forgejo
- name: nu_plugin_highlight
language: rust
repository:
Expand Down

0 comments on commit fbaf818

Please sign in to comment.