git-gitlab 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/git-gitlab +57 -0
- data/git-gitlab.gemspec +26 -0
- data/lib/git/error.rb +6 -0
- data/lib/git/gitlab/issue.rb +49 -0
- data/lib/git/gitlab/version.rb +5 -0
- data/lib/git/gitlab.rb +86 -0
- metadata +138 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 numa08
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Git::Gitlab
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'git-gitlab'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install git-gitlab
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/git-gitlab
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'git/gitlab'
|
5
|
+
require "thor"
|
6
|
+
|
7
|
+
class GitGitlabCLI < Thor
|
8
|
+
@@gitlab = GitlabKernel.new
|
9
|
+
|
10
|
+
desc "merge SOURCE TARGET --assign ${ASSING}", "create mergerequest SOURCE to TARGET. assign to ${ASSING}"
|
11
|
+
option :assign
|
12
|
+
def merge(source = nil, target = nil)
|
13
|
+
title = source
|
14
|
+
assign = options[:assign]
|
15
|
+
begin
|
16
|
+
url = if target == nil
|
17
|
+
@@gitlab.create_merge_request(title, assign, source)
|
18
|
+
else
|
19
|
+
@@gitlab.create_merge_request(title, assign, source, target)
|
20
|
+
end
|
21
|
+
rescue GitlabKernel::Error::MergeRequestError => e
|
22
|
+
puts("Failed Create Merge Request")
|
23
|
+
puts("Please check your command's argument ,options and already exists mergerequests...")
|
24
|
+
raise e
|
25
|
+
end
|
26
|
+
puts("created mergerequest at")
|
27
|
+
puts(url)
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "issue ID", "show issue which has ID"
|
31
|
+
def issue(id)
|
32
|
+
begin
|
33
|
+
issue = @@gitlab.issue(id)
|
34
|
+
rescue GitlabKernel::Error::IssueNotFound => e
|
35
|
+
puts("Could not find \##{id} issue!!")
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
39
|
+
puts("\##{issue.iid}")
|
40
|
+
puts("title : #{issue.title}")
|
41
|
+
puts("description: #{issue.description}")
|
42
|
+
puts("label : #{issue.labels.join(',')}")
|
43
|
+
puts("state : #{issue.state}")
|
44
|
+
if issue.assignee != nil
|
45
|
+
puts("assignee : #{issue.assignee.username}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def help
|
50
|
+
user = @@gitlab.authorize
|
51
|
+
puts("You are #{user.username}")
|
52
|
+
puts("Gitlab is #{Gitlab.endpoint}")
|
53
|
+
super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
GitGitlabCLI.start
|
data/git-gitlab.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'git/gitlab/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "git-gitlab"
|
8
|
+
spec.version = Git::Gitlab::VERSION
|
9
|
+
spec.authors = ["numa08"]
|
10
|
+
spec.email = ["n511287@gmail.com"]
|
11
|
+
spec.description = "Gitlab Command line interface"
|
12
|
+
spec.summary = "git-gitlab command line"
|
13
|
+
spec.homepage = "https://github.com/numa08/git-gitlab"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "thor" , "~> 0.19.1"
|
24
|
+
spec.add_development_dependency "gitlab", "~> 3.0.0"
|
25
|
+
spec.add_development_dependency "grit", "~> 2.5.0"
|
26
|
+
end
|
data/lib/git/error.rb
ADDED
@@ -0,0 +1,49 @@
|
|
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
|
data/lib/git/gitlab.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require "git/gitlab/version"
|
2
|
+
require "git/gitlab/issue"
|
3
|
+
require "git/error"
|
4
|
+
require "gitlab"
|
5
|
+
require "grit"
|
6
|
+
|
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
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-gitlab
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- numa08
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: thor
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.19.1
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.19.1
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: gitlab
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.0.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.0.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: grit
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.5.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.5.0
|
94
|
+
description: Gitlab Command line interface
|
95
|
+
email:
|
96
|
+
- n511287@gmail.com
|
97
|
+
executables:
|
98
|
+
- git-gitlab
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- bin/git-gitlab
|
108
|
+
- git-gitlab.gemspec
|
109
|
+
- lib/git/error.rb
|
110
|
+
- lib/git/gitlab.rb
|
111
|
+
- lib/git/gitlab/issue.rb
|
112
|
+
- lib/git/gitlab/version.rb
|
113
|
+
homepage: https://github.com/numa08/git-gitlab
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.23
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: git-gitlab command line
|
138
|
+
test_files: []
|