Skip to content

Commit b686eda

Browse files
committed
Initial commit
0 parents  commit b686eda

30 files changed

+1339
-0
lines changed

.editorconfig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# EditorConfig coding styles definitions. For more information about the
2+
# properties used in this file, please see the EditorConfig documentation:
3+
# http://editorconfig.org/
4+
5+
# indicate this is the root of the project
6+
root = true
7+
8+
[*]
9+
charset = utf-8
10+
indent_style = space
11+
indent_size = 4
12+
end_of_line = lf
13+
trim_trailing_whitespace = true
14+
max_line_length = 80
15+
16+
# Matches the exact files either package.json or .travis.yml
17+
[{package.json,*.yml}]
18+
indent_size = 2
19+
20+
[*.go]
21+
indent_style = tab
22+
insert_final_newline = true
23+
24+
[*.md]
25+
trim_trailing_whitespace = false
26+
27+
[Makefile]
28+
indent_style = tab
29+
30+
[COMMIT_EDITMSG]
31+
max_line_length = 72

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
*.swp
3+
/tmp/
4+
.idea
5+
build/gitlab-*

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vendor/github.com/xanzy/go-gitlab"]
2+
path = vendor/github.com/xanzy/go-gitlab
3+
url = https://github.com/xanzy/go-gitlab

.travis.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
language: go
2+
3+
sudo: required
4+
5+
services:
6+
- docker
7+
8+
before_install:
9+
- docker pull gitlab/gitlab-ce
10+
- docker run -d --name gitlab -p 80:80 gitlab/gitlab-ce
11+
- go get -d ./...
12+
- sleep 120 # GitLab is like a sloth
13+
14+
install: |
15+
docker exec gitlab sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql --port 5432 -h /var/opt/gitlab/postgresql -d gitlabhq_production -c "
16+
INSERT INTO labels (title, color, template) VALUES ('feature', '#000000', true);
17+
INSERT INTO labels (title, color, template) VALUES ('bug', '#ff0000', true);
18+
UPDATE users SET authentication_token='secret' WHERE username='root';"
19+
20+
script:
21+
- GITLAB_URL="http://127.0.0.1" GITLAB_TOKEN="secret" GO15VENDOREXPERIMENT="1" go test -v ./gitlab
22+
23+
go:
24+
- 1.5
25+
- 1.6
26+
- tip
27+
28+
matrix:
29+
allow_failures:
30+
- go: tip

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Calin Seciu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# gitlab-cli [![Build Status](https://travis-ci.org/clns/gitlab-cli.svg?branch=master)](https://travis-ci.org/clns/gitlab-cli)
2+
3+
Cli commands for performing actions against GitLab repositories.
4+
5+
- [Usage](#usage)
6+
- [Install](#install)
7+
- [Development](#development)
8+
9+
## Usage
10+
11+
See help for all available commands (`gitlab-cli -h`).
12+
13+
### Labels
14+
15+
##### Copy global labels into a target repository
16+
17+
> GitLab Limitation: Currently there's no way to [access global labels through the API](https://twitter.com/gitlab/status/724619173477924865), so this tool provides a workaround for copying them into a repository. Note that you should configure the global labels manually in GitLab.
18+
19+
```sh
20+
gitlab-cli label copy -u https://gitlab.com/<USER>/<REPO> -t <TOKEN>
21+
```
22+
23+
> Tip: To avoid specifying `-u` and `-t` every time you refer to a repository, you can save the details of it into the config file with `gitlab-cli config repo save -r <NAME> -u <URL> -t <TOKEN>`, then refer to it simply as `-r <NAME>`.
24+
25+
##### Copy labels from one repository to another
26+
27+
```sh
28+
gitlab-cli label copy -r <NAME> <USER>/<SOURCE_REPO>
29+
```
30+
31+
> Tip: The above command copies labels between repositories on the same GitLab instance. To copy from a different GitLab instance, first save the source repo in the config as explained above and specify its name as argument instead of the path.
32+
33+
##### Update label(s) based on a regex match
34+
35+
```sh
36+
gitlab-cli label update -r <NAME> --match <REGEX> --replace <REPLACE> --color <COLOR>
37+
```
38+
39+
> Note: `<REGEX>` is a Go regex string as in <https://golang.org/pkg/regexp/syntax> and `<REPLACE>` is a replacement string as in <https://golang.org/pkg/regexp/#Regexp.FindAllString>.
40+
41+
##### Delete label(s) that match a regex
42+
43+
```sh
44+
gitlab-cli label update -r <NAME> --regex <REGEX>
45+
```
46+
47+
### TODO
48+
49+
Currently only the label commands are useful. Other commands can be added as needed.
50+
51+
## Install
52+
53+
1. Follow the instructions from the [releases page](https://github.com/clns/gitlab-cli/releases) and run the `curl` command, which the releases page specifies, in your terminal.
54+
55+
> Note: If you get a "Permission denied" error, your `/usr/local/bin` directory probably isn't writable and you'll need to install Compose as the superuser. Run `sudo -i`, then the commands from the release page, then `exit`.
56+
57+
2. Test the installation.
58+
59+
```sh
60+
gitlab-cli version
61+
```
62+
63+
## Development
64+
65+
You'll need a [Go dev environment](https://golang.org/doc/install).
66+
67+
### Build
68+
69+
```sh
70+
go run build/build.go
71+
```
72+
73+
This will build all the executables into the [build/](build) directory.
74+
75+
### Test
76+
77+
You need to provide a GitLab URL and private token to be able to create temporary repositories for the tests.
78+
79+
```sh
80+
GITLAB_URL="<URL>" GITLAB_TOKEN="<TOKEN>" go test -v ./gitlab
81+
```
82+
83+
You can spin up a GitLab instance using [Docker](https://www.docker.com/):
84+
85+
```sh
86+
docker pull gitlab/gitlab-ce
87+
docker run -d --name gitlab -p 8055:80 gitlab/gitlab-ce
88+
sleep 60 # allow enough time for GitLab to start
89+
docker exec gitlab \
90+
sudo -u gitlab-psql \
91+
/opt/gitlab/embedded/bin/psql --port 5432 -h /var/opt/gitlab/postgresql -d gitlabhq_production -c " \
92+
INSERT INTO labels (title, color, template) VALUES ('feature', '#000000', true); \
93+
INSERT INTO labels (title, color, template) VALUES ('bug', '#ff0000', true); \
94+
UPDATE users SET authentication_token='secret' WHERE username='root';"
95+
96+
# Note: you may need to change GITLAB_URL to point to your docker container.
97+
# 'http://docker' is for Docker beta for Windows.
98+
GITLAB_URL="http://docker:8055" GITLAB_TOKEN="secret" go test -v ./gitlab
99+
```

build/build.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
"os/exec"
7+
"path/filepath"
8+
"strings"
9+
)
10+
11+
type output struct {
12+
GOOS string
13+
GOARCH string
14+
File string
15+
}
16+
17+
var outputs = []*output{
18+
&output{"windows", "amd64", "gitlab-cli-Windows-x86_64.exe"},
19+
&output{"linux", "amd64", "gitlab-cli-Linux-x86_64"},
20+
&output{"darwin", "amd64", "gitlab-cli-Darwin-x86_64"},
21+
}
22+
23+
func main() {
24+
for _, o := range outputs {
25+
vars := []string{"GOOS=" + o.GOOS, "GOARCH=" + o.GOARCH}
26+
log.Printf("%s go build -o build/%s main.go ...", strings.Join(vars, " "), o.File)
27+
cmd := exec.Command("go", "build", "-o", filepath.Join("build", o.File), "main.go")
28+
cmd.Stdout = os.Stdout
29+
cmd.Stderr = os.Stderr
30+
env := os.Environ()
31+
env = append(env, vars...)
32+
cmd.Env = env
33+
if err := cmd.Run(); err != nil {
34+
log.Println(err)
35+
}
36+
log.Println("done")
37+
}
38+
}

cmd/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
var configCmd = &cobra.Command{
6+
Use: "config",
7+
Short: "Config actions",
8+
Long: `Perform config-related actions.`,
9+
}
10+
11+
func init() {
12+
RootCmd.AddCommand(configCmd)
13+
}

cmd/config_cat.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"io/ioutil"
7+
"os"
8+
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/viper"
11+
)
12+
13+
var configCatCmd = &cobra.Command{
14+
Use: "cat",
15+
Short: "Print config file",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
b, err := ioutil.ReadFile(viper.ConfigFileUsed())
18+
if err != nil {
19+
os.Exit(1)
20+
}
21+
fmt.Fprintln(os.Stdout, string(b))
22+
},
23+
}
24+
25+
func init() {
26+
configCmd.AddCommand(configCatCmd)
27+
}

cmd/config_repo.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
var configRepoCmd = &cobra.Command{
6+
Use: "repo",
7+
Short: "Config repos actions",
8+
Long: `Perform actions on the repos from the config file.`,
9+
}
10+
11+
func init() {
12+
configCmd.AddCommand(configRepoCmd)
13+
}

0 commit comments

Comments
 (0)