github-copywriter 1.0.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af87c99fef9a0da582142cf02e362b279b4ecafc
4
- data.tar.gz: f7e0a2cfab670d32fe6b65fe9f2d626b96181f6e
3
+ metadata.gz: c84504ed9a92dd7dcbdd28884905da1fcdeb32a9
4
+ data.tar.gz: 7e046c94212fbc19527daa8dbf761fca3e772b0b
5
5
  SHA512:
6
- metadata.gz: 702e4e28d4935802b92ffe5103f34e87e8f6ca2b0bc4fced27fb1ca9d83044842999d04d9b02e3f0a595239dab11ab3af1a26e8211e06d528745be9c7da41643
7
- data.tar.gz: a926f723533243eb7f2013c9e7a8c616ed21c3efc6d88ccf02a8ad1f529e21e003a79dc2c1e71cb115da1c8487e14c7afb061e01880d2fd5c46ce7451cd7e8ee
6
+ metadata.gz: b7a3cdd5d25311fc57aaf0856483dff6dd756d52cb54611aee4f24ec2bfc392026d25f66ac9556cf264475c5d7884bab21a4e7bb2268a2c454e4317dfeac159d
7
+ data.tar.gz: 2d6ddcfaa1b8c657193845174d22511b4d4a768b146d7986e48bc8e679d397601280f64e231a1c97cd6bf9d2d7347748bb1ffd8febe592bcc5e70e5c3b4077ca
data/CONTRIBUTING.md CHANGED
@@ -40,6 +40,8 @@ Push changes to the origin.
40
40
  git push origin add-rainbow-text
41
41
  ```
42
42
 
43
+ Lastly, submit a pull request!
44
+
43
45
  ### Staying in sync with the upstream
44
46
  Set and fetch the upstream remote.
45
47
  ```
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Ryan Jacobs
1
+ Copyright (c) 2015 Ryan Jacobs
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
  [![Build Status](https://travis-ci.org/ryanmjacobs/github-copywriter.svg?branch=master)](https://travis-ci.org/ryanmjacobs/github-copywriter)
3
3
  [![Gem Version](https://badge.fury.io/rb/github-copywriter.svg)](http://badge.fury.io/rb/github-copywriter)
4
4
 
5
+ ![test-repo demo](https://raw.githubusercontent.com/ryanmjacobs/github-copywriter/master/test_repo_demo.gif)
6
+
7
+ See the commit [here](https://github.com/ryanmjacobs/test-repo/commit/7b095e65adf4cedcd7891326ec32c5f526838dd5).
8
+
5
9
  Updates your copyrights... so you don't have to!
6
10
 
7
11
  `$ gem install github-copywriter`
@@ -14,7 +18,7 @@ Updates your copyrights... so you don't have to!
14
18
  ### Update all repos
15
19
  `$ github-copywriter --all`
16
20
 
17
- ## Other Usage
21
+ ## More Usage
18
22
 
19
23
  ### Update all repos, excluding forks
20
24
  `$ github-copywriter --all --skip-forks`
@@ -26,17 +26,36 @@ class Copywriter
26
26
  return false
27
27
  end
28
28
 
29
- # Updates copyright using regex, then commits it.
29
+ # Updates copyright using regex.
30
30
  #
31
- # @param year [Numeric] Year to update to, e.g. 2024
32
- # @param content [String] Text with outdated copyright
33
- # @return [String] Text with updated copyright. Nil if file was already
34
- # up to date.
31
+ # @param year [String] Year to update to, e.g. "2024"
32
+ # @param content [String] Text with outdated copyright
33
+ # @return [String] Hash object {:new_content, :updated_now, :found_copyright}
34
+ #
35
+ # Example return hashes:
36
+ #
37
+ # Input:
38
+ # "...Copyright 2014..."
39
+ # Return:
40
+ # {:content => "...Copyright 2014...", :updated_now => false, :found_copyright => true}
41
+ #
42
+ # Input:
43
+ # "...no copyright here..."
44
+ # Return:
45
+ # {:content => "...no copyright here...", :updated_now => false, :found_copyright => false}
46
+ #
47
+ # Input:
48
+ # "...Copyright 2013..."
49
+ # Return:
50
+ # {:content => "...Copyright 2014...", :updated_now => true, :found_copyright => true}
35
51
  def update_copyright(year, old_content)
36
- # Have to do separate assignments b/c ruby shares strings,
37
- # TODO: find a way around this
52
+ data = {
53
+ :content => "",
54
+ :updated_now => false,
55
+ :found_copyright => false
56
+ }
38
57
 
39
- # Do the substitution
58
+ # The Glorious Regular Expression
40
59
  #
41
60
  # Matches:
42
61
  # Copyright 2014
@@ -50,21 +69,28 @@ class Copywriter
50
69
  # (c) 2014
51
70
  # (C) 2014
52
71
  # © 2014
72
+ utf_regex = /([Cc]opyright( \([Cc]\)| ©)?|\([Cc]\)|©) \d{4}/
73
+ ascii_regex = /([Cc]opyright( \([Cc]\))?|\([Cc]\)) \d{4}/
74
+ regex_replace = "\\1 #{year}"
75
+
76
+ # Do the substitution
53
77
  begin
54
- new_content = \
55
- old_content.gsub(/([Cc]opyright( \([Cc]\)| ©)?|\([Cc]\)|©) \d{4}/, "\\1 #{year}")
78
+ # Do UTF-8 Regex
79
+
80
+ data[:found_copyright] = (utf_regex === old_content)
81
+ data[:content] = old_content.gsub(utf_regex, regex_replace)
56
82
  rescue
57
- # try w/o "©" symbol if we had errors
58
- new_content = \
59
- old_content.gsub(/([Cc]opyright( \([Cc]\))?|\([Cc]\)) \d{4}/, "\\1 #{year}")
83
+ # Do Ascii Regex if the above fails
84
+ data[:found_copyright] = (ascii_regex === old_content)
85
+ data[:content] = old_content.gsub(ascii_regex, regex_replace)
60
86
  end
61
87
 
62
- # Only commit if we need to
63
- if new_content != old_content then
64
- return new_content
65
- else
66
- return nil
88
+ # Update whether or not we had to update the copyright
89
+ if data[:content] != old_content then
90
+ data[:updated_now] = true
67
91
  end
92
+
93
+ return data
68
94
  end
69
95
  end
70
96
  end
@@ -8,6 +8,6 @@ class Copywriter
8
8
 
9
9
  # Current version
10
10
  # @return [String]
11
- VERSION = "1.0.1".freeze
11
+ VERSION = "1.1.0".freeze
12
12
 
13
13
  end
@@ -116,9 +116,12 @@ class Copywriter
116
116
  # Update the copyright
117
117
  new_content = Copywriter::Regex.update_copyright(cur_year, Base64.decode64(file[:content]))
118
118
 
119
+ # Skip to the next file if we didn't even find a copyright in the text
120
+ next if not new_content[:found_copyright]
121
+
119
122
  # Add to list of files to commit, only if the file has changed
120
- if new_content != nil then
121
- @modified_files << {:path => file[:path], :content => new_content}
123
+ if new_content[:updated_now] then
124
+ @modified_files << {:path => file[:path], :content => new_content[:content]}
122
125
  puts " #{file[:path]} is now up-to-date.".green
123
126
  else
124
127
  puts " #{file[:path]} is already up-to-date."
@@ -128,9 +131,13 @@ class Copywriter
128
131
 
129
132
  # Commit stored up files
130
133
  if @modified_files.size > 0 then
131
- print " Committing #{@modified_files.size} files..."
134
+ if @modified_files.size == 1 then
135
+ print " Committing 1 file..."
136
+ else
137
+ print " Committing #{@modified_files.size} files..."
138
+ end
132
139
  commit_files(repo_name, ref, "100644", @modified_files, COMMIT_MSG)
133
- puts " done"
140
+ puts " done!"
134
141
  else
135
142
  puts " No files needed to be commited."
136
143
  end
@@ -23,25 +23,53 @@ copyrights = [
23
23
  { :old => "© 1970", :new => "© 2014" },
24
24
  ]
25
25
 
26
+ garbage_text = [
27
+ "sjdfhaksjdfashdjfahskdjfh",
28
+ "asdjfasdf",
29
+ "hello these are words",
30
+ "thing thing thing",
31
+ "NOTCOPYRIGHT",
32
+ "NOT COPYRIGHT",
33
+ "(c) (c) (C)",
34
+ "_dfasdf_",
35
+ "© © ©",
36
+ "REALLYLONGSTRINGWITHNOSPACES"
37
+ ]
38
+
26
39
  # ./lib/github-copywriter/regex.rb
27
40
  describe Copywriter do
28
41
  regex = Copywriter::Regex
29
42
 
30
- # Copywriter::Regex.update_copyright ->
31
- # should return the updated copyright if the input was out of date
43
+ # Copywriter::Regex.update_copyright
32
44
  context "an out-of-date copyright..." do
33
45
  copyrights.each do |copyright|
34
46
  updated_copyright = regex.update_copyright(2014, copyright[:old])
35
- it { expect(updated_copyright).to eq(copyright[:new]) }
47
+
48
+ it { expect(updated_copyright[:updated_now]) .to be(true) }
49
+ it { expect(updated_copyright[:found_copyright]).to be(true) }
50
+ it { expect(updated_copyright[:content]) .to eq(copyright[:new]) }
36
51
  end
37
52
  end
38
53
 
39
- # Copywriter::Regex.update_copyright ->
40
- # should return nil if the input was up-to-date
54
+ # Copywriter::Regex.update_copyright
41
55
  context "an up-to-date copyright..." do
42
56
  copyrights.each do |copyright|
43
57
  updated_copyright = regex.update_copyright(2014, copyright[:new])
44
- it { expect(updated_copyright).to be(nil) }
58
+
59
+ it { expect(updated_copyright[:updated_now]) .to be(false) }
60
+ it { expect(updated_copyright[:found_copyright]).to be(true) }
61
+ it { expect(updated_copyright[:content]) .to eq(copyright[:new]) }
62
+ end
63
+ end
64
+
65
+ # Copywriter::Regex.update_copyright
66
+ context "garbage text input..." do
67
+ garbage_text.each do |garbage|
68
+ updated_copyright = regex.update_copyright(2014, garbage)
69
+
70
+ it { expect(updated_copyright[:updated_now]) .to be(false) }
71
+ it { expect(updated_copyright[:found_copyright]).to be(false) }
72
+ it { expect(updated_copyright[:content]) .to eq(garbage) }
45
73
  end
46
74
  end
47
75
  end
Binary file
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: 1.0.1
4
+ version: 1.1.0
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-17 00:00:00.000000000 Z
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,8 +119,9 @@ files:
119
119
  - lib/github-copywriter/regex.rb
120
120
  - lib/github-copywriter/version.rb
121
121
  - spec/accepted_name_spec.rb
122
- - spec/copyright_spec.rb
122
+ - spec/copyright_regex_spec.rb
123
123
  - spec/spec_helper.rb
124
+ - test_repo_demo.gif
124
125
  homepage: http://ryanmjacobs.github.io/github-copywriter
125
126
  licenses:
126
127
  - MIT
@@ -147,5 +148,5 @@ specification_version: 4
147
148
  summary: github-copywriter updates your copyrights... so you don't have to!
148
149
  test_files:
149
150
  - spec/accepted_name_spec.rb
150
- - spec/copyright_spec.rb
151
+ - spec/copyright_regex_spec.rb
151
152
  - spec/spec_helper.rb