13 |
14 |
15 |
16 | Kamino is a dotnet tool to clone an organisation from GitLab
17 |
18 | ## Getting Started
19 |
20 | Install kamino as a global dotnet tool
21 |
22 | ```bash
23 | dotnet tool install kamino -g
24 | ```
25 |
26 | or update it with
27 |
28 | ```bash
29 | dotnet tool update kamino
30 | ```
31 |
32 | or as a dotnet local tool
33 |
34 | ```bash
35 | dotnet new tool-manifest
36 | dotnet tool install kamino
37 | ```
38 |
39 | ## Quickstart
40 |
41 | Run kamino:
42 |
43 | ```bash
44 | kamino -b my-gitlab.com -o C:\Development\Git\ -g 42 -t xT0K3Nx4CC355x
45 | ```
46 |
47 | ## Usage
48 |
49 | You can also get this with `dotnet kamino help`.
50 |
51 | ```sh
52 | Kamino GitLab Organisation Cloner
53 | ----------------------------------------------------------------
54 | EXAMPLE: kamino -b my-gitlab.com -o C:\Development\Git\ -g 42 -t xT0K3Nx4CC355x
55 |
56 | USAGE: kamino [--help] --baseaddress --group --output --token [--include ]
57 | [--exclude ] [--printonly]
58 |
59 | OPTIONS:
60 |
61 | --baseaddress, -b
62 | specify your gitlab instance base address
63 | --group, -g specify the group name or id to clone recursively
64 | --output, -o specify the output folder to clone to
65 | --token, -t specify your access token
66 | --include, -i
67 | exclude all repositories but include matching
68 | --exclude, -e
69 | include all repositories but exclude matching
70 | --printonly, -p print theorical path without actually cloning
71 | --help display this list of options.
72 | ```
73 |
74 | ## Contributing
75 |
76 | Help and feedback is always welcome and pull requests get accepted.
77 |
78 | Here is the contribution flow ([more information on datascholl.io](https://www.dataschool.io/how-to-contribute-on-github/)):
79 |
80 | * Open or answer an issue to discuss the changes
81 | * Fork the project after the change has been formally approved
82 | * Create a [feature branch](https://www.martinfowler.com/bliki/FeatureBranch.html)
83 | * Follow the code convention by examining existing code (mostly Microsoft's guidelines)
84 | * Edit the code with the changes
85 | * Add/modify unit tests as required
86 | * Submit your PR against the main branch
87 |
88 | PRs can only be approved and merged when all checks succeed (builds on Windows, MacOs and Linux)
89 |
90 | ## Alternatives
91 |
92 | * [GitLabber](https://github.com/ezbz/gitlabber) - clones or pulls entire groups tree from gitlab
93 | * [Ghorg](https://github.com/gabrie30/ghorg) - clone an entire org/users repositories into one directory
94 | * [Related SO Q&A](https://stackoverflow.com/q/29099456/1248177) - How to clone all projects of a group at once in GitLab?
95 |
96 | ## License
97 |
98 | * [Marble icon](https://thenounproject.com/term/marble/1056965/) is licensed as Creative Commons CCBY by [Monjin Friends](https://thenounproject.com/monjin.friends/) from the [Noun Project](https://thenounproject.com).
99 | * [MIT](https://github.com/d-edge/kamino/blob/main/License)
100 |
--------------------------------------------------------------------------------
/kamino/Program.fs:
--------------------------------------------------------------------------------
1 | open System
2 | open Argu
3 | open LibGit2Sharp
4 | open System.Text.Json.Serialization
5 |
6 | // # doc: https://docs.gitlab.com/ee/api/groups.html#list-a-groups-s-subgroups
7 |
8 | type Project =
9 | { []
10 | Path: string
11 | []
12 | Url: string }
13 |
14 | let clone url path printMode =
15 | if printMode then
16 | printfn "%s" path
17 | else
18 | Repository.Clone(url, path) |> ignore
19 | printfn "%s" path
20 |
21 | let inline (>) path1 path2 = IO.Path.Combine(path1, path2)
22 |
23 | let download token (url: string) =
24 | let client = new Net.WebClient()
25 | client.Headers.Set("PRIVATE-TOKEN", token)
26 | client.DownloadString url
27 |
28 | let deserialize (json: string) =
29 | Text.Json.JsonSerializer.Deserialize> json
30 |
31 | // ?private_token={token} ???
32 | let inline buildUrl url group =
33 | $"https://{url}/api/v4/groups/{group}/projects?include_subgroups=true&simple=true&per_page=100&page=1"
34 |
35 | let insertToken baseAddress token (url: string) =
36 | url.Replace(baseAddress, $"oauth2:{token}@{baseAddress}")
37 |
38 | let stringToSpan (s: string) =
39 | System.ReadOnlySpan(s.ToCharArray())
40 |
41 | // https://stackoverflow.com/q/30299671/1248177
42 | let matchWildcard pattern text =
43 | IO.Enumeration.FileSystemName.MatchesSimpleExpression(stringToSpan pattern, stringToSpan text)
44 |
45 | let patternPredicate (includePattern: string Option) (excludePattern: string Option) path =
46 | (includePattern.IsNone || matchWildcard includePattern.Value path) &&
47 | (excludePattern.IsNone || not (matchWildcard excludePattern.Value path))
48 |
49 | let filterByPattern (includePattern: string Option) (excludePattern: string Option) (paths: Project seq) :Project seq =
50 | Seq.filter (fun { Path = path } -> patternPredicate includePattern excludePattern path) paths
51 |
52 | let cloneOrganisation baseAddress group path token printMode includePattern excludePattern =
53 | let clone project =
54 | let url =
55 | insertToken baseAddress token project.Url
56 |
57 | let target = path > project.Path
58 | clone url target printMode
59 |
60 | if printMode then
61 | printfn "%s" "PrintMode: printonly"
62 | else
63 | IO.Directory.CreateDirectory path |> ignore
64 |
65 | buildUrl baseAddress group
66 | |> download token
67 | |> deserialize
68 | |> filterByPattern includePattern excludePattern
69 | |> Seq.iter clone
70 |
71 | type Cmd =
72 | | [] BaseAddress of string
73 | | [] Group of string
74 | | [] Output of string
75 | | [] Token of string
76 | | [] Include of string
77 | | [] Exclude of string
78 | | [] PrintOnly
79 |
80 | interface Argu.IArgParserTemplate with
81 | member this.Usage =
82 | match this with
83 | | BaseAddress _ -> "specify your gitlab instance base address"
84 | | Group _ -> "specify the group name or id to clone recursively"
85 | | Output _ -> "specify the output folder to clone to"
86 | | Token _ -> "specify your access token"
87 | | Include _ -> "exclude all repositories but include matching"
88 | | Exclude _ -> "include all repositories but exclude matching"
89 | | PrintOnly -> "print theorical path without actually cloning"
90 |
91 | let help = """Kamino GitLab Organisation Cloner
92 | ----------------------------------------------------------------
93 | EXAMPLE: kamino -b my-gitlab.com -o C:\Development\Git\ -g 42 -t xT0K3Nx4CC355x
94 | """
95 |
96 | []
97 | let main argv =
98 | let equalsDotNet name =
99 | String.Equals(name, "dotnet", StringComparison.OrdinalIgnoreCase)
100 |
101 | let processName =
102 | let isDotNet =
103 | Diagnostics
104 | .Process
105 | .GetCurrentProcess()
106 | .MainModule
107 | .FileName
108 | |> IO.Path.GetFileNameWithoutExtension
109 | |> equalsDotNet
110 |
111 | if isDotNet then
112 | "dotnet kamino"
113 | else
114 | "kamino"
115 |
116 | let parser =
117 | ArgumentParser(programName = processName)
118 |
119 | try
120 | let cmd = parser.ParseCommandLine(argv)
121 |
122 | let baseAddress = cmd.GetResult BaseAddress
123 | let group = cmd.GetResult Group
124 | let output = cmd.GetResult Output
125 | let token = cmd.GetResult Token
126 | let includePattern = cmd.TryGetResult Include
127 | let excludePattern = cmd.TryGetResult Exclude
128 | let printMode = cmd.Contains PrintOnly
129 |
130 | cloneOrganisation baseAddress group output token printMode includePattern excludePattern
131 | 0
132 | with :? Argu.ArguParseException ->
133 | printfn $"%s{help}"
134 | printfn $"%s{parser.PrintUsage()}"
135 | 1
136 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | softwarecraft@d-edge.com.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120 |
121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct
122 | enforcement ladder](https://github.com/mozilla/diversity).
123 |
124 | [homepage]: https://www.contributor-covenant.org
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | https://www.contributor-covenant.org/faq. Translations are available at
128 | https://www.contributor-covenant.org/translations.
129 |
--------------------------------------------------------------------------------