github-copywriter 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15cd7808bbe3d197e2893024b7f32088e7a0cbab
4
- data.tar.gz: 292896e21d05194b9a9309b8f40df956ebdf45dc
3
+ metadata.gz: 28edcf28a7ba50ed82f9abe685af12fc4da9da92
4
+ data.tar.gz: ab8737a3e5db04074640029084f557b706ad05b4
5
5
  SHA512:
6
- metadata.gz: 4289d219d03440699343066c243d7b42649feac8529fcf2302d802b769de82477b5a942ef06bf3c55a8a227630b5af855105c8384f18ac536ae2fc2db9f87870
7
- data.tar.gz: de1363e6c37fe08bc4c5d9308fecc4d39b935a670cc8ba55ede33b37b1a77b435e30278139d1368786acbbf65badacda5117b83ce5e548015093dc1e51db572b
6
+ metadata.gz: 92201c3e9cb8988113b394a17fbf96e8c40865fddb1961dce9451be45c0bf0358296d5ba8a3e6ad29197bb518bdedf162b8bfd084194965f05b703374e3ef332
7
+ data.tar.gz: a6f1efaee70f5451706d3d663daa74bf7f159b743650520b31a89ea37c424cd8a8d8109628ae75dc840100c87ed923cd135cdc948cfcd9440a3144680f357e7a
data/README.md CHANGED
@@ -24,7 +24,7 @@ Questions and comments are welcome as well. Checkout
24
24
  [CONTRIBUTING.md](//github.com/ryanmjacobs/github-copywriter/blob/master/CONTRIBUTING.md)
25
25
  for more info.
26
26
 
27
- Feel free to [fork](//github.com/ryanmjacobs/github-copywriter) this project, and:
27
+ Feel free to [fork](//github.com/ryanmjacobs/github-copywriter/fork) this project, and:
28
28
 
29
29
  * fix bugs
30
30
  * add some sweet features
@@ -24,7 +24,7 @@ Usage: #{executable_name} [repos...]
24
24
 
25
25
  EOS
26
26
 
27
- opts.on("--all", "Update copyrights on ALL repositories.") do
27
+ opts.on("-a", "--all", "Update copyrights on ALL repositories.") do
28
28
  options[:all] = true
29
29
  end
30
30
 
@@ -33,7 +33,20 @@ Usage: #{executable_name} [repos...]
33
33
  end
34
34
 
35
35
  opts.on("-y", "--year YEAR", "Update copyrights to a give year.") do |year|
36
- options[:year] = year
36
+ if year.to_i >= 1000 && year.to_i <= 9999 then
37
+ options[:year] = year
38
+ else
39
+ puts "error: year must be four digits".red
40
+ exit
41
+ end
42
+ end
43
+
44
+ opts.on("-b", "--branches branch1,branch2", "Update specific branches.") do |comma_separated_branches|
45
+ options[:branches] = comma_separated_branches.split(",").map(&:strip)
46
+ end
47
+
48
+ opts.on("--all-branches", "Update all branches.") do
49
+ options[:all_branches] = true
37
50
  end
38
51
 
39
52
  opts.on_tail("-h","--help", "Show this message.") do
@@ -49,7 +62,7 @@ end.parse!
49
62
 
50
63
  # Must have at least one repo!
51
64
  if ARGV.empty? and not options[:all]
52
- puts "error: No repositories supplied!"
65
+ puts "error: No repositories supplied!".red
53
66
  exit
54
67
  end
55
68
 
@@ -8,6 +8,6 @@ class Copywriter
8
8
 
9
9
  # Current version
10
10
  # @return [String]
11
- VERSION = "0.1.0".freeze
11
+ VERSION = "0.1.1".freeze
12
12
 
13
13
  end
@@ -32,7 +32,13 @@ class Copywriter
32
32
 
33
33
  def run!(options={})
34
34
  # Default options
35
- options = {all: false, skip_forks: false, year: nil}.merge(options)
35
+ options = {
36
+ all: false,
37
+ skip_forks: false,
38
+ year: nil,
39
+ branches: nil,
40
+ all_branches: false
41
+ }.merge(options)
36
42
 
37
43
  if options[:all] then
38
44
  repos = @client.repositories()
@@ -58,56 +64,78 @@ class Copywriter
58
64
  # Skip if repo is a fork and --skip-forks is on
59
65
  next if options[:skip_forks] and repo[:fork]
60
66
 
61
- # Get repo info
62
- repo_name = repo[:full_name]
63
- ref = "heads/#{repo[:default_branch]}"
64
- latest_commit = @client.ref(repo_name, ref).object
65
- root_tree = @client.commit(repo_name, latest_commit.sha).commit.tree
66
- puts "\n"+repo_name+":"
67
-
68
- # Grab the *whole* tree
69
- tree = @client.tree(repo_name, root_tree.sha, :recursive => true)
70
-
71
- # warn user about truncation
72
- if tree[:truncated] then
73
- puts " warning: tree truncated because number of items exceeded limit.".yellow
74
- puts " If you feel like fixing this, see issue #xx".yellow
75
- puts " http://github.com/ryanmjacobs/github-copywriter/xx".yellow
76
- end
67
+ # Repo name
68
+ repo_name = repo[:full_name]
69
+ puts "\n#{repo_name}:".cyan
77
70
 
78
- # Stores updated files until we commit
79
- # @modified_files is a hash {:path, :content}
80
- @modified_files = Array.new
71
+ # Repo refs (branches) to loop through
72
+ if options[:branches] != nil then
73
+ refs = options[:branches].map { |branch| "heads/#{branch}" }
74
+ else
75
+ refs = "heads/#{repo[:default_branch]}"
76
+ end
81
77
 
82
- # Loop through all of the tree's blobs
83
- tree[:tree].each do |file|
84
- next if file[:type] != "blob"
78
+ # Use all branches if we have the flag
79
+ if options[:all_branches] then
80
+ # Get all refs of type "heads"; remove leading "refs/"
81
+ refs = @client.refs(repo_name, "heads").map { |r| r[:ref].sub("refs/", "") }
82
+ end
85
83
 
86
- if Copywriter::Regex.accepted_name?(file[:path]) then
87
- # Grab file from repo
88
- file = @client.contents(repo_name, :path => file[:path])
89
- if file[:type] != "file" then raise "error: #{file_path} on #{repo} is not a file!" end
84
+ # Loop through each ref
85
+ refs.each do |ref|
86
+ puts " #{ref}:".yellow
87
+
88
+ # Grab the *whole* tree
89
+ begin
90
+ latest_commit = @client.ref(repo_name, ref).object
91
+ root_tree = @client.commit(repo_name, latest_commit.sha).commit.tree
92
+ whole_tree = @client.tree(repo_name, root_tree.sha, :recursive => true)
93
+ rescue Octokit::NotFound
94
+ puts "error: ref #{ref} not found.".red
95
+ exit
96
+ end
90
97
 
91
- # Update the copyright
92
- new_content = Copywriter::Regex.update_copyright(cur_year, Base64.decode64(file[:content]))
98
+ # Warn the user about truncation
99
+ if whole_tree[:truncated] then
100
+ puts " warning: tree truncated because number of items exceeded limit.".yellow
101
+ puts " If you feel like fixing this, see issue #xx".yellow
102
+ puts " http://github.com/ryanmjacobs/github-copywriter/xx".yellow
103
+ end
93
104
 
94
- # Add to list of files to commit, only if the file has changed
95
- if new_content != nil then
96
- @modified_files << {:path => file[:path], :content => new_content}
97
- puts " #{file[:path]} is now up-to-date.".green
98
- else
99
- puts " #{file[:path]} is already up-to-date."
105
+ # Stores updated files until we commit
106
+ # @modified_files is a hash {:path, :content}
107
+ @modified_files = Array.new
108
+
109
+ # Loop through all of whole_tree's blobs
110
+ whole_tree[:tree].each do |file|
111
+ next if file[:type] != "blob"
112
+
113
+ if Copywriter::Regex.accepted_name?(file[:path]) then
114
+ # Grab file from repo
115
+ file = @client.contents(repo_name, :path => file[:path], :ref => ref)
116
+ if file[:type] != "file" then raise "error: #{file_path} on #{repo} is not a file!" end
117
+
118
+ # Update the copyright
119
+ new_content = Copywriter::Regex.update_copyright(cur_year, Base64.decode64(file[:content]))
120
+
121
+ # Add to list of files to commit, only if the file has changed
122
+ if new_content != nil then
123
+ @modified_files << {:path => file[:path], :content => new_content}
124
+ puts " #{file[:path]} is now up-to-date.".green
125
+ else
126
+ puts " #{file[:path]} is already up-to-date."
127
+ end
100
128
  end
101
129
  end
102
- end
103
130
 
104
- # Commit stored up files
105
- if @modified_files.size > 0 then
106
- print " Committing #{@modified_files.size} files..."
107
- commit_files(repo_name, ref, "100644", @modified_files, COMMIT_MSG)
108
- puts " done"
109
- else
110
- puts " No files needed to be commited."
131
+ # Commit stored up files
132
+ if @modified_files.size > 0 then
133
+ print " Committing #{@modified_files.size} files..."
134
+ commit_files(repo_name, ref, "100644", @modified_files, COMMIT_MSG)
135
+ puts " done"
136
+ else
137
+ puts " No files needed to be commited."
138
+ end
111
139
  end
112
140
  end
113
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-copywriter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Jacobs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-15 00:00:00.000000000 Z
11
+ date: 2014-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler