pj 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 648b80b572e8bbac2b0885f3a80581099ffddce1
4
+ data.tar.gz: dd0128ec499965cf17e090955c9794ec0fae2fcc
5
+ SHA512:
6
+ metadata.gz: 82ca0b8d570f3b1c3cac7c9d5e5f78fa83daa8d22eb3eb6a11cb4babe6257709ee54c736f5c38ef4761fcf32f493e2d2e5d037ae2340583946bb464d62f4aeb5
7
+ data.tar.gz: 7c237037ad8202bb2b89bbf4fe6cdcbb0e2b75f415e94915041e839c05a80df58746ded2102fb7f62202a27a56e9b9c99620d1dfef16285a326ca1d6e5199c3c
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Pj
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'pj'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pj
18
+
19
+ ## Usage
20
+
21
+ ### sync
22
+ Syncing a fork from upstream with [the following instruction](https://help.github.com/articles/syncing-a-fork/)
23
+
24
+ $ pj project-name-in-config-file sync
25
+
26
+ ### push
27
+ Runs git push origin master
28
+
29
+ $ pj project-name push
30
+
31
+ ### owner
32
+ Assuming you have upstream, pushes to both upstream and origin
33
+
34
+ $ pj project owner
35
+
36
+ ### cd
37
+ Copy to cliboard `cd project-directory-name` command.
38
+
39
+ $ pj project cd
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/[my-github-username]/pj/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pj"
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
data/bin/pj ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path("../../lib", __FILE__)
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
+
5
+ require "pj/runner"
6
+
7
+ Pj::Runner.start
data/lib/pj/base.rb ADDED
@@ -0,0 +1,64 @@
1
+ require "thor"
2
+ require "clipboard"
3
+ require "pj"
4
+
5
+ module Pj
6
+ class Base < Thor
7
+ desc "sync", "git fetch upstream and merge upstream/master"
8
+ option aliases: :s
9
+ def sync(project = nil)
10
+ project = my_class_name if project.nil?
11
+ repo = Pj::Git.new project
12
+ if repo.upstream?
13
+ repo.git "fetch upstream"
14
+ repo.check_commit
15
+ repo.git "merge upstream/master"
16
+ else
17
+ puts "Nothing to do. You don't have any upstream to sync"
18
+ end
19
+ end
20
+
21
+ desc "push", "git push origin [branch]"
22
+ option aliases: :p
23
+ def push(project = nil, branch = "master")
24
+ project = my_class_name if project.nil?
25
+ repo = Pj::Git.new project
26
+ repo.check_commit
27
+ repo.push("origin", branch)
28
+ end
29
+
30
+ desc "owner", "git push origin and upstream [branch]"
31
+ option aliases: :o
32
+ def owner(project = nil, branch = "master")
33
+ project = my_class_name if project.nil?
34
+ repo = Pj::Git.new project
35
+ if repo.upstream? && repo.origin?
36
+ repo.check_commit
37
+ repo.push("origin", branch)
38
+ repo.push("upstream", branch)
39
+ else
40
+ puts "Nothing to do. You don't have origin && upstream"
41
+ end
42
+ end
43
+
44
+ desc "cd", "copys cd to-repository command to clipboard"
45
+ def cd(project = nil)
46
+ project = my_class_name if project.nil?
47
+ repo_dir = repository(project)
48
+ cmd = "cd #{repo_dir}"
49
+ Clipboard.copy cmd
50
+ puts "#{cmd} copied to your clipboard. Paste and change directory"
51
+ cmd
52
+ end
53
+
54
+ private
55
+
56
+ def my_class_name
57
+ self.class.name.downcase.split("::").last
58
+ end
59
+
60
+ def repository(project)
61
+ Pj::Config.repository project
62
+ end
63
+ end
64
+ end
data/lib/pj/config.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "json"
2
+
3
+ module Pj
4
+ class Config
5
+ class << self
6
+ def instance
7
+ @instance ||= new
8
+ end
9
+
10
+ def repository(name)
11
+ instance.repository name
12
+ end
13
+
14
+ def projects
15
+ instance.projects
16
+ end
17
+ end
18
+
19
+ def initialize
20
+ @config = load_config
21
+ end
22
+
23
+ def repository(name)
24
+ return nil unless @config.key?("repository")
25
+ @config["repository"].fetch(name, nil)
26
+ end
27
+
28
+ def projects
29
+ @config["repository"].keys
30
+ end
31
+
32
+ def load_config
33
+ JSON.load(File.read(config_file_name))
34
+ end
35
+
36
+ def config_file_name
37
+ File.join ENV["HOME"], "pj.json"
38
+ end
39
+ end
40
+ end
data/lib/pj/git.rb ADDED
@@ -0,0 +1,53 @@
1
+ require "pj"
2
+
3
+ module Pj
4
+ class Git
5
+ def initialize(repo_name)
6
+ @repo = Pj::Config.repository(repo_name)
7
+ end
8
+
9
+ def needs_commit?
10
+ status_short.empty? ? false : true
11
+ end
12
+
13
+ def upstream?
14
+ msg = git "remote --verbose"
15
+ msg.include? "upstream"
16
+ end
17
+
18
+ def origin?
19
+ msg = git "remote --verbose"
20
+ msg.include? "origin"
21
+ end
22
+
23
+ def check_commit
24
+ return unless needs_commit?
25
+ puts status_short
26
+ puts "you have to commit the above changes first"
27
+ puts "enter commit message:"
28
+ msg = STDIN.gets.chomp
29
+ commit msg
30
+ end
31
+
32
+ def commit(msg)
33
+ git "add --all"
34
+ git "commit --all --message=\"#{msg}\""
35
+ end
36
+
37
+ def status
38
+ git "status"
39
+ end
40
+
41
+ def status_short
42
+ git "status --short"
43
+ end
44
+
45
+ def push(remote, branch)
46
+ git "push #{remote} #{branch}"
47
+ end
48
+
49
+ def git(cmd)
50
+ Dir.chdir(@repo) { `git #{cmd}` }
51
+ end
52
+ end
53
+ end
data/lib/pj/runner.rb ADDED
@@ -0,0 +1,30 @@
1
+ require "thor"
2
+ require "pj"
3
+
4
+ class Module
5
+ def task(name, &block)
6
+ define_method(name, &block)
7
+ end
8
+ end
9
+
10
+ module Pj
11
+ class Runner < Thor
12
+ Pj::Config.projects.each do |project|
13
+ desc("#{project} [sync|push|owner|cd]", "manages #{project} project")
14
+ define_method(project.to_sym) do |*args|
15
+ case args.shift
16
+ when "sync", "s"
17
+ invoke "pj:base:sync", [project]
18
+ when "push", "p"
19
+ branch = args.shift || "master"
20
+ invoke "pj:base:push", [project, branch]
21
+ when "owner", "o"
22
+ branch = args.shift || "master"
23
+ invoke "pj:base:owner", [project, branch]
24
+ when "cd"
25
+ invoke "pj:base:cd", [project]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
data/lib/pj/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Pj
2
+ VERSION = "0.1.2"
3
+ end
data/lib/pj.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "pj/base"
2
+ require "pj/config"
3
+ require "pj/git"
4
+ require "pj/version"
data/pj.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "pj/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pj"
8
+ spec.version = Pj::VERSION
9
+ spec.authors = %w(iamdionysus)
10
+ spec.email = %w(iamdionysus@gmail.com)
11
+
12
+ spec.summary = spec.description
13
+ spec.description = "helper to manage git project"
14
+ spec.homepage = "https://github.com/iamdionysus/pj"
15
+
16
+ spec.files = %w(pj.gemspec) + Dir["*.md", "bin/*", "lib/**/*.rb"]
17
+ spec.bindir = "bin"
18
+ spec.executables = %w(pj)
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+
23
+ spec.add_runtime_dependency "clipboard", "~> 1.0"
24
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pj
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - iamdionysus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-04 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: clipboard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: helper to manage git project
42
+ email:
43
+ - iamdionysus@gmail.com
44
+ executables:
45
+ - pj
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - bin/console
51
+ - bin/pj
52
+ - lib/pj.rb
53
+ - lib/pj/base.rb
54
+ - lib/pj/config.rb
55
+ - lib/pj/git.rb
56
+ - lib/pj/runner.rb
57
+ - lib/pj/version.rb
58
+ - pj.gemspec
59
+ homepage: https://github.com/iamdionysus/pj
60
+ licenses: []
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: ''
82
+ test_files: []