Skip to content

Commit c91c1e0

Browse files
committed
✨ Importers
1 parent 0f18a37 commit c91c1e0

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ cmd/ortfodb/ortfodb
3636
dist/
3737
.env
3838
packages/php/vendor
39+
cmd/cmd

importers/cloud.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Cloud services importer
2+
3+
description: Supports importing from various cloud services, using rclone. See https://rclone.org/ for more information.
4+
5+
requires: [rclone]
6+
7+
data:
8+
# Name of the rclone remote to use
9+
remote:
10+
11+
# Path to the directory to import from
12+
folder:
13+
14+
list:
15+
- log: [Listing, blue, "files in remote {{ .Data.remote }} at {{ .Data.folder }}"]
16+
- run: rclone lsjson --dirs-only {{ .Data.remote }}:{{ .Data.folder }} | jq -r '.[].Path' > output
17+
18+
import:
19+
- log: [Importing, blue, "{{ .ID }} from {{ .Data.remote }}:{{ .Data.folder }}/{{ .ID }}"]
20+
- run: rclone copy {{ .Data.remote }}:{{ .Data.folder }}/{{ .ID }} . --progress --create-empty-src-dirs

importers/github.yaml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,36 @@ data:
1111
# Topic to filter repositories by
1212
topic: uses-ortfo
1313

14+
# List of additional owner/repo pairs to import. the repo part must be different from any repo names that are already imported with username/ and the topic.
15+
additional: []
16+
1417
list:
1518
- log: [Listing, blue, "repositories for github user {{ .Data.username }}"]
1619
- run: gh repo list --source --json description,name {{ .Data.username }} --topic {{ .Data.topic }} --jq '.[]|.name' > output
20+
- log: [Listing, blue, "additional repositories to import"]
21+
- run: >
22+
{{ range $i, $v := .Data.additional }}
23+
echo {{ $v | replaceMatching "^.+/" "" }} >> output
24+
{{ end }}
1725
1826
import:
1927
- log:
20-
[
21-
Importing,
22-
blue,
23-
"{{ .ID }} from https://github.com/{{ .Data.username }}/{{ .ID }}",
24-
]
25-
- run: gh repo clone {{ .Data.username }}/{{ .ID }} . -- --depth 1
28+
- Importing
29+
- blue
30+
- >
31+
{{ .ID }} from https://github.com/
32+
{{ if .Data.additional | hasMatch ( cat ".+/" .ID ) }}
33+
{{ .Data.additional | findMatch (cat ".+/" .ID) }}
34+
{{ else }}
35+
{{ .Data.username }}/{{ .ID }}
36+
{{ end}}
37+
38+
39+
- run: >
40+
gh repo clone
41+
{{ if .Data.additional | hasMatch (cat ".+/" .ID) }}
42+
{{ .Data.additional | findMatch (cat ".+/" .ID) }}
43+
{{ else }}
44+
{{ .Data.username }}/{{ .ID }}
45+
{{ end }}
46+
. -- --depth 1

plugins_custom.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"path/filepath"
9+
"regexp"
910
"runtime"
1011
"strings"
1112
"text/template"
@@ -103,7 +104,6 @@ func (e *CustomPlugin) runCommands(ctx *RunContext, verbose bool, cwd string, co
103104

104105
if filepath.IsAbs(cwd) {
105106
proc.Dir = filepath.Clean(cwd)
106-
// } else if cwd == "." {
107107
} else {
108108
proc.Dir = filepath.Clean(filepath.Join(filepath.Dir(ctx.Config.source), cwd))
109109
}
@@ -200,6 +200,28 @@ var funcmap = template.FuncMap{
200200
"escape": func(data string) string {
201201
return shellescape.Quote(data)
202202
},
203+
"hasMatch": func(pattern string, data []string) bool {
204+
pat := regexp.MustCompile(pattern)
205+
for _, item := range data {
206+
if pat.MatchString(item) {
207+
return true
208+
}
209+
}
210+
return false
211+
},
212+
"findMatch": func(pattern string, data []string) string {
213+
pat := regexp.MustCompile(pattern)
214+
for _, item := range data {
215+
if pat.MatchString(item) {
216+
return item
217+
}
218+
}
219+
return ""
220+
},
221+
"replaceMatching": func(pattern, replacement string, data string) string {
222+
pat := regexp.MustCompile(pattern)
223+
return pat.ReplaceAllString(data, replacement)
224+
},
203225
}
204226

205227
func (e *CustomPlugin) renderCommandParts(ctx *RunContext, commands []string, additionalData map[string]any, recursive bool) ([]string, error) {

0 commit comments

Comments
 (0)