gitlab_mr_release 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e74b91dbe20ff578ba041452848e85f244ba6403
4
+ data.tar.gz: 4789e5d235e1ac0b995ac55618b6375dfe7ca65e
5
+ SHA512:
6
+ metadata.gz: f9e8c3f964cf68c570c69fb8f1b95d0e2b21c4a6439eef3ee62a8b847a3f31f1e709abc8c9051e65d637d1c9032ec1fef8a719380f7c707c1f7f485537b46a29
7
+ data.tar.gz: 5b60391374b30970d5599d53e1e8bfb204e1093e5ae22ff5189736fa4f19e65458adc9446fca503c4da4eaf2293ec81b1c04ca0245da4b503f3401df7c2c8f84
@@ -0,0 +1 @@
1
+ repo_token: pA8VrMwrNTyChkaDFsIF08GmfC4a0jIz2
@@ -0,0 +1,4 @@
1
+ GITLAB_API_ENDPOINT=http://example.com/api/v3
2
+ GITLAB_API_PRIVATE_TOKEN=XXXXXXXXXXXXXXXXXXX
3
+ GITLAB_PROJECT_NAME=group/name
4
+ TEMPLATE_FILE=gitlab_mr_release.md.erb
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .env.gitlab
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,25 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
4
+ - 2.2
5
+ - 2.3
6
+ - ruby-head
7
+ cache: bundler
8
+ sudo: false
9
+ before_install: gem install bundler -v 1.10.6
10
+ before_script:
11
+ - export CODECLIMATE_REPO_TOKEN=771643fe0b3a3f2185eacf5fb025ec009d40cab4402d97b83ece04436e5e1739
12
+ - export CI=true
13
+ script:
14
+ - bundle exec rspec
15
+ branches:
16
+ only:
17
+ - master
18
+ notifications:
19
+ email: false
20
+ slack:
21
+ secure: dkjEtoWyHEstKewrX6InD/wym1hmUZMdr/JfSP2HJLWS5U4mWyq8UY3ulvRWgoElKFhEUtQYYTzAp0BwoM4pQ9VdXX+tR0wIg6ETte2uP/ETTv/bZLbCm6ZfD0pk86Wq5NJVAVskwjZcxL3GKYVJz5kru83h7yGGHJ2oxB0ClZLK0DPJSReC7fItzcKHiz0LQe1P26BqOSeRIzTLiJldNiu/tCQyZxN8m5rRiaDfsWxeH0oRnz0VCY8L3ZU0ji5qTXZeE89o+TikL4fNri78bziDRXOiC+PGAsr03F8fNCja6UgofNSRsVkpjkbQhyBnjQJnU4aVzRIOcZDcRXXRvk/VNfvxiodZ8EpEwn9qkjx71rfklTyOj2HMNpuWLeNfFkdnh2qaVOfKAQ/hW0wfStn2Pcxm1mBV0bAFQuon2mXcj+vUYrXo9iHslXlzO6nf/wQR7R6rvqJGgmjSpVomehoR5EllD6AmhaWyboh0i0Kyr6INKzvLtV4bHqaYlZXD931gRXGW0PWHrX8KvXAtYVngjmouJ8Jqu5PdJm2nH0OQMHfwxWbh991gGG76UIga4Pfou+XSxTji3G3T0D1btHvMLpNvx6rfeL+cPXq5LGc2UVf9QEwEwJyKB/i2XjXUNQE4X5yl+rfgky9dWOBu+D8yYxnoUoKYfo1uOg/kns8=
22
+ matrix:
23
+ allow_failures:
24
+ - rvm: ruby-head
25
+ - rvm: 2.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gitlab_mr_release.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 sue445
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # GitlabMrRelease
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gitlab_mr_release`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ [![Build Status](https://travis-ci.org/sue445/gitlab_mr_release.svg?branch=master)](https://travis-ci.org/sue445/gitlab_mr_release)
8
+ [![Code Climate](https://codeclimate.com/github/sue445/gitlab_mr_release/badges/gpa.svg)](https://codeclimate.com/github/sue445/gitlab_mr_release)
9
+ [![Coverage Status](https://coveralls.io/repos/sue445/gitlab_mr_release/badge.svg?branch=master&service=github)](https://coveralls.io/github/sue445/gitlab_mr_release?branch=master)
10
+ [![Dependency Status](https://gemnasium.com/sue445/gitlab_mr_release.svg)](https://gemnasium.com/sue445/gitlab_mr_release)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'gitlab_mr_release'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install gitlab_mr_release
27
+
28
+ ## Usage
29
+
30
+ TODO: Write usage instructions here
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec gitlab_mr_release` to use the gem in this directory, ignoring other installed copies of this gem.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gitlab_mr_release.
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
46
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gitlab_mr_release"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "dotenv"
10
+ Dotenv.load(".env.gitlab", "~/.env.gitlab")
11
+
12
+ clean_room = Object.new
13
+ clean_room.instance_eval do
14
+ @project = GitlabMrRelease::Project.new(
15
+ api_endpoint: ENV["GITLAB_API_ENDPOINT"],
16
+ private_token: ENV["GITLAB_API_PRIVATE_TOKEN"],
17
+ project_name: ENV["GITLAB_PROJECT_NAME"],
18
+ )
19
+ end
20
+
21
+ require "pry"
22
+ Pry.start(clean_room)
@@ -0,0 +1,11 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
8
+ cp .env.gitlab.example .env.gitlab
9
+
10
+ echo ""
11
+ echo "edit .env.gitlab"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "gitlab_mr_release/cli"
4
+ GitlabMrRelease::CLI.start(ARGV)
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gitlab_mr_release/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gitlab_mr_release"
8
+ spec.version = GitlabMrRelease::VERSION
9
+ spec.authors = ["sue445"]
10
+ spec.email = ["sue445@sue445.net"]
11
+
12
+ spec.summary = %q{Release MergeRequest generator for GitLab}
13
+ spec.description = %q{Release MergeRequest generator for GitLab}
14
+ spec.homepage = "https://github.com/sue445/gitlab_mr_release"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "dotenv"
23
+ spec.add_dependency "gitlab"
24
+ spec.add_dependency "thor"
25
+
26
+ spec.add_development_dependency "activesupport"
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "coveralls"
29
+ spec.add_development_dependency "codeclimate-test-reporter"
30
+ spec.add_development_dependency "pry-byebug"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency "webmock"
34
+ end
@@ -0,0 +1,6 @@
1
+ require "gitlab_mr_release/version"
2
+ require "gitlab_mr_release/project"
3
+
4
+ module GitlabMrRelease
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,66 @@
1
+ require "gitlab_mr_release"
2
+ require "thor"
3
+ require "dotenv"
4
+
5
+ module GitlabMrRelease
6
+ class CLI < Thor
7
+ include Thor::Actions
8
+
9
+ GITLAB_ENV_FILES = %w(.env.gitlab ~/.env.gitlab)
10
+
11
+ DEFAULT_TEMPLATE = <<-MARKDOWN
12
+ # MergeRequests
13
+ <% merge_requests.each do |mr| %>
14
+ * [ ] !<%= mr.iid %> <%= mr.title %>
15
+ <% end %>
16
+ MARKDOWN
17
+
18
+ def self.source_root
19
+ "#{__dir__}/../templates"
20
+ end
21
+
22
+ desc "version", "Show gitlab_mr_release version"
23
+ def version
24
+ puts GitlabMrRelease::VERSION
25
+ end
26
+
27
+ desc "init", "Copy setting files to current directory"
28
+ def init
29
+ copy_file ".env.gitlab", ".env.gitlab"
30
+ copy_file "gitlab_mr_release.md.erb", "gitlab_mr_release.md.erb"
31
+ end
32
+
33
+ desc "create", "Create merge requrst"
34
+ option :source, aliases: "-s", required: true, desc: "Source branch (e.g. develop)"
35
+ option :target, aliases: "-t", required: true, desc: "Target branch (e.g. master)"
36
+ option :title, desc: "MergeRequest title (default. 'Release :source -> :target')"
37
+ def create
38
+ title = options[:title] || default_title
39
+
40
+ template =
41
+ if ENV["TEMPLATE_FILE"]
42
+ File.read(ENV["TEMPLATE_FILE"])
43
+ else
44
+ DEFAULT_TEMPLATE
45
+ end
46
+
47
+ project = GitlabMrRelease::Project.new(
48
+ api_endpoint: ENV["GITLAB_API_ENDPOINT"],
49
+ private_token: ENV["GITLAB_API_PRIVATE_TOKEN"],
50
+ project_name: ENV["GITLAB_PROJECT_NAME"],
51
+ )
52
+ project.create_merge_request(
53
+ source_branch: options[:source],
54
+ target_branch: options[:target],
55
+ title: title,
56
+ template: template,
57
+ )
58
+ end
59
+
60
+ private
61
+
62
+ def default_title
63
+ "Release #{options[:source]} -> #{options[:target]}"
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,65 @@
1
+ module GitlabMrRelease
2
+ require "gitlab"
3
+
4
+ class Project
5
+ # @param api_endpoint [String]
6
+ # @param private_token [String]
7
+ # @param project_name [String]
8
+ def initialize(api_endpoint:, private_token:, project_name:)
9
+ Gitlab.configure do |config|
10
+ config.endpoint = api_endpoint
11
+ config.private_token = private_token
12
+ end
13
+ @project_name = project_name
14
+ end
15
+
16
+ def web_url
17
+ @web_url ||= Gitlab.project(escaped_project_name).web_url
18
+ end
19
+
20
+ # find merge requests between from...to
21
+ # @param from [String]
22
+ # @param to [String]
23
+ # @return [Array<Integer>] MergeRequest iids
24
+ def merge_request_iids_between(from, to)
25
+ commits = Gitlab.repo_compare(escaped_project_name, from, to).commits
26
+ commits.map do |commit|
27
+ commit["message"] =~ /^Merge branch .*See merge request \!(\d+)$/m
28
+ $1
29
+ end.compact.map(&:to_i)
30
+ end
31
+
32
+ # find MergeRequest with iid
33
+ def merge_request(iid)
34
+ mr = Gitlab.merge_requests(escaped_project_name, iid: iid).first
35
+ assert_merge_request_iid(mr, iid) if mr
36
+ mr
37
+ end
38
+
39
+ def generate_description(iids, template)
40
+ merge_requests = iids.map { |iid| merge_request(iid) }
41
+ ERB.new(template).result(binding)
42
+ end
43
+
44
+ def create_merge_request(source_branch:, target_branch:, title:, template:)
45
+ iids = merge_request_iids_between(target_branch, source_branch)
46
+ options = {
47
+ source_branch: source_branch,
48
+ target_branch: target_branch,
49
+ description: generate_description(iids, template),
50
+ }
51
+ Gitlab.create_merge_request(escaped_project_name, title, options)
52
+ end
53
+
54
+ private
55
+
56
+ def escaped_project_name
57
+ CGI.escape(@project_name)
58
+ end
59
+
60
+ def assert_merge_request_iid(mr, iid)
61
+ # NOTE: MR is found, but server is old GitLab?
62
+ raise "MergeRequest iid does not match (expected #{iid}, but #{mr.iid})" unless iid == mr.iid
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module GitlabMrRelease
2
+ VERSION = "0.1.0.beta1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # MergeRequests
2
+ <% merge_requests.each do |mr| %>
3
+ * [ ] !<%= mr.iid %> <%= mr.title %>
4
+ <% end %>
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitlab_mr_release
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - sue445
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gitlab
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: webmock
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Release MergeRequest generator for GitLab
168
+ email:
169
+ - sue445@sue445.net
170
+ executables:
171
+ - gitlab_mr_release
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".coveralls.yml"
176
+ - ".env.gitlab.example"
177
+ - ".gitignore"
178
+ - ".rspec"
179
+ - ".travis.yml"
180
+ - Gemfile
181
+ - LICENSE.txt
182
+ - README.md
183
+ - Rakefile
184
+ - bin/console
185
+ - bin/setup
186
+ - exe/gitlab_mr_release
187
+ - gitlab_mr_release.gemspec
188
+ - lib/gitlab_mr_release.rb
189
+ - lib/gitlab_mr_release/cli.rb
190
+ - lib/gitlab_mr_release/project.rb
191
+ - lib/gitlab_mr_release/version.rb
192
+ - lib/templates/.env.gitlab
193
+ - lib/templates/gitlab_mr_release.md.erb
194
+ homepage: https://github.com/sue445/gitlab_mr_release
195
+ licenses:
196
+ - MIT
197
+ metadata: {}
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">"
210
+ - !ruby/object:Gem::Version
211
+ version: 1.3.1
212
+ requirements: []
213
+ rubyforge_project:
214
+ rubygems_version: 2.4.5.1
215
+ signing_key:
216
+ specification_version: 4
217
+ summary: Release MergeRequest generator for GitLab
218
+ test_files: []