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 +4 -4
- data/CONTRIBUTING.md +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +5 -1
- data/lib/github-copywriter/regex.rb +44 -18
- data/lib/github-copywriter/version.rb +1 -1
- data/lib/github-copywriter.rb +11 -4
- data/spec/{copyright_spec.rb → copyright_regex_spec.rb} +34 -6
- data/test_repo_demo.gif +0 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84504ed9a92dd7dcbdd28884905da1fcdeb32a9
|
4
|
+
data.tar.gz: 7e046c94212fbc19527daa8dbf761fca3e772b0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7a3cdd5d25311fc57aaf0856483dff6dd756d52cb54611aee4f24ec2bfc392026d25f66ac9556cf264475c5d7884bab21a4e7bb2268a2c454e4317dfeac159d
|
7
|
+
data.tar.gz: 2d6ddcfaa1b8c657193845174d22511b4d4a768b146d7986e48bc8e679d397601280f64e231a1c97cd6bf9d2d7347748bb1ffd8febe592bcc5e70e5c3b4077ca
|
data/CONTRIBUTING.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
[](https://travis-ci.org/ryanmjacobs/github-copywriter)
|
3
3
|
[](http://badge.fury.io/rb/github-copywriter)
|
4
4
|
|
5
|
+

|
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
|
-
##
|
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
|
29
|
+
# Updates copyright using regex.
|
30
30
|
#
|
31
|
-
# @param year [
|
32
|
-
# @param content [String]
|
33
|
-
# @return [String]
|
34
|
-
#
|
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
|
-
|
37
|
-
|
52
|
+
data = {
|
53
|
+
:content => "",
|
54
|
+
:updated_now => false,
|
55
|
+
:found_copyright => false
|
56
|
+
}
|
38
57
|
|
39
|
-
#
|
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
|
-
|
55
|
-
|
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
|
-
#
|
58
|
-
|
59
|
-
old_content.gsub(
|
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
|
-
#
|
63
|
-
if
|
64
|
-
|
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
|
data/lib/github-copywriter.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/test_repo_demo.gif
ADDED
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
|
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-
|
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/
|
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/
|
151
|
+
- spec/copyright_regex_spec.rb
|
151
152
|
- spec/spec_helper.rb
|