git-gitlab 0.1.0 → 0.2.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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # Git::Gitlab
2
2
 
3
- TODO: Write a gem description
3
+ [日本語](https://github.com/numa08/git-gitlab/blob/master/README_ja.md)
4
+
5
+ Command line tool for [Gitlab](https://www.gitlab.com/)
4
6
 
5
7
  ## Installation
6
8
 
@@ -18,7 +20,25 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ ### Set up
24
+
25
+ Config some setting
26
+
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
30
+
31
+ ### Let' run and Confirm setting
32
+
33
+ git gitlab
34
+
35
+ ### Create Merge Request
36
+
37
+ git gitlab merge SOURCE_BRANCH TARGET_BRANCH --assign USER_NAME
38
+
39
+ ### Show Issue by ID
40
+
41
+ git gitlab issue ISSUE_ID
22
42
 
23
43
  ## Contributing
24
44
 
data/README_ja.md ADDED
@@ -0,0 +1,39 @@
1
+ # Git::Gitlab
2
+
3
+ [Gitlab](https://www.gitlab.com/)のためのコマンドラインツールです
4
+
5
+ ## インストール方法
6
+
7
+ Ruby関連のツールをインストールして、次のコマンドを実行します
8
+
9
+ $ gem install git-gitlab
10
+
11
+ ## 使い方
12
+
13
+ ### 初期設定
14
+
15
+ 次のようにGitの設定を行います
16
+
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
20
+
21
+ ### 設定の確認を行います
22
+
23
+ git gitlab
24
+
25
+ ### マージリクエストを作ります
26
+
27
+ git gitlab merge SOURCE_BRANCH TARGET_BRANCH --assign USER_NAME
28
+
29
+ ### IDでイシューを検索し、表示します
30
+
31
+ git gitlab issue ISSUE_ID
32
+
33
+ ## 貢献するには
34
+
35
+ 1. フォークします
36
+ 2. あなたの機能ブランチを作ります (`git checkout -b my-new-feature`)
37
+ 3. 変更をコミットします (`git commit -am 'Add some feature'`)
38
+ 4. リモートブランチにプッシュします (`git push origin my-new-feature`)
39
+ 5. 新しいプルリクエストを作ります
data/bin/git-gitlab CHANGED
@@ -28,10 +28,17 @@ class GitGitlabCLI < Thor
28
28
  end
29
29
 
30
30
  desc "issue ID", "show issue which has ID"
31
- def issue(id)
31
+ option :all, :type => :boolean
32
+ def issue(id = nil)
33
+ if id == nil
34
+ issues = @@gitlab.issues(options[:all])
35
+ result = issues.map { |i| "\##{i.iid}, #{i.title}" }.join("\n")
36
+ puts(result)
37
+ exit 0
38
+ end
32
39
  begin
33
40
  issue = @@gitlab.issue(id)
34
- rescue GitlabKernel::Error::IssueNotFound => e
41
+ rescue GitlabApi::Error::IssueNotFound => e
35
42
  puts("Could not find \##{id} issue!!")
36
43
  exit 1
37
44
  end
data/git-gitlab.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "thor" , "~> 0.19.1"
24
24
  spec.add_development_dependency "gitlab", "~> 3.0.0"
25
25
  spec.add_development_dependency "grit", "~> 2.5.0"
26
+ spec.add_development_dependency "rspec", "~> 2.14.1"
26
27
  end
data/lib/git/gitlab.rb CHANGED
@@ -1,86 +1,14 @@
1
1
  require "git/gitlab/version"
2
- require "git/gitlab/issue"
2
+ require "git/gitlab/apiclient"
3
+ require "git/gitlab/api/issue"
4
+ require "git/gitlab/api/authorize"
5
+ require "git/gitlab/api/mergerequest"
3
6
  require "git/error"
4
7
  require "gitlab"
5
8
  require "grit"
6
9
 
7
- module GitlabApi
8
- API_VERSION = "v3"
9
- USER_AGENT = "nyonyonyonyonyo! Gitlab nyo!!"
10
- attr_reader :client, :repository
11
-
12
- def initialize
13
- @repository = Grit::Repo.new(`git rev-parse --show-toplevel`.chomp)
14
- config = @repository.config
15
-
16
- url = config["gitlab.url"]
17
- if url == nil
18
- raise "Plase set 'git config gitlab.url ${Gitlab URL}'"
19
- end
20
-
21
- token = config["gitlab.token"]
22
- if token == nil
23
- raise "Please set 'git config gitlab.token ${Gitlab Token}'"
24
- end
25
-
26
- Gitlab.configure do |config|
27
- config.endpoint = "#{url}/api/#{API_VERSION}"
28
- config.private_token = token
29
- config.user_agent = USER_AGENT
30
- end
31
-
32
- @client = Gitlab.client
33
- end
34
-
35
- def authorize
36
- @client.user
37
- end
38
-
39
- def create_merge_request(title, assign, source, target = "master")
40
- pid = @repository.config["gitlab.projectid"].to_i
41
-
42
- if pid == 0
43
- raise "Please set 'git config gitlab.projectid ${Gitlab Project id}'"
44
- end
45
-
46
- mr_title = if title == nil
47
- @repository.head.name
48
- else
49
- title
50
- end
51
-
52
- mr_source = if source == nil
53
- @repository.head.name
54
- else
55
- source
56
- end
57
-
58
- assignee_id = if assign == nil
59
- 0
60
- else
61
- @client.users.select { |user|
62
- user.username == assign
63
- }[0].id
64
- end
65
-
66
- begin
67
- mergerequest = if assignee_id > 0
68
- @client.create_merge_request(pid, mr_title, :source_branch => mr_source, :target_branch => target, :assignee_id => assignee_id)
69
- else
70
- @client.create_merge_request(pid, mr_title, :source_branch => mr_source, :target_branch => target)
71
- end
72
- rescue Gitlab::Error::NotFound => e
73
- raise Error::MergeRequestError, "Failed Create Merge Request"
74
- end
75
-
76
- project_url = @client.project(pid).web_url
77
- mergerequest_url = project_url + "/merge_requests/" + mergerequest.id.to_s
78
-
79
- mergerequest_url
80
- end
81
- end
82
-
83
- class GitlabKernel
84
- include GitlabApi
85
- include Issue
10
+ class GitlabKernel < GitlabApi::ApiClient
11
+ include GitlabApi::ApiClient::Issue
12
+ include GitlabApi::ApiClient::Authorize
13
+ include GitlabApi::ApiClient::Mergerequest
86
14
  end
@@ -0,0 +1,13 @@
1
+ require "gitlab"
2
+ require "grit"
3
+ require "git/error"
4
+
5
+ class GitlabApi::ApiClient
6
+
7
+ module Authorize
8
+ def authorize
9
+ @client.user
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,70 @@
1
+ require "gitlab"
2
+ require "grit"
3
+ require "git/error"
4
+
5
+
6
+ class GitlabApi::ApiClient
7
+
8
+ module Issue
9
+ PER_PAGE = 100
10
+ PAGE = 1
11
+
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
18
+
19
+ issues = all_issues(pid, PAGE, PER_PAGE)
20
+
21
+ specfied_issue = issues.select { |issue|
22
+ issue.iid == id.to_i
23
+ }.first
24
+
25
+ if specfied_issue == nil
26
+ raise GitlabApi::Error::IssueNotFound, "Issue not find"
27
+ else
28
+ specfied_issue
29
+ end
30
+ end
31
+
32
+ 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
38
+
39
+ issues = all_issues(pid, PAGE, PER_PAGE)
40
+ if with_closed
41
+ issues
42
+ else
43
+ issues.select { |i|
44
+ i.state == "opened"
45
+ }
46
+ end
47
+ end
48
+
49
+ def all_issues(pid, page, per_page)
50
+ def _issues(list, pid, page, per_page)
51
+ i = @client.issues(pid, :page => page, :per_page => per_page)
52
+ if i.count < per_page
53
+ list + i
54
+ else
55
+ _issues(list + i, pid, page + 1, per_page)
56
+ end
57
+
58
+ end
59
+
60
+ i = @client.issues(pid, :page => page, :per_page => per_page)
61
+ if i.count < per_page
62
+ i
63
+ else
64
+ _issues(i, pid, page + 1, per_page)
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,51 @@
1
+ require "gitlab"
2
+ require "grit"
3
+ require "git/error"
4
+
5
+ class GitlabApi::ApiClient
6
+
7
+ module Mergerequest
8
+ def create_merge_request(title, assign, source, target = "master")
9
+ pid = @repository.config["gitlab.projectid"].to_i
10
+
11
+ if pid == 0
12
+ raise "Please set 'git config gitlab.projectid ${Gitlab Project id}'"
13
+ end
14
+
15
+ mr_title = if title == nil
16
+ @repository.head.name
17
+ else
18
+ title
19
+ end
20
+
21
+ mr_source = if source == nil
22
+ @repository.head.name
23
+ else
24
+ source
25
+ end
26
+
27
+ assignee_id = if assign == nil
28
+ 0
29
+ else
30
+ @client.users.select { |user|
31
+ user.username == assign
32
+ }[0].id
33
+ end
34
+
35
+ begin
36
+ mergerequest = if assignee_id > 0
37
+ @client.create_merge_request(pid, mr_title, :source_branch => mr_source, :target_branch => target, :assignee_id => assignee_id)
38
+ else
39
+ @client.create_merge_request(pid, mr_title, :source_branch => mr_source, :target_branch => target)
40
+ end
41
+ rescue Gitlab::Error::NotFound => e
42
+ raise GitlabApi::Error::MergeRequestError, "Failed Create Merge Request"
43
+ end
44
+
45
+ project_url = @client.project(pid).web_url
46
+ mergerequest_url = project_url + "/merge_requests/" + mergerequest.iid.to_s
47
+
48
+ mergerequest_url
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,35 @@
1
+ require "git/gitlab/version"
2
+ require "gitlab"
3
+ require "grit"
4
+
5
+
6
+ module GitlabApi
7
+ class ApiClient
8
+ API_VERSION = "v3"
9
+ USER_AGENT = "nyonyonyonyonyo! Gitlab nyo!!"
10
+ attr_reader :client, :repository
11
+
12
+ def initialize
13
+ @repository = Grit::Repo.new(`git rev-parse --show-toplevel`.chomp)
14
+ config = @repository.config
15
+
16
+ url = config["gitlab.url"]
17
+ if url == nil
18
+ raise "Plase set 'git config gitlab.url ${Gitlab URL}'"
19
+ end
20
+
21
+ token = config["gitlab.token"]
22
+ if token == nil
23
+ raise "Please set 'git config gitlab.token ${Gitlab Token}'"
24
+ end
25
+
26
+ Gitlab.configure do |config|
27
+ config.endpoint = "#{url}/api/#{API_VERSION}"
28
+ config.private_token = token
29
+ config.user_agent = USER_AGENT
30
+ end
31
+
32
+ @client = Gitlab.client
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Gitlab
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require "git/gitlab"
3
+
4
+ describe GitlabKernel, "get issue" do
5
+
6
+ before do
7
+ @gitlab = GitlabKernel.new
8
+ end
9
+
10
+ it "should return issue title" do
11
+ actual = @gitlab.issue(1).title
12
+ actual.should == "the issue"
13
+ end
14
+
15
+ it "should get all issues" do
16
+ actual = @gitlab.issues(true).count
17
+ actual.should == 650
18
+ end
19
+
20
+ it "should get opened issues" do
21
+ actual = @gitlab.issues(false).count
22
+ actual.should == 649
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require "git/gitlab"
3
+
4
+ describe GitlabKernel, "create new mergerequest" do
5
+
6
+ before do
7
+ @gitlab = GitlabKernel.new
8
+
9
+ @test_config = {:projectid => 8,
10
+ :project_path => "numa08/git-gitlab",
11
+ :gitlab_url => "http://vagrant-ubuntu-precise-64/"}
12
+ end
13
+
14
+ it "should return mergerquest url" do
15
+ actual = @gitlab.create_merge_request("test", nil, "tem", "master")
16
+ expect(actual).to include("#{@test_config[:gitlab_url]}#{@test_config[:project_path]}/merge_requests")
17
+ end
18
+ end
@@ -0,0 +1,2 @@
1
+ # -*- coding: utf-8 -*-
2
+
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.1.0
4
+ version: 0.2.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-20 00:00:00.000000000 Z
12
+ date: 2014-04-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
93
  version: 2.5.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 2.14.1
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 2.14.1
94
110
  description: Gitlab Command line interface
95
111
  email:
96
112
  - n511287@gmail.com
@@ -103,13 +119,20 @@ files:
103
119
  - Gemfile
104
120
  - LICENSE.txt
105
121
  - README.md
122
+ - README_ja.md
106
123
  - Rakefile
107
124
  - bin/git-gitlab
108
125
  - git-gitlab.gemspec
109
126
  - lib/git/error.rb
110
127
  - lib/git/gitlab.rb
111
- - lib/git/gitlab/issue.rb
128
+ - lib/git/gitlab/api/authorize.rb
129
+ - lib/git/gitlab/api/issue.rb
130
+ - lib/git/gitlab/api/mergerequest.rb
131
+ - lib/git/gitlab/apiclient.rb
112
132
  - lib/git/gitlab/version.rb
133
+ - spec/issue_spec.rb
134
+ - spec/mergerequest_spec.rb
135
+ - spec/spec_helper.rb
113
136
  homepage: https://github.com/numa08/git-gitlab
114
137
  licenses:
115
138
  - MIT
@@ -135,4 +158,7 @@ rubygems_version: 1.8.23
135
158
  signing_key:
136
159
  specification_version: 3
137
160
  summary: git-gitlab command line
138
- test_files: []
161
+ test_files:
162
+ - spec/issue_spec.rb
163
+ - spec/mergerequest_spec.rb
164
+ - spec/spec_helper.rb
@@ -1,49 +0,0 @@
1
- require "gitlab"
2
- require "grit"
3
- require "git/error"
4
-
5
-
6
- module Issue
7
-
8
- def issue(id)
9
- pid = @repository.config["gitlab.projectid"].to_i
10
-
11
- if pid == 0
12
- raise "Please set 'git config gitlab.projectid ${Gitlab Project id}'"
13
- end
14
-
15
- per_page = 100
16
- page = 1
17
-
18
- def all_issues(pid, page, per_page)
19
- def _issues(list, pid, page, per_page)
20
- i = @client.issues(pid, :page => page, :per_page => per_page)
21
- if i.count < per_page
22
- list + i
23
- else
24
- _issues(list + i, pid, page + 1, per_page)
25
- end
26
-
27
- end
28
-
29
- i = @client.issues(pid, :page => page, :per_page => per_page)
30
- if i.count < per_page
31
- i
32
- else
33
- _issues(i, pid, page + 1, per_page)
34
- end
35
- end
36
-
37
- issues = all_issues(pid, page, per_page)
38
-
39
- specfied_issue = issues.select { |issue|
40
- issue.iid == id.to_i
41
- }.first
42
-
43
- if specfied_issue == nil
44
- raise GitlabKernel::Error::IssueNotFound, "Issue not find"
45
- else
46
- specfied_issue
47
- end
48
- end
49
- end