git-gitlab 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +8 -0
- data/README_ja.md +8 -0
- data/bin/git-gitlab +98 -70
- data/lib/git/error.rb +7 -6
- data/lib/git/gitlab.rb +10 -4
- data/lib/git/gitlab/api/authorize.rb +8 -8
- data/lib/git/gitlab/api/issue.rb +56 -56
- data/lib/git/gitlab/api/mergerequest.rb +83 -71
- data/lib/git/gitlab/apiclient.rb +8 -0
- data/lib/git/gitlab/gitlablocal.rb +9 -0
- data/lib/git/gitlab/local/codereview.rb +23 -0
- data/lib/git/gitlab/version.rb +1 -1
- metadata +4 -2
data/README.md
CHANGED
@@ -28,6 +28,10 @@ Config some setting
|
|
28
28
|
git config --global gitlab.token GITLAB_SECRET_TOKEN
|
29
29
|
git config gitlab.project NAMESPACE/PROJECT
|
30
30
|
|
31
|
+
if your remote repository is not origin
|
32
|
+
|
33
|
+
git config gitlab.remote REMOTE
|
34
|
+
|
31
35
|
### Let' run and Confirm setting
|
32
36
|
|
33
37
|
git gitlab
|
@@ -44,6 +48,10 @@ Config some setting
|
|
44
48
|
|
45
49
|
git gitlab issue ISSUE_ID
|
46
50
|
|
51
|
+
### Code Review
|
52
|
+
|
53
|
+
git gitlab review MERGEREQUEST_ID
|
54
|
+
|
47
55
|
## Contributing
|
48
56
|
|
49
57
|
1. Fork it
|
data/README_ja.md
CHANGED
@@ -18,6 +18,10 @@ Ruby関連のツールをインストールして、次のコマンドを実行
|
|
18
18
|
git config --glolab gitlab.token GITLAB_SECRET_TOKEN
|
19
19
|
git config gitlab.project NAMESPACE/PROJECT
|
20
20
|
|
21
|
+
もしもGitlabのリモートリポジトリがoriginでない場合には
|
22
|
+
|
23
|
+
git config gitlab.remote REMOTE
|
24
|
+
|
21
25
|
### 設定の確認を行います
|
22
26
|
|
23
27
|
git gitlab
|
@@ -34,6 +38,10 @@ Ruby関連のツールをインストールして、次のコマンドを実行
|
|
34
38
|
|
35
39
|
git gitlab issue ISSUE_ID
|
36
40
|
|
41
|
+
### Mergeリクエストのレビューを行います
|
42
|
+
|
43
|
+
git gitlab review MERGEREQUEST_ID
|
44
|
+
|
37
45
|
## 貢献するには
|
38
46
|
|
39
47
|
1. フォークします
|
data/bin/git-gitlab
CHANGED
@@ -2,83 +2,111 @@
|
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
4
|
require 'git/gitlab'
|
5
|
-
require
|
5
|
+
require 'thor'
|
6
6
|
|
7
|
+
#
|
8
|
+
# Gitlab Commandline interface
|
9
|
+
#
|
7
10
|
class GitGitlabCLI < Thor
|
8
|
-
|
11
|
+
@gitlab = GitlabKernel.new
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
desc "merge SOURCE TARGET --assign ${ASSING}", "create mergerequest SOURCE to TARGET. assign to ${ASSING}"
|
14
|
+
long_desc <<-LONGDESC
|
15
|
+
[-l | --list] get all opened mergerequests
|
16
|
+
LONGDESC
|
17
|
+
option :assign
|
18
|
+
option :list, :type => :boolean
|
19
|
+
option :l , :type => :boolean
|
20
|
+
def merge(source =nil, target = nil)
|
21
|
+
if options[:list] || options[:l]
|
22
|
+
mergerequests = @gitlab.mergerequests
|
23
|
+
result = mergerequests.map { |m| "\##{m.iid}, #{m.title}" }.join("\n")
|
24
|
+
puts(result)
|
25
|
+
exit 0
|
26
|
+
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
28
|
+
title = source
|
29
|
+
assign = options[:assign]
|
30
|
+
begin
|
31
|
+
url = if target == nil
|
32
|
+
@gitlab.create_merge_request(title, assign, source)
|
33
|
+
else
|
34
|
+
@gitlab.create_merge_request(title, assign, source, target)
|
35
|
+
end
|
36
|
+
rescue GitlabApi::Error::MergeRequestError => e
|
37
|
+
puts("Failed Create Merge Request")
|
38
|
+
puts("Please check your command's argument ,options and already exists mergerequests...")
|
39
|
+
puts(e.message)
|
40
|
+
exit 1
|
41
|
+
rescue GitlabApi::Error::ProjectIdNotFound => e
|
42
|
+
puts(e.message)
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
puts("created mergerequest at")
|
46
|
+
puts(url)
|
47
|
+
end
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
49
|
+
desc "issue ID", "show issue which has ID"
|
50
|
+
option :all, :type => :boolean
|
51
|
+
def issue(id = nil)
|
52
|
+
if id == nil
|
53
|
+
issues = @gitlab.issues(options[:all])
|
54
|
+
result = issues.map { |i| "\##{i.iid}, #{i.title}" }.join("\n")
|
55
|
+
puts(result)
|
56
|
+
exit 0
|
57
|
+
end
|
58
|
+
begin
|
59
|
+
issue = @gitlab.issue(id)
|
60
|
+
rescue GitlabApi::Error::IssueNotFound => e
|
61
|
+
puts("Could not find \##{id} issue!!")
|
62
|
+
puts(e.message)
|
63
|
+
exit 1
|
64
|
+
rescue GitlabApi::Error::ProjectIdNotFound => e
|
65
|
+
puts(e.message)
|
66
|
+
exit 1
|
67
|
+
end
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
puts("\##{issue.iid}")
|
70
|
+
puts("title : #{issue.title}")
|
71
|
+
puts("description: #{issue.description}")
|
72
|
+
puts("label : #{issue.labels.join(',')}")
|
73
|
+
puts("state : #{issue.state}")
|
74
|
+
if issue.assignee != nil
|
75
|
+
puts("assignee : #{issue.assignee.username}")
|
76
|
+
end
|
77
|
+
end
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
desc "review ID", "checkout mergerequest merged commit"
|
80
|
+
def review(id)
|
81
|
+
|
82
|
+
begin
|
83
|
+
remote = @gitlab.remote
|
84
|
+
mergerequest = @gitlab.mergerequest(id)
|
85
|
+
|
86
|
+
repository = GitlabLocalRepository.new()
|
87
|
+
repository.review("mergerequest/\##{id}" , mergerequest.source_branch, mergerequest.target_branch, remote)
|
88
|
+
puts("When you finish code review,then")
|
89
|
+
puts(" git merge --abort")
|
90
|
+
puts("and")
|
91
|
+
puts(" git checkout -")
|
92
|
+
rescue GitlabApi::Error::MergeRequestError => e
|
93
|
+
puts("Merege request is not found")
|
94
|
+
puts(e.message)
|
95
|
+
exit 1
|
96
|
+
rescue GitlabApi::Error::ReviewError => e
|
97
|
+
puts("Local Repository's status is invalided")
|
98
|
+
puts("Check your repository's status")
|
99
|
+
puts(e.message)
|
100
|
+
exit 1
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def help
|
105
|
+
user = @gitlab.authorize
|
106
|
+
puts("You are #{user.username}")
|
107
|
+
puts("Gitlab is #{Gitlab.endpoint}")
|
108
|
+
super
|
109
|
+
end
|
82
110
|
end
|
83
111
|
|
84
112
|
GitGitlabCLI.start
|
data/lib/git/error.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module GitlabApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
2
|
+
module Error
|
3
|
+
class MergeRequestError < StandardError; end
|
4
|
+
class IssueNotFound < StandardError; end
|
5
|
+
class ProjectIdNotFound < StandardError; end
|
6
|
+
class ReviewError < StandardError; end
|
7
|
+
end
|
8
|
+
end
|
data/lib/git/gitlab.rb
CHANGED
@@ -3,12 +3,18 @@ require "git/gitlab/apiclient"
|
|
3
3
|
require "git/gitlab/api/issue"
|
4
4
|
require "git/gitlab/api/authorize"
|
5
5
|
require "git/gitlab/api/mergerequest"
|
6
|
+
require "git/gitlab/gitlablocal"
|
7
|
+
require "git/gitlab/local/codereview"
|
6
8
|
require "git/error"
|
7
9
|
require "gitlab"
|
8
10
|
require "grit"
|
9
11
|
|
10
12
|
class GitlabKernel < GitlabApi::ApiClient
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
13
|
+
include GitlabApi::ApiClient::Issue
|
14
|
+
include GitlabApi::ApiClient::Authorize
|
15
|
+
include GitlabApi::ApiClient::Mergerequest
|
16
|
+
end
|
17
|
+
|
18
|
+
class GitlabLocalRepository < GitlabLocal
|
19
|
+
include GitlabLocal::CodeReview
|
20
|
+
end
|
data/lib/git/gitlab/api/issue.rb
CHANGED
@@ -4,59 +4,59 @@ require "git/error"
|
|
4
4
|
|
5
5
|
|
6
6
|
class GitlabApi::ApiClient
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
7
|
+
|
8
|
+
module Issue
|
9
|
+
PER_PAGE = 100
|
10
|
+
PAGE = 1
|
11
|
+
|
12
|
+
def issue(id)
|
13
|
+
pid = project_id
|
14
|
+
|
15
|
+
issues = all_issues(pid, PAGE, PER_PAGE)
|
16
|
+
|
17
|
+
specfied_issue = issues.select { |issue|
|
18
|
+
issue.iid == id.to_i
|
19
|
+
}.first
|
20
|
+
|
21
|
+
if specfied_issue == nil
|
22
|
+
raise GitlabApi::Error::IssueNotFound, "Issue not find"
|
23
|
+
else
|
24
|
+
specfied_issue
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def issues(with_closed)
|
29
|
+
pid = project_id
|
30
|
+
|
31
|
+
issues = all_issues(pid, PAGE, PER_PAGE)
|
32
|
+
if with_closed
|
33
|
+
issues
|
34
|
+
else
|
35
|
+
issues.select { |i|
|
36
|
+
i.state == "opened"
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def all_issues(pid, page, per_page)
|
42
|
+
def _issues(list, pid, page, per_page)
|
43
|
+
i = @client.issues(pid, :page => page, :per_page => per_page)
|
44
|
+
if i.count < per_page
|
45
|
+
list + i
|
46
|
+
else
|
47
|
+
_issues(list + i, pid, page + 1, per_page)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
i = @client.issues(pid, :page => page, :per_page => per_page)
|
53
|
+
if i.count < per_page
|
54
|
+
i
|
55
|
+
else
|
56
|
+
_issues(i, pid, page + 1, per_page)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -3,74 +3,86 @@ require "grit"
|
|
3
3
|
require "git/error"
|
4
4
|
|
5
5
|
class GitlabApi::ApiClient
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
6
|
+
|
7
|
+
module Mergerequest
|
8
|
+
PER_PAGE = 100
|
9
|
+
PAGE = 1
|
10
|
+
|
11
|
+
def create_merge_request(title, assign, source, target = "master")
|
12
|
+
pid = project_id
|
13
|
+
|
14
|
+
mr_title = if title == nil
|
15
|
+
@repository.head.name
|
16
|
+
else
|
17
|
+
title
|
18
|
+
end
|
19
|
+
|
20
|
+
mr_source = if source == nil
|
21
|
+
@repository.head.name
|
22
|
+
else
|
23
|
+
source
|
24
|
+
end
|
25
|
+
|
26
|
+
assignee_id = if assign == nil
|
27
|
+
0
|
28
|
+
else
|
29
|
+
@client.users.select { |user|
|
30
|
+
user.username == assign
|
31
|
+
}[0].id
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
mergerequest = if assignee_id > 0
|
36
|
+
@client.create_merge_request(pid, mr_title, :source_branch => mr_source, :target_branch => target, :assignee_id => assignee_id)
|
37
|
+
else
|
38
|
+
@client.create_merge_request(pid, mr_title, :source_branch => mr_source, :target_branch => target)
|
39
|
+
end
|
40
|
+
rescue Gitlab::Error::NotFound => e
|
41
|
+
raise GitlabApi::Error::MergeRequestError, "Failed Create Merge Request"
|
42
|
+
end
|
43
|
+
|
44
|
+
project_url = @client.project(pid).web_url
|
45
|
+
mergerequest_url = project_url + "/merge_requests/" + mergerequest.iid.to_s
|
46
|
+
|
47
|
+
mergerequest_url
|
48
|
+
end
|
49
|
+
|
50
|
+
def mergerequests
|
51
|
+
pid = project_id
|
52
|
+
|
53
|
+
all_mergerequests(pid, PAGE, PER_PAGE).select { |m|
|
54
|
+
m.state == "opened"
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def mergerequest(id)
|
59
|
+
pid = project_id
|
60
|
+
|
61
|
+
begin
|
62
|
+
mr = @client.merge_request(pid, id)
|
63
|
+
rescue Gitlab::Error::NotFound => e
|
64
|
+
raise GitlabApi::Error::MergeRequestError, "Can not find #{id} mergerequest"
|
65
|
+
end
|
66
|
+
mr
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def all_mergerequests(pid, page, per_page)
|
71
|
+
def _mergerequests(list, pid, page, per_page)
|
72
|
+
m = @client.merge_requests(pid, :page => page, :per_page => per_page)
|
73
|
+
if m.count < per_page
|
74
|
+
list + m
|
75
|
+
else
|
76
|
+
_mergerequests(list + m, pid, page + 1, per_page)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
m = @client.merge_requests(pid, :page => page, :per_page => per_page)
|
81
|
+
if m.count < per_page
|
82
|
+
m
|
83
|
+
else
|
84
|
+
_mergerequests(m, pid, page + 1, per_page)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/git/gitlab/apiclient.rb
CHANGED
@@ -33,6 +33,14 @@ module GitlabApi
|
|
33
33
|
@client = Gitlab.client
|
34
34
|
end
|
35
35
|
|
36
|
+
def remote
|
37
|
+
if @repository.config.keys.include? "gitlab.remote"
|
38
|
+
@repository.config["gitlab.remote"]
|
39
|
+
else
|
40
|
+
"origin"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
36
44
|
def project_id
|
37
45
|
pid = if @repository.config.keys.include? "gitlab.projectid"
|
38
46
|
@repository.config["gitlab.projectid"].to_i
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "git/gitlab/version"
|
2
|
+
require "git/error"
|
3
|
+
require "grit"
|
4
|
+
|
5
|
+
class GitlabLocal
|
6
|
+
|
7
|
+
module CodeReview
|
8
|
+
|
9
|
+
def review(title ,source, target, remote)
|
10
|
+
status = @repository.status
|
11
|
+
is_modified = status.added.count > 0 ||
|
12
|
+
status.changed.count >0 ||
|
13
|
+
status.deleted.count >0
|
14
|
+
if is_modified
|
15
|
+
raise GitlabApi::Error::ReviewError, `git status`
|
16
|
+
end
|
17
|
+
|
18
|
+
puts(`git fetch #{remote}`)
|
19
|
+
puts(`git checkout -b #{title} #{remote}/#{target}`)
|
20
|
+
puts(`git merge --no-ff --no-commit #{remote}/#{source}`)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/git/gitlab/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-gitlab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -129,6 +129,8 @@ files:
|
|
129
129
|
- lib/git/gitlab/api/issue.rb
|
130
130
|
- lib/git/gitlab/api/mergerequest.rb
|
131
131
|
- lib/git/gitlab/apiclient.rb
|
132
|
+
- lib/git/gitlab/gitlablocal.rb
|
133
|
+
- lib/git/gitlab/local/codereview.rb
|
132
134
|
- lib/git/gitlab/version.rb
|
133
135
|
- spec/issue_spec.rb
|
134
136
|
- spec/mergerequest_spec.rb
|