git-gitlab 0.2.0 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,8 +25,8 @@ Or install it yourself as:
25
25
  Config some setting
26
26
 
27
27
  git config --global gitlab.url http://gitlab.example.com/
28
- git config --gloabl gitlab.token GITLAB_SECRET_TOKEN
29
- git config gitlab.projectid GITLAB_PROJECTID
28
+ git config --global gitlab.token GITLAB_SECRET_TOKEN
29
+ git config gitlab.project NAMESPACE/PROJECT
30
30
 
31
31
  ### Let' run and Confirm setting
32
32
 
@@ -36,6 +36,10 @@ Config some setting
36
36
 
37
37
  git gitlab merge SOURCE_BRANCH TARGET_BRANCH --assign USER_NAME
38
38
 
39
+ ### Get Mergerequest list
40
+
41
+ git gitlab merge --list
42
+
39
43
  ### Show Issue by ID
40
44
 
41
45
  git gitlab issue ISSUE_ID
data/README_ja.md CHANGED
@@ -15,8 +15,8 @@ Ruby関連のツールをインストールして、次のコマンドを実行
15
15
  次のようにGitの設定を行います
16
16
 
17
17
  git config --global gitlab.url http://gitlab.example.com/
18
- git config --gloabl gitlab.token GITLAB_SECRET_TOKEN
19
- git config gitlab.projectid GITLAB_PROJECTID
18
+ git config --glolab gitlab.token GITLAB_SECRET_TOKEN
19
+ git config gitlab.project NAMESPACE/PROJECT
20
20
 
21
21
  ### 設定の確認を行います
22
22
 
@@ -26,6 +26,10 @@ Ruby関連のツールをインストールして、次のコマンドを実行
26
26
 
27
27
  git gitlab merge SOURCE_BRANCH TARGET_BRANCH --assign USER_NAME
28
28
 
29
+ ### OpenなMergerequestを全て取得します
30
+
31
+ git gitlab merge --list
32
+
29
33
  ### IDでイシューを検索し、表示します
30
34
 
31
35
  git gitlab issue ISSUE_ID
data/bin/git-gitlab CHANGED
@@ -8,8 +8,20 @@ class GitGitlabCLI < Thor
8
8
  @@gitlab = GitlabKernel.new
9
9
 
10
10
  desc "merge SOURCE TARGET --assign ${ASSING}", "create mergerequest SOURCE to TARGET. assign to ${ASSING}"
11
+ long_desc <<-LONGDESC
12
+ [-l | --list] get all opened mergerequests
13
+ LONGDESC
11
14
  option :assign
12
- def merge(source = nil, target = nil)
15
+ option :list, :type => :boolean
16
+ option :l , :type => :boolean
17
+ def merge(source, target = nil)
18
+ if options[:list] || options[:l]
19
+ mergerequests = @@gitlab.mergerequests
20
+ result = mergerequests.map { |m| "\##{m.iid}, #{m.title}" }.join("\n")
21
+ puts(result)
22
+ exit 0
23
+ end
24
+
13
25
  title = source
14
26
  assign = options[:assign]
15
27
  begin
@@ -18,10 +30,14 @@ class GitGitlabCLI < Thor
18
30
  else
19
31
  @@gitlab.create_merge_request(title, assign, source, target)
20
32
  end
21
- rescue GitlabKernel::Error::MergeRequestError => e
33
+ rescue GitlabApi::Error::MergeRequestError => e
22
34
  puts("Failed Create Merge Request")
23
35
  puts("Please check your command's argument ,options and already exists mergerequests...")
24
- raise e
36
+ puts(e.message)
37
+ exit 1
38
+ rescue GitlabApi::Error::ProjectIdNotFound => e
39
+ puts(e.message)
40
+ exit 1
25
41
  end
26
42
  puts("created mergerequest at")
27
43
  puts(url)
@@ -40,6 +56,10 @@ class GitGitlabCLI < Thor
40
56
  issue = @@gitlab.issue(id)
41
57
  rescue GitlabApi::Error::IssueNotFound => e
42
58
  puts("Could not find \##{id} issue!!")
59
+ puts(e.message)
60
+ exit 1
61
+ rescue GitlabApi::Error::ProjectIdNotFound => e
62
+ puts(e.message)
43
63
  exit 1
44
64
  end
45
65
 
data/lib/git/error.rb CHANGED
@@ -2,5 +2,6 @@ module GitlabApi
2
2
  module Error
3
3
  class MergeRequestError < StandardError; end
4
4
  class IssueNotFound < StandardError; end
5
+ class ProjectIdNotFound < StandardError; end
5
6
  end
6
7
  end
@@ -10,11 +10,7 @@ class GitlabApi::ApiClient
10
10
  PAGE = 1
11
11
 
12
12
  def issue(id)
13
- pid = @repository.config["gitlab.projectid"].to_i
14
-
15
- if pid == 0
16
- raise "Please set 'git config gitlab.projectid ${Gitlab Project id}'"
17
- end
13
+ pid = project_id
18
14
 
19
15
  issues = all_issues(pid, PAGE, PER_PAGE)
20
16
 
@@ -30,11 +26,7 @@ class GitlabApi::ApiClient
30
26
  end
31
27
 
32
28
  def issues(with_closed)
33
- pid = @repository.config["gitlab.projectid"].to_i
34
-
35
- if pid == 0
36
- raise "Please set 'git config gitlab.projectid ${Gitlab Project id}'"
37
- end
29
+ pid = project_id
38
30
 
39
31
  issues = all_issues(pid, PAGE, PER_PAGE)
40
32
  if with_closed
@@ -5,12 +5,11 @@ require "git/error"
5
5
  class GitlabApi::ApiClient
6
6
 
7
7
  module Mergerequest
8
- def create_merge_request(title, assign, source, target = "master")
9
- pid = @repository.config["gitlab.projectid"].to_i
8
+ PER_PAGE = 100
9
+ PAGE = 1
10
10
 
11
- if pid == 0
12
- raise "Please set 'git config gitlab.projectid ${Gitlab Project id}'"
13
- end
11
+ def create_merge_request(title, assign, source, target = "master")
12
+ pid = project_id
14
13
 
15
14
  mr_title = if title == nil
16
15
  @repository.head.name
@@ -47,5 +46,31 @@ class GitlabApi::ApiClient
47
46
 
48
47
  mergerequest_url
49
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 all_mergerequests(pid, page, per_page)
59
+ def _mergerequests(list, pid, page, per_page)
60
+ m = @client.merge_requests(pid, :page => page, :per_page => per_page)
61
+ if m.count < per_page
62
+ list + m
63
+ else
64
+ _mergerequests(list + m, pid, page + 1, per_page)
65
+ end
66
+ end
67
+
68
+ m = @client.merge_requests(pid, :page => page, :per_page => per_page)
69
+ if m.count < per_page
70
+ m
71
+ else
72
+ _mergerequests(m, pid, page + 1, per_page)
73
+ end
74
+ end
50
75
  end
51
76
  end
@@ -1,7 +1,8 @@
1
1
  require "git/gitlab/version"
2
+ require "git/error"
2
3
  require "gitlab"
3
4
  require "grit"
4
-
5
+ require "uri"
5
6
 
6
7
  module GitlabApi
7
8
  class ApiClient
@@ -31,5 +32,24 @@ module GitlabApi
31
32
 
32
33
  @client = Gitlab.client
33
34
  end
35
+
36
+ def project_id
37
+ pid = if @repository.config.keys.include? "gitlab.projectid"
38
+ @repository.config["gitlab.projectid"].to_i
39
+ else
40
+ @repository.config["gitlab.project"]
41
+ end
42
+
43
+ if pid == nil
44
+ raise "Please set 'git config gitlab.projectid ${Gitlab Project id}' of git config gitlab.project ${NAMESPACE/PROJECT}"
45
+ end
46
+
47
+ begin
48
+ @client.project( URI.encode_www_form_component(pid.to_s)).id
49
+ rescue Gitlab::Error::NotFound => e
50
+ raise GitlabApi::Error::ProjectIdNotFound, "Can not find #{pid} Project."
51
+ end
52
+
53
+ end
34
54
  end
35
55
  end
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Gitlab
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.5"
4
4
  end
5
5
  end
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.2.0
4
+ version: 0.2.5
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-21 00:00:00.000000000 Z
12
+ date: 2014-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler