open_git 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6bb8fffc5ee5273d02d2a2a07f23c2af921f8123
4
+ data.tar.gz: fc781fe6cbf605cd23f3412573dbe955999e2370
5
+ SHA512:
6
+ metadata.gz: 70a3893363907baf007ca7a5d4c37a71fd5192cb4df245cc5ac40ef6f210e3e1b0e4ac0c1b450ebe9f40020a72dc28fb1b90af10e6a45900feb75405891029e6
7
+ data.tar.gz: feef97af3de291776a7d5a77880fe9f6c009ec332d82038cfe6067530ea316b72392d1659c062db7aee1ef818aad9432445941c9450fc3f9def524c1e90df686
data/bin/ogh ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
3
+
4
+ require 'rubygems'
5
+ require 'open_git'
6
+
7
+ if ARGV.size > 1
8
+ puts "usage: ogh [<branch>]"
9
+ else
10
+ begin
11
+ system "open #{OpenGit::Open.github ARGV[0]}"
12
+ rescue OpenGit::Git::NoGitRepoError
13
+ puts "ogh: No git repo found. Please use ogh in a git repo."
14
+ end
15
+ end
data/bin/opr ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
3
+
4
+ require 'rubygems'
5
+ require 'open_git'
6
+
7
+ if ARGV.size > 1
8
+ puts "usage: opr [<branch>]"
9
+ else
10
+ begin
11
+ system "open #{OpenGit::Open.github_pull_request ARGV[0]}"
12
+ rescue OpenGit::Git::NoGitRepoError
13
+ puts "opr: No git repo found. Please use opr in a git repo."
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ module OpenGit
2
+ module Git
3
+ class NoGitRepoError < StandardError
4
+ end
5
+
6
+ class InvalidRemoteError < StandardError
7
+ end
8
+
9
+ # asserting that rest of git commands will work
10
+ def self.is_git_repo
11
+ # only returns true if in git repo and not in the .git folder itself
12
+ `git rev-parse --is-inside-work-tree`.strip == "true"
13
+ end
14
+
15
+ def self.remote_url(remote_name)
16
+ `git ls-remote --get-url #{remote_name}`.strip
17
+ end
18
+
19
+ def self.url(name = nil)
20
+ remote_name = name || self.remote
21
+ url = self.remote_url(remote_name)
22
+ # git returns the remote id instead of link if it is not valid
23
+ raise OpenGit::Git::InvalidRemoteError if url == remote_name
24
+ url
25
+ end
26
+
27
+ def self.remote
28
+ lines = `git remote`.lines
29
+ lines[-1].strip
30
+ end
31
+
32
+ def self.branch
33
+ return `git rev-parse --abbrev-ref HEAD`.strip
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,24 @@
1
+ module OpenGit
2
+ module Github
3
+ class InvalidLinkError < StandardError
4
+ end
5
+
6
+ def self.parse(link)
7
+ re = /^((git@)|(https?:\/\/))(.*)[\/:]([^:\/]*)\/([^:\/]*)\.git$/
8
+ match = re.match(link)
9
+ raise OpenGit::Github::InvalidLinkError unless match
10
+ return {
11
+ protocol: if match[2]
12
+ "ssh"
13
+ elsif match[3] == "https://"
14
+ "https"
15
+ elsif match[3] == "http://"
16
+ "http"
17
+ end,
18
+ domain: match[4],
19
+ org: match[5],
20
+ repo: match[6]
21
+ }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module OpenGit
2
+ module Open
3
+ def self.github(remote = nil)
4
+ raise OpenGit::Git::NoGitRepoError unless OpenGit::Git.is_git_repo
5
+ match = OpenGit::Github.parse(OpenGit::Git.url(remote))
6
+ protocol = match[:protocol]
7
+ protocol = "https" if protocol == "ssh"
8
+ "#{protocol}://#{match[:domain]}/#{match[:org]}/#{match[:repo]}"
9
+ end
10
+
11
+ def self.github_pull_request(remote = nil)
12
+ "#{self.github(remote)}/pull/#{OpenGit::Git.branch}"
13
+ end
14
+
15
+ end
16
+ end
data/lib/open_git.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "open_git/git"
2
+ require "open_git/github"
3
+ require "open_git/open"
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open_git
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Peng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Command line utility for opening web pages for repository management
14
+ services
15
+ email: kevin@kpeng.ca
16
+ executables:
17
+ - opr
18
+ - ogh
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/ogh
23
+ - bin/opr
24
+ - lib/open_git.rb
25
+ - lib/open_git/git.rb
26
+ - lib/open_git/github.rb
27
+ - lib/open_git/open.rb
28
+ homepage: http://rubygems.org/gems/open_git
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.5.2
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Command line utility for opening a repository's remote web page on github-style
52
+ repository management services and for opening pull requests using the corresponding
53
+ web interface
54
+ test_files: []