github-copywriter 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTORS.md +1 -0
- data/README.md +6 -3
- data/bin/github-copywriter +1 -1
- data/lib/github-copywriter/octikit_wrapper.rb +1 -1
- data/lib/github-copywriter/regex.rb +69 -45
- data/lib/github-copywriter/version.rb +2 -2
- data/lib/github-copywriter.rb +7 -4
- data/spec/copyright_regex_spec.rb +59 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55ba1c50fe50049d63c0896d776523db6c848497
|
4
|
+
data.tar.gz: 64f7c36d11b8a2b724146816904bb17f2677bc00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4feb393e92984308a3898cefbae8e1022db77f0cd72915dd222cd13ea7c4d99e525e1108688cc18e17b2f9f068f735b0c6db345215cfbf721d9d7cbb065794cb
|
7
|
+
data.tar.gz: bd3a7beb5eb870dcf40db87416c3f36667eb7c80d7413d645aca666a654f7b2f059b509fd67617c6a294d061da0a918019dbe18c5a87787f38f0f6675c6850c6
|
data/CONTRIBUTORS.md
CHANGED
data/README.md
CHANGED
@@ -4,11 +4,14 @@
|
|
4
4
|
|
5
5
|
![test-repo demo](https://raw.githubusercontent.com/ryanmjacobs/github-copywriter/master/test_repo_demo.gif)
|
6
6
|
|
7
|
-
See the commit [here](
|
7
|
+
**See the example commit [here](//github.com/ryanmjacobs/test-repo/commit/7b095e65adf4cedcd7891326ec32c5f526838dd5). See the pretty website [here](//ryanmjacobs.github.io/github-copywriter).**
|
8
8
|
|
9
|
-
|
9
|
+
**Wanna see something a little more...
|
10
|
+
[complex](https://github.com/ryanmjacobs/test-repo/commit/7fbc410ce1171a2e858972b1c7cfed32b86d98e2)?**
|
10
11
|
|
11
|
-
|
12
|
+
## Updates your copyrights... so you don't have to!
|
13
|
+
|
14
|
+
### `$ gem install github-copywriter`
|
12
15
|
|
13
16
|
## Basic Usage
|
14
17
|
|
data/bin/github-copywriter
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
################################################################################
|
3
3
|
# github-copywriter
|
4
4
|
#
|
5
|
-
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com
|
5
|
+
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com>
|
6
6
|
################################################################################
|
7
7
|
|
8
8
|
require "optparse"
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# Octokit wrapper for commiting multiple files to a GitHub repo.
|
5
5
|
#
|
6
|
-
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com
|
6
|
+
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com>
|
7
7
|
################################################################################
|
8
8
|
|
9
9
|
class Copywriter
|
@@ -4,7 +4,7 @@
|
|
4
4
|
#
|
5
5
|
# All of the regex that's behind this amazing project :)
|
6
6
|
#
|
7
|
-
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com
|
7
|
+
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com>
|
8
8
|
################################################################################
|
9
9
|
|
10
10
|
class Copywriter
|
@@ -30,64 +30,88 @@ class Copywriter
|
|
30
30
|
#
|
31
31
|
# @param year [String] Year to update to, e.g. "2024"
|
32
32
|
# @param content [String] Text with outdated copyright
|
33
|
-
# @return [
|
33
|
+
# @return [Hash] {:new_content, :copyrights_found, :copyrights_updated}
|
34
34
|
#
|
35
35
|
# Example return hashes:
|
36
|
+
# ======================
|
36
37
|
#
|
37
|
-
# Input:
|
38
|
-
# "...Copyright
|
38
|
+
# Input -- an out-of-date copyright:
|
39
|
+
# "...Copyright 2013..."
|
39
40
|
# Return:
|
40
|
-
# {:content => "...Copyright 2014...", :
|
41
|
+
# {:content => "...Copyright 2014...", :copyrights_found => 1, :copyrights_updated => 1}
|
41
42
|
#
|
42
|
-
# Input:
|
43
|
-
# "...
|
43
|
+
# Input -- an already up-to-date copyright:
|
44
|
+
# "...Copyright 2014..."
|
44
45
|
# Return:
|
45
|
-
# {:content => "...
|
46
|
+
# {:content => "...Copyright 2014...", :copyrights_found => 1, :copyrights_updated => 0}
|
46
47
|
#
|
47
|
-
# Input:
|
48
|
-
# "...
|
48
|
+
# Input -- no copyright whatsoever:
|
49
|
+
# "...no copyright here..."
|
49
50
|
# Return:
|
50
|
-
# {:content => "...
|
51
|
+
# {:content => "...no copyright here...", :copyrights_found => 0, :copyrights_updated => 0}
|
51
52
|
def update_copyright(year, old_content)
|
52
53
|
data = {
|
53
54
|
:content => "",
|
54
|
-
:
|
55
|
-
:
|
55
|
+
:copyrights_found => 0,
|
56
|
+
:copyrights_updated => 0
|
56
57
|
}
|
57
58
|
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
59
|
+
# All teh regex
|
60
|
+
prefix = /([Cc]opyright( \([Cc]\)| ©)?|\([Cc]\)|©) /
|
61
|
+
suffix = /(\.| |$)/
|
62
|
+
comma_sep = /((\d{4},|\d{4}-\d{4},)*)/
|
63
|
+
regexs = [
|
64
|
+
# Singular -> (c) 2012 -> (c) 2014
|
65
|
+
# for any year
|
66
|
+
{ :regex => /#{prefix}\d{4}#{suffix}/, :replace => "\\1 #{year}\\3" },
|
67
|
+
|
68
|
+
# Multiple comma separated, ending w/ year_before
|
69
|
+
# (c) 2009-2011,2013 -> (c) 2009-2011,2013-2014
|
70
|
+
# for year before
|
71
|
+
{ :regex => /#{prefix}#{comma_sep}#{year-1}#{suffix}/, :replace => "\\1 \\3#{year-1}-#{year}\\5" },
|
72
|
+
|
73
|
+
# Multiple comma separated, ending w/ some_year DASH year_before
|
74
|
+
# (c) 2008-2010,2012-2013 -> (c) 2008-2010,2012-2014
|
75
|
+
# for year before
|
76
|
+
{ :regex => /#{prefix}#{comma_sep}((\d{4}-)?#{year-1})#{suffix}/, :replace => "\\1 \\3\\6#{year}\\7" },
|
77
|
+
|
78
|
+
# Multiple comma separated with dash
|
79
|
+
# (c) 2009,2012 -> (c) 2009,2012,2014
|
80
|
+
# (c) 2009-2012 -> (c) 2009-2012,2014
|
81
|
+
# for any year
|
82
|
+
{ :regex => /#{prefix}#{comma_sep}((\d{4}-)?\d{4})#{suffix}/, :replace => "\\1 \\3\\5,#{year}\\7" },
|
83
|
+
]
|
84
|
+
|
85
|
+
already_updated = /#{prefix}#{comma_sep}(\d{4}-)?#{year}#{suffix}/
|
86
|
+
has_copyright = /#{prefix}#{comma_sep}(\d{4}-)?\d{4}#{suffix}/
|
87
|
+
|
88
|
+
# Loop through each line of the input text
|
89
|
+
old_content.lines.each do |line|
|
90
|
+
# Is there even a copyright? If there isn't, goto the next line.
|
91
|
+
if not (has_copyright === line) then
|
92
|
+
data[:content] << line
|
93
|
+
next
|
94
|
+
end
|
95
|
+
|
96
|
+
# Are we already updated? If so, goto the next line.
|
97
|
+
if (already_updated === line) then
|
98
|
+
data[:copyrights_found] += 1
|
99
|
+
data[:content] << line
|
100
|
+
next
|
101
|
+
end
|
102
|
+
|
103
|
+
# Loop through our regex until we get one to work
|
104
|
+
regexs.each do |r|
|
105
|
+
data[:copyrights_found] += 1 if (r[:regex] === line)
|
106
|
+
updated_line = line.gsub(r[:regex], r[:replace])
|
87
107
|
|
88
|
-
|
89
|
-
|
90
|
-
|
108
|
+
# Did the regex update the copyright? If so, goto the next line.
|
109
|
+
if updated_line != line then
|
110
|
+
data[:content] << updated_line
|
111
|
+
data[:copyrights_updated] += 1
|
112
|
+
break
|
113
|
+
end
|
114
|
+
end
|
91
115
|
end
|
92
116
|
|
93
117
|
return data
|
@@ -1,13 +1,13 @@
|
|
1
1
|
################################################################################
|
2
2
|
# github-copywriter/version.rb
|
3
3
|
#
|
4
|
-
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com
|
4
|
+
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com>
|
5
5
|
################################################################################
|
6
6
|
|
7
7
|
class Copywriter
|
8
8
|
|
9
9
|
# Current version
|
10
10
|
# @return [String]
|
11
|
-
VERSION = "1.
|
11
|
+
VERSION = "1.2.0".freeze
|
12
12
|
|
13
13
|
end
|
data/lib/github-copywriter.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
################################################################################
|
3
3
|
# github-copywriter/github-copywriter.rb
|
4
4
|
#
|
5
|
-
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com
|
5
|
+
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com>
|
6
6
|
################################################################################
|
7
7
|
|
8
8
|
require "github-copywriter/regex"
|
@@ -19,9 +19,12 @@ class Copywriter
|
|
19
19
|
|
20
20
|
def initialize(username, password)
|
21
21
|
# Auth to GitHub
|
22
|
+
Octokit.auto_paginate = true
|
22
23
|
@client = Octokit::Client.new(:login => username, :password => password)
|
23
24
|
|
24
|
-
# Check if the basic_auth worked
|
25
|
+
# Check if the basic_auth worked.
|
26
|
+
# TODO: Find a better way to do this
|
27
|
+
# https://github.com/ryanmjacobs/github-copywriter/issues/1
|
25
28
|
begin
|
26
29
|
@client.authorizations
|
27
30
|
rescue Octokit::Unauthorized
|
@@ -117,10 +120,10 @@ class Copywriter
|
|
117
120
|
new_content = Copywriter::Regex.update_copyright(cur_year, Base64.decode64(file[:content]))
|
118
121
|
|
119
122
|
# Skip to the next file if we didn't even find a copyright in the text
|
120
|
-
next if
|
123
|
+
next if new_content[:copyrights_found] == 0
|
121
124
|
|
122
125
|
# Add to list of files to commit, only if the file has changed
|
123
|
-
if new_content[:
|
126
|
+
if new_content[:copyrights_updated] > 0 then
|
124
127
|
@modified_files << {:path => file[:path], :content => new_content[:content]}
|
125
128
|
puts " #{file[:path]} is now up-to-date.".green
|
126
129
|
else
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
|
+
### This script assumes the current year is 2014. ###
|
5
|
+
|
4
6
|
###
|
5
7
|
# This spec desperately needs a rewrite.
|
6
8
|
# It works, but the display is all wrong
|
@@ -21,6 +23,43 @@ copyrights = [
|
|
21
23
|
{ :old => "(c) 1970", :new => "(c) 2014" },
|
22
24
|
{ :old => "(C) 1970", :new => "(C) 2014" },
|
23
25
|
{ :old => "© 1970", :new => "© 2014" },
|
26
|
+
|
27
|
+
###
|
28
|
+
|
29
|
+
{ :old => "Copyright (C) 2010-2013", :new => "Copyright (C) 2010-2014" },
|
30
|
+
{ :old => "Copyright (C) 2010-2012", :new => "Copyright (C) 2010-2012,2014" },
|
31
|
+
{ :old => "Copyright (C) 2009,2012", :new => "Copyright (C) 2009,2012,2014" },
|
32
|
+
{ :old => "Copyright (C) 2010,2013", :new => "Copyright (C) 2010,2013-2014" },
|
33
|
+
|
34
|
+
{ :old => "Copyright (C) 2006,2008,2010,2012", :new => "Copyright (C) 2006,2008,2010,2012,2014" },
|
35
|
+
{ :old => "Copyright (C) 2001,2003,2006,2008,2010,2012", :new => "Copyright (C) 2001,2003,2006,2008,2010,2012,2014" },
|
36
|
+
|
37
|
+
{ :old => "Copyright (C) 1996-1998,2001-2002,2010-2013", :new => "Copyright (C) 1996-1998,2001-2002,2010-2014" },
|
38
|
+
{ :old => "Copyright (C) 1996-1998,2001-2002,2010-2012", :new => "Copyright (C) 1996-1998,2001-2002,2010-2012,2014" },
|
39
|
+
{ :old => "Copyright (C) 2001-2002,2010-2013", :new => "Copyright (C) 2001-2002,2010-2014" },
|
40
|
+
{ :old => "Copyright (C) 2001,2003,2010-2013", :new => "Copyright (C) 2001,2003,2010-2014" },
|
41
|
+
|
42
|
+
{ :old => "copyright © 1970 more words", :new => "copyright © 2014 more words" },
|
43
|
+
{ :old => "words copyright © 1970", :new => "words copyright © 2014" },
|
44
|
+
|
45
|
+
##
|
46
|
+
|
47
|
+
{
|
48
|
+
:old => "This is my paragraph. Blah blah blah... Copyright 2001.\nCopyright (C) 2001,2003,2006,2008,2010,2012",
|
49
|
+
:new => "This is my paragraph. Blah blah blah... Copyright 2014.\nCopyright (C) 2001,2003,2006,2008,2010,2012,2014"
|
50
|
+
},
|
51
|
+
{
|
52
|
+
:old => "This is my paragraph. Blah blah blah... Copyright 2001.\nCopyright (C) 2001,2003,2006,2008,2010,2013",
|
53
|
+
:new => "This is my paragraph. Blah blah blah... Copyright 2014.\nCopyright (C) 2001,2003,2006,2008,2010,2013-2014"
|
54
|
+
},
|
55
|
+
{
|
56
|
+
:old => "This is my paragraph. Blah blah blah... Copyright 2001.\nCopyright (C) 2001,2003,2006,2008,2010-2013",
|
57
|
+
:new => "This is my paragraph. Blah blah blah... Copyright 2014.\nCopyright (C) 2001,2003,2006,2008,2010-2014"
|
58
|
+
},
|
59
|
+
{
|
60
|
+
:old => "This is my paragraph. Blah blah blah... Copyright 2001.\nCopyright (C) 2001,2003,2006,2008,2010-2013\n",
|
61
|
+
:new => "This is my paragraph. Blah blah blah... Copyright 2014.\nCopyright (C) 2001,2003,2006,2008,2010-2014\n"
|
62
|
+
}
|
24
63
|
]
|
25
64
|
|
26
65
|
garbage_text = [
|
@@ -33,7 +72,8 @@ garbage_text = [
|
|
33
72
|
"(c) (c) (C)",
|
34
73
|
"_dfasdf_",
|
35
74
|
"© © ©",
|
36
|
-
"REALLYLONGSTRINGWITHNOSPACES"
|
75
|
+
"REALLYLONGSTRINGWITHNOSPACES",
|
76
|
+
"copyright © 1970more words"
|
37
77
|
]
|
38
78
|
|
39
79
|
# ./lib/github-copywriter/regex.rb
|
@@ -43,33 +83,39 @@ describe Copywriter do
|
|
43
83
|
# Copywriter::Regex.update_copyright
|
44
84
|
context "an out-of-date copyright..." do
|
45
85
|
copyrights.each do |copyright|
|
46
|
-
|
86
|
+
context(copyright[:old]) do
|
87
|
+
updated_copyright = regex.update_copyright(2014, copyright[:old])
|
47
88
|
|
48
|
-
|
49
|
-
|
50
|
-
|
89
|
+
it { expect(updated_copyright[:content]) .to eq(copyright[:new]) }
|
90
|
+
it { expect(updated_copyright[:copyrights_found]) .to be > 0 }
|
91
|
+
it { expect(updated_copyright[:copyrights_updated]) .to be > 0 }
|
92
|
+
end
|
51
93
|
end
|
52
94
|
end
|
53
95
|
|
54
96
|
# Copywriter::Regex.update_copyright
|
55
97
|
context "an up-to-date copyright..." do
|
56
98
|
copyrights.each do |copyright|
|
57
|
-
|
99
|
+
context(copyright[:new]) do
|
100
|
+
updated_copyright = regex.update_copyright(2014, copyright[:new])
|
58
101
|
|
59
|
-
|
60
|
-
|
61
|
-
|
102
|
+
it { expect(updated_copyright[:content]) .to eq(copyright[:new]) }
|
103
|
+
it { expect(updated_copyright[:copyrights_found]) .to be > 0 }
|
104
|
+
it { expect(updated_copyright[:copyrights_updated]) .to be(0) }
|
105
|
+
end
|
62
106
|
end
|
63
107
|
end
|
64
108
|
|
65
109
|
# Copywriter::Regex.update_copyright
|
66
110
|
context "garbage text input..." do
|
67
111
|
garbage_text.each do |garbage|
|
68
|
-
|
112
|
+
context(garbage) do
|
113
|
+
updated_copyright = regex.update_copyright(2014, garbage)
|
69
114
|
|
70
|
-
|
71
|
-
|
72
|
-
|
115
|
+
it { expect(updated_copyright[:content]) .to eq(garbage) }
|
116
|
+
it { expect(updated_copyright[:copyrights_found]) .to be(0) }
|
117
|
+
it { expect(updated_copyright[:copyrights_updated]) .to be(0) }
|
118
|
+
end
|
73
119
|
end
|
74
120
|
end
|
75
121
|
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: 1.
|
4
|
+
version: 1.2.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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|