bitbucket_pr 0.1.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 98a4ee867e83674ad6b8b3925f41aaf11bab57d864d79fb0398e54c085f8129c
4
+ data.tar.gz: d688a8f307daac192a7e8a5e1516cce435494c7c0e641ee7a326b897b97cdc8d
5
+ SHA512:
6
+ metadata.gz: db437459b1ba89c8cb396661d823e874c8776b8b6dfc3c7e510261dbaf33411191e66b4a3a679b61caadefda6eb8fc5e3abc883bdd6108ddaf398bf2f7e4e512
7
+ data.tar.gz: d9c0cd4cf563a41ae355a8b55a5e4b61b97c73315a60a9817fbc507b9e93bdce8472118c4180a83097ad01617510c16af07128bcb757f06001573cc5d90639d5
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,171 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ DisplayCopNames: true
4
+ DisabledByDefault: true
5
+
6
+ # Prefer &&/|| over and/or.
7
+ Style/AndOr:
8
+ Enabled: true
9
+
10
+ # Do not use braces for hash literals when they are the last argument of a
11
+ # method call.
12
+ Style/BracesAroundHashParameters:
13
+ Enabled: true
14
+ EnforcedStyle: context_dependent
15
+
16
+ # Align `when` with `case`.
17
+ Layout/CaseIndentation:
18
+ Enabled: true
19
+
20
+ # Align comments with method definitions.
21
+ Layout/CommentIndentation:
22
+ Enabled: true
23
+
24
+ Layout/EmptyLineAfterMagicComment:
25
+ Enabled: true
26
+
27
+ # In a regular class definition, no empty lines around the body.
28
+ Layout/EmptyLinesAroundClassBody:
29
+ Enabled: true
30
+
31
+ # In a regular method definition, no empty lines around the body.
32
+ Layout/EmptyLinesAroundMethodBody:
33
+ Enabled: true
34
+
35
+ # In a regular module definition, no empty lines around the body.
36
+ Layout/EmptyLinesAroundModuleBody:
37
+ Enabled: true
38
+
39
+ Layout/FirstParameterIndentation:
40
+ Enabled: true
41
+
42
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
43
+ Style/HashSyntax:
44
+ Enabled: true
45
+
46
+ # Method definitions after `private` or `protected` isolated calls need one
47
+ # extra level of indentation.
48
+ Layout/IndentationConsistency:
49
+ Enabled: true
50
+ EnforcedStyle: normal
51
+
52
+ # Two spaces, no tabs (for indentation).
53
+ Layout/IndentationWidth:
54
+ Enabled: true
55
+
56
+ Layout/SpaceAfterColon:
57
+ Enabled: true
58
+
59
+ Layout/SpaceAfterComma:
60
+ Enabled: true
61
+
62
+ Layout/SpaceAroundEqualsInParameterDefault:
63
+ Enabled: true
64
+
65
+ Layout/SpaceAroundKeyword:
66
+ Enabled: true
67
+
68
+ Layout/SpaceAroundOperators:
69
+ Enabled: true
70
+
71
+ Layout/SpaceBeforeFirstArg:
72
+ Enabled: true
73
+
74
+ # Defining a method with parameters needs parentheses.
75
+ Style/MethodDefParentheses:
76
+ Enabled: true
77
+
78
+ # VuDo: Enable this when confident about all test coverage
79
+ Style/FrozenStringLiteralComment:
80
+ Enabled: false
81
+ EnforcedStyle: always
82
+
83
+ # Use `foo {}` not `foo{}`.
84
+ Layout/SpaceBeforeBlockBraces:
85
+ Enabled: true
86
+
87
+ # Use `foo { bar }` not `foo {bar}`.
88
+ Layout/SpaceInsideBlockBraces:
89
+ Enabled: true
90
+
91
+ # Use `{ a: 1 }` not `{a:1}`.
92
+ Layout/SpaceInsideHashLiteralBraces:
93
+ Enabled: true
94
+
95
+ Layout/SpaceInsideParens:
96
+ Enabled: true
97
+
98
+ # Check quotes usage according to lint rule below.
99
+ Style/StringLiterals:
100
+ Enabled: true
101
+ EnforcedStyle: double_quotes
102
+
103
+ # Detect hard tabs, no hard tabs.
104
+ Layout/Tab:
105
+ Enabled: true
106
+
107
+ # Blank lines should not have any spaces.
108
+ Layout/TrailingBlankLines:
109
+ Enabled: true
110
+
111
+ # No trailing whitespace.
112
+ Layout/TrailingWhitespace:
113
+ Enabled: true
114
+
115
+ # Use quotes for string literals when they are enough.
116
+ Style/UnneededPercentQ:
117
+ Enabled: true
118
+
119
+ # Align `end` with the matching keyword or starting expression except for
120
+ # assignments, where it should be aligned with the LHS.
121
+ Lint/EndAlignment:
122
+ Enabled: true
123
+ EnforcedStyleAlignWith: variable
124
+
125
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
126
+ Lint/RequireParentheses:
127
+ Enabled: true
128
+
129
+ # CMG Rules
130
+ Rails:
131
+ Enabled: true
132
+
133
+ Bundler:
134
+ Enabled: true
135
+
136
+ Security:
137
+ Enabled: true
138
+
139
+ Style/Documentation:
140
+ Description: 'Document classes and non-namespace modules.'
141
+ Enabled: false
142
+
143
+ Style/MethodCalledOnDoEndBlock:
144
+ Enabled: true
145
+
146
+ Style/CollectionMethods:
147
+ Enabled: true
148
+
149
+ Style/SymbolArray:
150
+ Description: 'Use %i or %I for arrays of symbols.'
151
+ Enabled: true
152
+
153
+ Metrics/LineLength:
154
+ Description: 'Limit lines to 120 characters.'
155
+ Enabled: true
156
+ Max: 120
157
+ Exclude:
158
+ - 'spec/**/*.rb'
159
+
160
+ Lint/AmbiguousBlockAssociation:
161
+ Enabled: false
162
+
163
+ Style/RescueStandardError:
164
+ Enabled: false
165
+
166
+ Layout/AlignParameters:
167
+ Enabled: true
168
+ EnforcedStyle: with_fixed_indentation
169
+ SupportedStyles:
170
+ - with_first_parameter
171
+ - with_fixed_indentation
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dachinat@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bitbucket_pr.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bitbucket_pr (0.1.0)
5
+ commander (~> 4.4)
6
+ faraday (~> 0.15)
7
+ growl (~> 1.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.0)
13
+ commander (4.4.7)
14
+ highline (~> 2.0.0)
15
+ diff-lcs (1.3)
16
+ faraday (0.15.3)
17
+ multipart-post (>= 1.2, < 3)
18
+ growl (1.0.3)
19
+ highline (2.0.0)
20
+ jaro_winkler (1.5.1)
21
+ multipart-post (2.0.0)
22
+ parallel (1.12.1)
23
+ parser (2.5.3.0)
24
+ ast (~> 2.4.0)
25
+ powerpack (0.1.2)
26
+ rainbow (3.0.0)
27
+ rake (10.5.0)
28
+ rspec (3.8.0)
29
+ rspec-core (~> 3.8.0)
30
+ rspec-expectations (~> 3.8.0)
31
+ rspec-mocks (~> 3.8.0)
32
+ rspec-core (3.8.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-expectations (3.8.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.8.0)
37
+ rspec-mocks (3.8.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.8.0)
40
+ rspec-support (3.8.0)
41
+ rubocop (0.60.0)
42
+ jaro_winkler (~> 1.5.1)
43
+ parallel (~> 1.10)
44
+ parser (>= 2.5, != 2.5.1.1)
45
+ powerpack (~> 0.1)
46
+ rainbow (>= 2.2.2, < 4.0)
47
+ ruby-progressbar (~> 1.7)
48
+ unicode-display_width (~> 1.4.0)
49
+ ruby-progressbar (1.10.0)
50
+ unicode-display_width (1.4.0)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ bitbucket_pr!
57
+ bundler (~> 1.16)
58
+ rake (~> 10.0)
59
+ rspec (~> 3.0)
60
+ rubocop (~> 0.59)
61
+
62
+ BUNDLED WITH
63
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Dachi Natsvlishvili
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.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # BitbucketPr
2
+
3
+ Gem is useful to submit pull-requests to Attlasian Bitbucket through CLI command __if you don't like to open new browser tab__
4
+
5
+ ![](http://www.quickmeme.com/img/78/7802c0254fca6dc4b3ee20300007dc8aa4164ac99b466f66bb9fb84befec097a.jpg)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ $ gem install bitbucket_pr
11
+ ```
12
+
13
+ ## Aliasing
14
+
15
+ This is optional you can always use `$ bitbucket_pr` as an executable,
16
+ but we'll be using `$ git pr` instead.
17
+
18
+ Create bash executable named `git-pr` with following snippet:
19
+
20
+ ```bash
21
+ #!/bin/bash
22
+ bitbucket_pr "$@"
23
+ ```
24
+
25
+ and add this to your path. On macOS you can place this in `~/bin`
26
+
27
+ ## Usage
28
+
29
+ `source` `destination` and `title` are required options.
30
+
31
+ `username` `password` and `repository name` are also required, but can be saved for future.
32
+
33
+ #### Minimal setup
34
+
35
+ ```
36
+ $ git pr [source] [destination] -t[title] -a[username:password]`
37
+ ```
38
+
39
+ example:
40
+ ```
41
+ $ git pr middleware-patch master -rdachinat/rack_pg -adachinat:3Edm$51dd2 -t'Patching a middleware'
42
+ ```
43
+
44
+ you can use `--title="Patching a middelware" --auth="username:password"` style if you want
45
+
46
+ #### Save credentials and repository name
47
+
48
+ ##### Warning: this will create file containing your encrypted password. Use at your own risks!
49
+
50
+ ```
51
+ $ git pr configure -u[username] -p[password] -r[repository_name]
52
+ ```
53
+
54
+ Repository name has to be in `username/repository` format
55
+
56
+ example:
57
+
58
+ ```
59
+ $ git pr configure -udachinat -p3Edm$51dd2 -rdachinat/rack_pg
60
+ ```
61
+
62
+ Once you have credentials stored, you can skip `-r` and `-a` options
63
+
64
+ #### More options
65
+
66
+ * `-d` `--d` - Optional PR description
67
+ * `--reviewers` - Optional reviewer username array (i.e.: --reviewers="reviewer1, reviewer2")
68
+ * `-c` `--close` - Optional close flag / close branch after PR is merged or not
69
+
70
+ #### Help
71
+
72
+ You can always use `git pr help` for further help 😄
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dachinat/bitbucket_pr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
81
+
82
+ ## Code of Conduct
83
+
84
+ Everyone interacting in the BitbucketPr project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dachinat/bitbucket_pr/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bitbucket_pr"
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
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bitbucket_pr/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bitbucket_pr"
8
+ spec.version = BitbucketPr::VERSION
9
+ spec.authors = ["Dachi Natsvlishvili"]
10
+ spec.email = ["dachinat@gmail.com"]
11
+
12
+ spec.summary = "Create BitBucket PR with single CLI command"
13
+ spec.description = "Gem uses Bitbucket API endpoint to create a new pull-reqeust"
14
+ spec.homepage = "https://github.com/dachinat/bitbucket_pr"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "rubocop", "~> 0.59"
37
+
38
+ spec.add_dependency "commander", "~> 4.4"
39
+ spec.add_dependency "faraday", "~> 0.15"
40
+ spec.add_dependency "growl", "~> 1.0"
41
+ end
data/exe/bitbucket_pr ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bitbucket_pr"
4
+ require "rubygems"
5
+ require "commander/import"
6
+
7
+ program :name, "bitbucket_pr"
8
+ program :version, BitbucketPr::VERSION
9
+ program :description, "Create Bitbucket PR using CLI command"
10
+ default_command :create
11
+
12
+ command :create do |c|
13
+ c.syntax = "bitbucket_pr [create] [source branch] [destination branch]"
14
+ c.option "-r STRING", "--repository STRING", String, "Your Bitbucket repository"
15
+ c.option "--auth STRING", String, "Your Bitbucket username:password"
16
+ c.option "--title STRING", String, "Your PR title"
17
+ c.option "--description STRING", String, "Your PR description"
18
+ c.option "--close", "Close Source Branch"
19
+ c.option "--reviewers Array", Array, "PR reviewer usernames"
20
+ c.summary = "Creates a new pull request with specified parameters"
21
+ c.description = c.summary
22
+ c.example "description", c.syntax
23
+ c.action do |_args, _options|
24
+ config = BitbucketPr.read
25
+
26
+ _options.default \
27
+ close: false,
28
+ repository: config&.[](:repository) || nil,
29
+ auth: config ? "#{config[:username]}:#{config[:password]}" : nil
30
+
31
+ unless _args[0] && _args[1]
32
+ (color("No source and destination branches given. See 'create --help'", :red); exit(1))
33
+ end
34
+
35
+ unless _options.repository
36
+ (color("No repository given. Either use '-r your_repository' or see 'configure --help'", :red); exit(1))
37
+ end
38
+
39
+ unless _options.auth
40
+ color("No authorization credentials. Either use '--auth=username:password' or see 'configure --help'", :red)
41
+ exit(1)
42
+ else
43
+ unless _options.auth =~ /^.+\:.+$/
44
+ (color("--auth value is not well-formated use 'your_username:your_password style'", :red); exit(1))
45
+ end
46
+ end
47
+
48
+ (color("No PR title given. Use '--title option'", :red); exit(1)) unless _options.title
49
+
50
+ BitbucketPr.create(_args[0], _args[1], _options)
51
+ end
52
+ end
53
+
54
+ command :configure do |c|
55
+ c.syntax = "bitbucket_pr configure --username=[username] --password=[password]"
56
+ c.option "--username STRING", String, "Your Bitbucket username"
57
+ c.option "--password STRING", String, "Your Bitbucket password"
58
+ c.option "--repository STRING", String, "Your Bitbucket repository (username/repo)"
59
+ c.summary = "Creates a new pull request with specified parameters"
60
+ c.description = c.summary
61
+ c.example "Saves username, password and repo. for future use", c.syntax
62
+ c.action do |_args, _options|
63
+ username = _options.username
64
+ password = _options.password
65
+ repository = _options.repository
66
+ (color("No --username specified", :red); exit(1)) unless username
67
+ (color("No --password specified", :red); exit(1)) unless password
68
+ (color("No --repository specified", :red); exit(1)) unless repository
69
+ BitbucketPr.write(username: username, password: password, repository: repository)
70
+ color "Password for your Bitbucket account '#{username}' and repository were saved!", :green
71
+ end
72
+ end
@@ -0,0 +1,34 @@
1
+ require "openssl"
2
+ require "yaml"
3
+
4
+ module BitbucketPr
5
+ HOMES = ["HOME", "HOMEPATH"]
6
+ FILE_NAME = ".bitbucket_pr"
7
+
8
+ class << self
9
+ def home; ENV[HOMES.find { |h| ENV[h] != nil }]; end
10
+
11
+ def file; File.join(home, FILE_NAME); end
12
+
13
+ def write(credentials)
14
+ begin
15
+ credentials[:password] = [credentials[:password]].pack("u")
16
+ File.open(file, "w") { |file| file.write(credentials.to_yaml) }
17
+ rescue => e
18
+ say("Internal error: " + e.message)
19
+ false
20
+ end
21
+ end
22
+
23
+ def read
24
+ begin
25
+ credentials = YAML.safe_load(File.read(file), [Symbol])
26
+ credentials[:password] = credentials[:password].unpack("u")[0]
27
+ credentials
28
+ rescue => e
29
+ say("Internal error: " + e.message)
30
+ nil
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module BitbucketPr
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,60 @@
1
+ require "bitbucket_pr/system"
2
+ require "bitbucket_pr/version"
3
+ require "faraday"
4
+ require "json"
5
+ require "growl"
6
+
7
+ module BitbucketPr
8
+ def self.create(source, destination, options)
9
+ auth_match = options.auth.match(":")
10
+ conn = Faraday.new(url: "https://bitbucket.org")
11
+ conn.basic_auth(auth_match.pre_match, auth_match.post_match)
12
+
13
+ res = conn.post do |req|
14
+ req.url "/api/2.0/repositories/#{options.repository}/pullrequests"
15
+ req.headers["Content-Type"] = "application/json"
16
+ req.body = {
17
+ source: {
18
+ branch: {
19
+ name: source
20
+ }
21
+ },
22
+ destination: {
23
+ branch: {
24
+ name: destination
25
+ }
26
+ },
27
+ repository: {
28
+ full_name: options.repository
29
+ },
30
+ title: options.title
31
+ }
32
+
33
+ req.body.merge!(close_source_branch: options.close) if options.close
34
+
35
+ if options.reviewers
36
+ reviewers = []
37
+ options.reviewers.each { |r| reviewers << { username: r } }
38
+ req.body.merge!(reviewers: reviewers)
39
+ end
40
+
41
+ req.body[:description] = options.description if options.description
42
+
43
+ req.body = req.body.to_json
44
+ end
45
+
46
+ say res.reason_phrase
47
+
48
+ if res.reason_phrase == "Created"
49
+ notify_ok "PR Created"
50
+ else
51
+ notify_error "PR not created"
52
+ end
53
+
54
+ begin
55
+ body = JSON.parse(res.body)
56
+ color("Failed: " + body["error"]["message"], :red) if (body["type"] == "error")
57
+ rescue
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitbucket_pr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dachi Natsvlishvili
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.59'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.59'
69
+ - !ruby/object:Gem::Dependency
70
+ name: commander
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.15'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.15'
97
+ - !ruby/object:Gem::Dependency
98
+ name: growl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ description: Gem uses Bitbucket API endpoint to create a new pull-reqeust
112
+ email:
113
+ - dachinat@gmail.com
114
+ executables:
115
+ - bitbucket_pr
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - ".travis.yml"
123
+ - CODE_OF_CONDUCT.md
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - bin/console
130
+ - bin/setup
131
+ - bitbucket_pr.gemspec
132
+ - exe/bitbucket_pr
133
+ - lib/bitbucket_pr.rb
134
+ - lib/bitbucket_pr/system.rb
135
+ - lib/bitbucket_pr/version.rb
136
+ homepage: https://github.com/dachinat/bitbucket_pr
137
+ licenses:
138
+ - MIT
139
+ metadata:
140
+ allowed_push_host: https://rubygems.org
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.7.6
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Create BitBucket PR with single CLI command
161
+ test_files: []