git-remote-parser 1.0.0

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: 35a186e12b3e7fbee2d304e6afc08ddaa8077ef0
4
+ data.tar.gz: f63e474cd2db7834cb560d9ac84fb1ea7b117560
5
+ SHA512:
6
+ metadata.gz: 69b3fc93c44c5050fe80a82464cfc1a7ec47d024b0fe881cd6bcb5bd57e9f0e6328ac89a130c0ddad5594d79a8c98b9b2602a86a7406a546d39f8b3b50d8aa45
7
+ data.tar.gz: 95e6d7a590f9933626e667c8e9a7cdd8237cc6a1bed391cc686162317157c8006567d2e78eeca69001b62cbce92a92c3a25e25d372a9cd18e6fc39791f2dea8b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.1
6
+ - 2.2.5
7
+ - 2.1
8
+ - 2.0
9
+ - ruby-head
10
+ matrix:
11
+ fast_finish: true
12
+ allow_failures:
13
+ - rvm: ruby-head
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.0.0 - 2016.07.12
4
+
5
+ Init v1.0.0 :tada:.
@@ -0,0 +1,30 @@
1
+ # Contributing
2
+
3
+ First, thank you for contributing!
4
+
5
+ Here are a few technical guidelines to follow:
6
+
7
+ 0. Open an [issue][] to discuss a new feature
8
+ 0. Write tests
9
+ 0. Make sure the entire test suite passes locally and on CI
10
+ 0. Open a Pull Request
11
+ 0. [Squash your commits][squash] after receiving feedback
12
+ 0. Party!
13
+
14
+ [issue]: https://github.com/juanitofatas/git-remote-parser/issues
15
+ [squash]: https://github.com/thoughtbot/guides/tree/master/protocol/git#write-a-feature
16
+
17
+ ## Development
18
+
19
+ After checking out the repo, run `bin/setup` to install dependencies.
20
+ Run `bin/hack` for an interactive prompt that will allow you to experiment.
21
+ To install this gem onto your local machine, run `bundle exec rake install`.
22
+
23
+ ## Testing
24
+
25
+ 0. Set up your `development` environment as per above.
26
+ 0. Run `rake` to execute the full test suite.
27
+
28
+ ## Release
29
+
30
+ 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).
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in git-remote-parser.gemspec
4
+ gemspec
5
+
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "pry"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 JuanitoFatas
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,88 @@
1
+ # Git::Remote::Parser
2
+
3
+ [![Build Status](https://travis-ci.org/JuanitoFatas/git-remote-parser.svg?branch=master)][travis]
4
+
5
+ [travis]: https://travis-ci.org/JuanitoFatas/git-remote-parser
6
+
7
+ ## Usage
8
+
9
+ This gem can parse remote urls into `Git::Remote::Parser::Result` object:
10
+
11
+ ```ruby
12
+ > parser = Git::Remote::Parser.new
13
+ => #<Git::Remote::Parser:0x007ffd5c0d4718>
14
+
15
+ > result = parser.parse "git@github.com:torvalds/linux.git"
16
+ => #<Git::Remote::Parser::Result:0x007fb11b82fc70 @protocol=nil, @username="git", @host="github.com", @owner="torvalds", @repo="linux", @html_url="https://github.com/torvalds/linux">
17
+
18
+ > result.host
19
+ => "github.com"
20
+
21
+ > result.owner
22
+ => "torvalds"
23
+
24
+ > result.repo
25
+ => "linux"
26
+
27
+ > result.html_url
28
+ => "https://github.com/torvalds/linux"
29
+
30
+ > result.to_h
31
+ => {:protocol=>nil, :username=>"git", :host=>"github.com", :owner=>"torvalds", :repo=>"linux", :html_url=>"https://github.com/torvalds/linux"}
32
+ ```
33
+
34
+ Tested work for these Git providers:
35
+
36
+ * [GitHub][github]
37
+
38
+ Examples:
39
+
40
+ - `https://github.com/torvalds/linux.git`
41
+ - `git@github.com:torvalds/linux.git`
42
+
43
+ * [Gitlab][gitlab]
44
+
45
+ Examples:
46
+
47
+ - `https://gitlab.com/gitlab-org/gitlab-ce.git`
48
+ - `git@gitlab.com:gitlab-org/gitlab-ce.git`
49
+
50
+ * [Bitbucket][bitbucket]
51
+
52
+ Examples:
53
+
54
+ - `https://JuanitoFatas@bitbucket.org/ged/ruby-pg`
55
+ - `ssh://hg@bitbucket.org/ged/ruby-pg`
56
+ - and legacy host `bitbucket.com`
57
+
58
+ [github]: https://github.com
59
+ [gitlab]: https://gitlab.com
60
+ [bitbucket]: https://bitbucket.org
61
+
62
+ ## Installation
63
+
64
+ Add this line to your application's Gemfile:
65
+
66
+ ```ruby
67
+ gem 'git-remote-parser'
68
+
69
+ # or double quote if you prefer:
70
+
71
+ gem "git-remote-parser"
72
+ ```
73
+
74
+ And then execute:
75
+
76
+ $ bundle
77
+
78
+ Or install it yourself as:
79
+
80
+ $ gem install git-remote-parser
81
+
82
+ ## Contributing
83
+
84
+ See [CONTRIBUTING.md](/CONTRIBUTING.md)
85
+
86
+ ## License
87
+
88
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -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,19 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "git/remote/parser/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git-remote-parser"
8
+ spec.version = Git::Remote::Parser::VERSION
9
+ spec.authors = ["JuanitoFatas"]
10
+ spec.email = ["katehuang0320@gmail.com"]
11
+
12
+ spec.summary = %q{Parse Git Remote URI into Useful object.}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/JuanitoFatas/git-remote-parser"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|bin)/}) }
18
+ spec.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,54 @@
1
+ require "git/remote/parser/version"
2
+
3
+ module Git
4
+ module Remote
5
+ class Parser
6
+ class Result
7
+ attr_reader :protocol, :username, :host, :owner, :repo, :html_url
8
+
9
+ def initialize(protocol, username, host, owner, repo, html_url)
10
+ @protocol = protocol
11
+ @username = username
12
+ @host = host
13
+ @owner = owner
14
+ @repo = repo
15
+ @html_url = html_url
16
+ end
17
+
18
+ def to_h
19
+ {
20
+ protocol: protocol,
21
+ username: username,
22
+ host: host,
23
+ owner: owner,
24
+ repo: repo,
25
+ html_url: html_url,
26
+ }
27
+ end
28
+ end
29
+
30
+ REGEXP = %r(
31
+ (?<protocol>(http://|https://|git://|ssh://))*
32
+ (?<username>[^@]+@)*
33
+ (?<host>[^/]+)
34
+ [/:]
35
+ (?<owner>[^/]+)
36
+ /
37
+ (?<repo>[^/.]+)
38
+ )x
39
+
40
+ def parse(remote_uri)
41
+ if matched = remote_uri.match(REGEXP)
42
+ Result.new(
43
+ matched[:protocol],
44
+ matched[:username] && matched[:username].delete("@".freeze),
45
+ matched[:host],
46
+ matched[:owner],
47
+ matched[:repo],
48
+ File.join("https://#{matched[:host]}", matched[:owner],matched[:repo]),
49
+ )
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,7 @@
1
+ module Git
2
+ module Remote
3
+ class Parser
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-remote-parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - JuanitoFatas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Parse Git Remote URI into Useful object.
14
+ email:
15
+ - katehuang0320@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - CHANGELOG.md
24
+ - CONTRIBUTING.md
25
+ - Gemfile
26
+ - LICENSE
27
+ - README.md
28
+ - Rakefile
29
+ - git-remote-parser.gemspec
30
+ - lib/git/remote/parser.rb
31
+ - lib/git/remote/parser/version.rb
32
+ homepage: https://github.com/JuanitoFatas/git-remote-parser
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 2.6.4
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Parse Git Remote URI into Useful object.
56
+ test_files: []
57
+ has_rdoc: