github-copywriter 0.0.4 → 0.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/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CONTRIBUTING.md +56 -0
- data/CONTRIBUTORS.md +7 -0
- data/Gemfile +9 -2
- data/README.md +7 -6
- data/Rakefile +5 -0
- data/bin/github-copywriter +16 -3
- data/github-copywriter.gemspec +22 -20
- data/lib/github-copywriter.rb +25 -120
- data/lib/github-copywriter/octikit_wrapper.rb +58 -0
- data/lib/github-copywriter/regex.rb +70 -0
- data/lib/github-copywriter/version.rb +13 -0
- data/spec/accepted_name_spec.rb +32 -0
- data/spec/copyright_spec.rb +47 -0
- data/spec/spec_helper.rb +6 -0
- metadata +49 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15cd7808bbe3d197e2893024b7f32088e7a0cbab
|
4
|
+
data.tar.gz: 292896e21d05194b9a9309b8f40df956ebdf45dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4289d219d03440699343066c243d7b42649feac8529fcf2302d802b769de82477b5a942ef06bf3c55a8a227630b5af855105c8384f18ac536ae2fc2db9f87870
|
7
|
+
data.tar.gz: de1363e6c37fe08bc4c5d9308fecc4d39b935a670cc8ba55ede33b37b1a77b435e30278139d1368786acbbf65badacda5117b83ce5e548015093dc1e51db572b
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
## Contributing
|
2
|
+
|
3
|
+
### Introduction
|
4
|
+
I'm pretty much open to anything really. If you have a feature you want to
|
5
|
+
implement, first create an issue for it (so I can see what you're trying to
|
6
|
+
achieve). Then submit a pull request later when you're done with it.
|
7
|
+
|
8
|
+
Or, if you're feeling generous, implement someone else's feature request!
|
9
|
+
|
10
|
+
Try best you can to keep the code consistent. My only gripe is indentation.
|
11
|
+
Please set your editor to use 4-space indentation!
|
12
|
+
|
13
|
+
If I merge any of your pull requests, big or small, I will add you to the
|
14
|
+
[list of contributors](//github.com/ryanmjacobs/github-copywriter/blob/master/CONTRIBUTORS.md)
|
15
|
+
with a small note of what you did. If you want to update it to
|
16
|
+
include your website and/or email, just submit a PR.
|
17
|
+
|
18
|
+
### Setup
|
19
|
+
To start hacking away, fork and clone the project.
|
20
|
+
```
|
21
|
+
$ git clone https://github.com/YourUsername/github-copywriter
|
22
|
+
$ cd github-copywriter
|
23
|
+
```
|
24
|
+
|
25
|
+
### Adding features and fixing bugs
|
26
|
+
Create an aptly named branch off the master.
|
27
|
+
```
|
28
|
+
$ git checkout master
|
29
|
+
$ git checkout -b add-rainbow-text
|
30
|
+
```
|
31
|
+
|
32
|
+
Make some modifications/additions.
|
33
|
+
```
|
34
|
+
$ do some work...
|
35
|
+
$ add some commits...
|
36
|
+
```
|
37
|
+
|
38
|
+
Push changes to the origin.
|
39
|
+
```
|
40
|
+
git push origin add-rainbow-text
|
41
|
+
```
|
42
|
+
|
43
|
+
### Staying in sync with the upstream
|
44
|
+
Set and fetch the upstream remote.
|
45
|
+
```
|
46
|
+
$ git remote add upstream https://github.com/ryanmjacobs/github-copywriter
|
47
|
+
$ git fetch upstream
|
48
|
+
```
|
49
|
+
|
50
|
+
And every once in a while sync your `master` to `upstream/master`.
|
51
|
+
```
|
52
|
+
$ git fetch upstream
|
53
|
+
$ git checkout master
|
54
|
+
$ git merge upstream/master
|
55
|
+
$ git push origin master
|
56
|
+
```
|
data/CONTRIBUTORS.md
ADDED
data/Gemfile
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in copywriter.gemspec
|
3
|
+
# Specify your gem's dependencies in github-copywriter.gemspec
|
4
4
|
gemspec
|
5
|
+
gem "octokit"
|
6
|
+
gem "colorize"
|
7
|
+
|
8
|
+
group :test do
|
9
|
+
gem "rspec"
|
10
|
+
gem "rake"
|
11
|
+
end
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# github-copywriter
|
2
|
+
[](https://travis-ci.org/ryanmjacobs/github-copywriter)
|
3
|
+
[](http://badge.fury.io/rb/github-copywriter)
|
2
4
|
|
3
5
|
Updates your copyrights... so you don't have to!
|
4
6
|
|
5
7
|
`$ gem install github-copywriter`
|
6
8
|
|
7
|
-
---
|
8
|
-
|
9
9
|
### Update specific repos
|
10
10
|
`$ github-copywriter MyCoolRepo MyOtherCoolRepo`
|
11
11
|
|
@@ -15,11 +15,14 @@ Updates your copyrights... so you don't have to!
|
|
15
15
|
### Update all repos, excluding forks
|
16
16
|
`$ github-copywriter --all --skip-forks`
|
17
17
|
|
18
|
-
|
18
|
+
### Update all repos to 2015
|
19
|
+
`$ github-copywriter --all --year 2015`
|
19
20
|
|
20
21
|
## Contributing
|
21
22
|
Please submit issues or feature requests [here](//github.com/ryanmjacobs/github-copywriter/issues).
|
22
|
-
Questions and comments are
|
23
|
+
Questions and comments are welcome as well. Checkout
|
24
|
+
[CONTRIBUTING.md](//github.com/ryanmjacobs/github-copywriter/blob/master/CONTRIBUTING.md)
|
25
|
+
for more info.
|
23
26
|
|
24
27
|
Feel free to [fork](//github.com/ryanmjacobs/github-copywriter) this project, and:
|
25
28
|
|
@@ -28,8 +31,6 @@ Feel free to [fork](//github.com/ryanmjacobs/github-copywriter) this project, an
|
|
28
31
|
* implement feature requests
|
29
32
|
* improve the docs and/or this site
|
30
33
|
|
31
|
-
---
|
32
|
-
|
33
34
|
## Under the hood
|
34
35
|
All GitHub API calls are made with [Octokit](//github.com/octokit/octokit.rb).
|
35
36
|
|
data/Rakefile
CHANGED
data/bin/github-copywriter
CHANGED
@@ -5,11 +5,14 @@
|
|
5
5
|
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com
|
6
6
|
################################################################################
|
7
7
|
|
8
|
-
require "github-copywriter"
|
9
8
|
require "optparse"
|
9
|
+
require "highline/import"
|
10
|
+
require "github-copywriter"
|
10
11
|
|
12
|
+
# To store command-line options/parameters
|
11
13
|
options = {}
|
12
14
|
|
15
|
+
# Grab command-line options/parameters
|
13
16
|
ARGV << "-h" if ARGV.empty?
|
14
17
|
OptionParser.new do |opts|
|
15
18
|
executable_name = File.split($0)[1]
|
@@ -44,12 +47,22 @@ Usage: #{executable_name} [repos...]
|
|
44
47
|
end
|
45
48
|
end.parse!
|
46
49
|
|
50
|
+
# Must have at least one repo!
|
47
51
|
if ARGV.empty? and not options[:all]
|
48
52
|
puts "error: No repositories supplied!"
|
49
53
|
exit
|
50
54
|
end
|
51
55
|
|
56
|
+
# Pass input repos into options
|
52
57
|
options[:repos] = ARGV
|
53
58
|
|
54
|
-
|
55
|
-
|
59
|
+
# Get username and password
|
60
|
+
puts "Obtaining OAuth2 access_token from github."
|
61
|
+
username = ask("GitHub username: ") { |q| q.echo = true }
|
62
|
+
password = ask("GitHub password: ") { |q| q.echo = "*" }
|
63
|
+
|
64
|
+
# Auth to GitHub
|
65
|
+
cw = Copywriter.new(username, password)
|
66
|
+
|
67
|
+
# Do it!
|
68
|
+
cw.run!(options)
|
data/github-copywriter.gemspec
CHANGED
@@ -1,28 +1,30 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "github-copywriter"
|
4
|
+
require "github-copywriter/version"
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "github-copywriter"
|
8
|
+
gem.version = Copywriter::VERSION
|
9
|
+
gem.authors = ["Ryan Jacobs"]
|
10
|
+
gem.email = ["ryan.mjacobs@gmail.com"]
|
11
|
+
gem.summary = %q{github-copywriter updates your copyrights... so you don't have to!}
|
12
|
+
gem.description = %q{github-copywriter scans through your repositories and updates any copyrights it finds.}
|
13
|
+
gem.homepage = "http://ryanmjacobs.github.io/github-copywriter"
|
14
|
+
gem.license = "MIT"
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
gem.files = `git ls-files -z`.split("\x0")
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
21
|
+
gem.required_ruby_version = ">= 1.9.2"
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
gem.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
gem.add_development_dependency "rake", "~> 10.0"
|
25
|
+
gem.add_development_dependency "rspec", "~> 3.1"
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
gem.add_runtime_dependency "octokit", "~> 3.7"
|
28
|
+
gem.add_runtime_dependency "colorize", "~> 0.7"
|
29
|
+
gem.add_runtime_dependency "highline", "~> 1.6"
|
28
30
|
end
|
data/lib/github-copywriter.rb
CHANGED
@@ -1,27 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
################################################################################
|
2
|
-
# github-copywriter
|
3
|
+
# github-copywriter/github-copywriter.rb
|
3
4
|
#
|
4
5
|
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com
|
5
6
|
################################################################################
|
6
7
|
|
7
|
-
require "
|
8
|
-
require "
|
8
|
+
require "github-copywriter/regex"
|
9
|
+
require "github-copywriter/version"
|
10
|
+
require "github-copywriter/octikit_wrapper"
|
11
|
+
|
9
12
|
require "base64"
|
13
|
+
require "octokit"
|
10
14
|
require "colorize"
|
11
|
-
require "pp" # debug tool
|
12
15
|
|
13
|
-
|
14
|
-
extend self
|
16
|
+
class Copywriter
|
15
17
|
|
16
|
-
VERSION = "0.0.4"
|
17
18
|
COMMIT_MSG = "Update copyright. ♥ github-copywriter\nFor more info, visit http://ryanmjacobs.github.io/github-copywriter"
|
18
19
|
|
19
|
-
def
|
20
|
-
# Grab username and pass
|
21
|
-
puts "Obtaining OAuth2 access_token from github."
|
22
|
-
username = ask("GitHub username: ") { |q| q.echo = true }
|
23
|
-
password = ask("GitHub password: ") { |q| q.echo = "*" }
|
24
|
-
|
20
|
+
def initialize(username, password)
|
25
21
|
# Auth to GitHub
|
26
22
|
@client = Octokit::Client.new(:login => username, :password => password)
|
27
23
|
|
@@ -34,108 +30,6 @@ module Copywriter
|
|
34
30
|
end
|
35
31
|
end
|
36
32
|
|
37
|
-
##
|
38
|
-
# Returns true if this is a file that we will update.
|
39
|
-
def accepted_name?(filename)
|
40
|
-
filename = File.basename(filename)
|
41
|
-
|
42
|
-
names = ["readme", "license"]
|
43
|
-
extensions = [".md", ".txt", ".html"]
|
44
|
-
|
45
|
-
if names.include? filename.downcase then return true end
|
46
|
-
if extensions.include? File.extname(filename.downcase) then return true end
|
47
|
-
end
|
48
|
-
|
49
|
-
##
|
50
|
-
# Updates copyright using regex, then commits it.
|
51
|
-
#
|
52
|
-
# repo = Repo to commit to, e.g. "user/repo_name"
|
53
|
-
# ref = Branch to commit to, e.g. "heads/master"
|
54
|
-
# file_path = File path on repo, e.g. "readme", "src/file.rb", etc.
|
55
|
-
#
|
56
|
-
def update_copyright(repo, ref, file_path)
|
57
|
-
|
58
|
-
# Grab file from repo
|
59
|
-
file = @client.contents(repo, :path => file_path)
|
60
|
-
if file[:type] != "file" then raise "error: #{file_path} on #{repo} is not a file!" end
|
61
|
-
|
62
|
-
# Have to do separate assignments b/c ruby shares strings,
|
63
|
-
# TODO: find a way around this
|
64
|
-
content = Base64.decode64(file[:content])
|
65
|
-
old_content = Base64.decode64(file[:content])
|
66
|
-
|
67
|
-
# Do the substitution
|
68
|
-
#
|
69
|
-
# Matches:
|
70
|
-
# Copyright 2014
|
71
|
-
# copyright 2014
|
72
|
-
#
|
73
|
-
# Copyright (C) 2014
|
74
|
-
# copyright (c) 2014
|
75
|
-
# Copyright © 2014
|
76
|
-
# copyright © 2014
|
77
|
-
#
|
78
|
-
# (c) 2014
|
79
|
-
# (C) 2014
|
80
|
-
# © 2014
|
81
|
-
begin
|
82
|
-
content.gsub!(/([Cc]opyright( \([Cc]\)| ©)?|\([Cc]\)|©) \d{4}/, "\\1 #{@cur_year}")
|
83
|
-
rescue
|
84
|
-
# try w/o "©" symbol if we had errors
|
85
|
-
content.gsub!(/([Cc]opyright( \([Cc]\))?|\([Cc]\)) \d{4}/, "\\1 #{@cur_year}")
|
86
|
-
end
|
87
|
-
|
88
|
-
# Only commit if we need to
|
89
|
-
if content != old_content then
|
90
|
-
@modified_files << {:path => file_path, :content => content}
|
91
|
-
puts " #{file_path} is now up-to-date.".green
|
92
|
-
else
|
93
|
-
puts " #{file_path} is already up-to-date."
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
##
|
98
|
-
# Commits files to a GitHub repo.
|
99
|
-
#
|
100
|
-
# repo = Repo to commit to, e.g. "user/repo_name"
|
101
|
-
# ref = Branch to commit to, e.g. "heads/master"
|
102
|
-
# file_mode = Filemode on repo, e.g. "100644"
|
103
|
-
# files = Array of {:path, :content}
|
104
|
-
# commit_msg = Commit message, e.g. "Update file.rb"
|
105
|
-
#
|
106
|
-
def commit_files(repo, ref, file_mode, files, commit_msg)
|
107
|
-
|
108
|
-
# Return if we don't have any files to commit
|
109
|
-
if files.size == 0 then return end
|
110
|
-
|
111
|
-
# Force file_mode to be either 100644 or 100775
|
112
|
-
if file_mode != "100644" or file_mode != "100775" then
|
113
|
-
file_mode = "100644"
|
114
|
-
end
|
115
|
-
|
116
|
-
# Construct temp. tree of files to commit
|
117
|
-
trees = Array.new
|
118
|
-
files.each do |file|
|
119
|
-
blob_sha = @client.create_blob(repo, Base64.encode64(file[:content]), "base64")
|
120
|
-
|
121
|
-
trees << {
|
122
|
-
:path => file[:path],
|
123
|
-
:mode => file_mode,
|
124
|
-
:type => "blob",
|
125
|
-
:sha => blob_sha
|
126
|
-
}
|
127
|
-
end
|
128
|
-
|
129
|
-
# Contruct the commit
|
130
|
-
latest_commit = @client.ref(repo, ref).object
|
131
|
-
base_tree = @client.commit(repo, latest_commit.sha).commit.tree
|
132
|
-
new_tree = @client.create_tree(repo, trees, :base_tree => base_tree.sha)
|
133
|
-
new_commit = @client.create_commit(repo, commit_msg, new_tree.sha, latest_commit.sha)
|
134
|
-
|
135
|
-
# Commit it!
|
136
|
-
@client.update_ref(repo, ref, new_commit.sha)
|
137
|
-
end
|
138
|
-
|
139
33
|
def run!(options={})
|
140
34
|
# Default options
|
141
35
|
options = {all: false, skip_forks: false, year: nil}.merge(options)
|
@@ -156,7 +50,7 @@ module Copywriter
|
|
156
50
|
end
|
157
51
|
|
158
52
|
# Get copyright year
|
159
|
-
|
53
|
+
cur_year = options[:year] || Time.now.year
|
160
54
|
|
161
55
|
# Loop through each repo
|
162
56
|
repos.each do |repo|
|
@@ -189,8 +83,21 @@ module Copywriter
|
|
189
83
|
tree[:tree].each do |file|
|
190
84
|
next if file[:type] != "blob"
|
191
85
|
|
192
|
-
if accepted_name?(file[:path]) then
|
193
|
-
|
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
|
90
|
+
|
91
|
+
# Update the copyright
|
92
|
+
new_content = Copywriter::Regex.update_copyright(cur_year, Base64.decode64(file[:content]))
|
93
|
+
|
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."
|
100
|
+
end
|
194
101
|
end
|
195
102
|
end
|
196
103
|
|
@@ -204,6 +111,4 @@ module Copywriter
|
|
204
111
|
end
|
205
112
|
end
|
206
113
|
end
|
207
|
-
|
208
|
-
private :update_copyright, :accepted_name?, :commit_files
|
209
114
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
################################################################################
|
2
|
+
# github-copywriter/octikit_wrapper.rb
|
3
|
+
#
|
4
|
+
# Octokit wrapper for commiting multiple files to a GitHub repo.
|
5
|
+
#
|
6
|
+
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com
|
7
|
+
################################################################################
|
8
|
+
|
9
|
+
class Copywriter
|
10
|
+
private
|
11
|
+
# Commits files to a GitHub repo.
|
12
|
+
# Requires @client to be already authorized with Copywriter.login!
|
13
|
+
#
|
14
|
+
# @param repo Repo to commit to, e.g. "user/repo_name"
|
15
|
+
# @param ref Branch to commit to, e.g. "heads/master"
|
16
|
+
# @param file_mode Filemode on repo, e.g. "100644"
|
17
|
+
# @param files Array of {:path, :content}
|
18
|
+
# @param commit_msg Commit message, e.g. "Update file.rb"
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# commit_files("user/repo", "heads/master", "100644", [{:path => "file.md", :content => "files content}], "modify file.md")
|
22
|
+
def commit_files(repo, ref, file_mode, files, commit_msg)
|
23
|
+
# Return if we don't have any files to commit
|
24
|
+
if files.size == 0 then return false end
|
25
|
+
|
26
|
+
# Force file_mode to be either 100644 or 100775
|
27
|
+
if file_mode != "100644" or file_mode != "100775" then
|
28
|
+
file_mode = "100644"
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
# Construct temp. tree of files to commit
|
33
|
+
trees = Array.new
|
34
|
+
files.each do |file|
|
35
|
+
blob_sha = @client.create_blob(repo, Base64.encode64(file[:content]), "base64")
|
36
|
+
|
37
|
+
trees << {
|
38
|
+
:path => file[:path],
|
39
|
+
:mode => file_mode,
|
40
|
+
:type => "blob",
|
41
|
+
:sha => blob_sha
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
# Contruct the commit
|
46
|
+
latest_commit = @client.ref(repo, ref).object
|
47
|
+
base_tree = @client.commit(repo, latest_commit.sha).commit.tree
|
48
|
+
new_tree = @client.create_tree(repo, trees, :base_tree => base_tree.sha)
|
49
|
+
new_commit = @client.create_commit(repo, commit_msg, new_tree.sha, latest_commit.sha)
|
50
|
+
|
51
|
+
# Commit it!
|
52
|
+
@client.update_ref(repo, ref, new_commit.sha)
|
53
|
+
return true
|
54
|
+
rescue
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
################################################################################
|
3
|
+
# github-copywriter/regex.rb
|
4
|
+
#
|
5
|
+
# All of the regex that's behind this amazing project :)
|
6
|
+
#
|
7
|
+
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com
|
8
|
+
################################################################################
|
9
|
+
|
10
|
+
class Copywriter
|
11
|
+
module Regex
|
12
|
+
extend self
|
13
|
+
|
14
|
+
# Returns true if this is a file that we will update, (otherwise false).
|
15
|
+
#
|
16
|
+
# @return [Boolean] True if name is accepted. False if otherwise.
|
17
|
+
def accepted_name?(filename)
|
18
|
+
filename = File.basename(filename)
|
19
|
+
|
20
|
+
names = ["readme", "license"]
|
21
|
+
extensions = [".md", ".txt", ".html"]
|
22
|
+
|
23
|
+
if names.include? filename.downcase then return true end
|
24
|
+
if extensions.include? File.extname(filename.downcase) then return true end
|
25
|
+
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
|
29
|
+
# Updates copyright using regex, then commits it.
|
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.
|
35
|
+
def update_copyright(year, old_content)
|
36
|
+
# Have to do separate assignments b/c ruby shares strings,
|
37
|
+
# TODO: find a way around this
|
38
|
+
|
39
|
+
# Do the substitution
|
40
|
+
#
|
41
|
+
# Matches:
|
42
|
+
# Copyright 2014
|
43
|
+
# copyright 2014
|
44
|
+
#
|
45
|
+
# Copyright (C) 2014
|
46
|
+
# copyright (c) 2014
|
47
|
+
# Copyright © 2014
|
48
|
+
# copyright © 2014
|
49
|
+
#
|
50
|
+
# (c) 2014
|
51
|
+
# (C) 2014
|
52
|
+
# © 2014
|
53
|
+
begin
|
54
|
+
new_content = \
|
55
|
+
old_content.gsub(/([Cc]opyright( \([Cc]\)| ©)?|\([Cc]\)|©) \d{4}/, "\\1 #{year}")
|
56
|
+
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}")
|
60
|
+
end
|
61
|
+
|
62
|
+
# Only commit if we need to
|
63
|
+
if new_content != old_content then
|
64
|
+
return new_content
|
65
|
+
else
|
66
|
+
return nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
################################################################################
|
2
|
+
# github-copywriter/version.rb
|
3
|
+
#
|
4
|
+
# Author: Ryan Jacobs <ryan.mjacobs@gmail.com
|
5
|
+
################################################################################
|
6
|
+
|
7
|
+
class Copywriter
|
8
|
+
|
9
|
+
# Current version
|
10
|
+
# @return [String]
|
11
|
+
VERSION = "0.1.0".freeze
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
###
|
4
|
+
# This spec desperately needs a rewrite.
|
5
|
+
# It works, but the display is all wrong
|
6
|
+
# and unreadable.
|
7
|
+
#
|
8
|
+
# (Sorry, I'm still learning how to format my rpecs.)
|
9
|
+
###
|
10
|
+
|
11
|
+
describe Copywriter do
|
12
|
+
regex = Copywriter::Regex
|
13
|
+
|
14
|
+
# Accepted
|
15
|
+
context "a filename matching README, LICENSE, or with the extensions .md, .txt, or .html" do
|
16
|
+
it { expect(regex.accepted_name? "README") .to be(true) }
|
17
|
+
it { expect(regex.accepted_name? "LICENSE") .to be(true) }
|
18
|
+
it { expect(regex.accepted_name? "README.md") .to be(true) }
|
19
|
+
it { expect(regex.accepted_name? "LICENSE.md") .to be(true) }
|
20
|
+
|
21
|
+
it { expect(regex.accepted_name? "whatever.md") .to be(true) }
|
22
|
+
it { expect(regex.accepted_name? "thing.html") .to be(true) }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Not Accepted
|
26
|
+
context "a filename NOT matching README, LICENSE, or with the extensions .md, .txt, or .html" do
|
27
|
+
it { expect(regex.accepted_name? "garbage") .to be(false) }
|
28
|
+
it { expect(regex.accepted_name? "colors.py") .to be(false) }
|
29
|
+
it { expect(regex.accepted_name? "list_files.c") .to be(false) }
|
30
|
+
it { expect(regex.accepted_name? "coolLib.js") .to be(false) }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
###
|
5
|
+
# This spec desperately needs a rewrite.
|
6
|
+
# It works, but the display is all wrong
|
7
|
+
# and unreadable.
|
8
|
+
#
|
9
|
+
# (Sorry, I'm still learning how to format my rpecs.)
|
10
|
+
###
|
11
|
+
|
12
|
+
copyrights = [
|
13
|
+
{ :old => "Copyright 1970", :new => "Copyright 2014" },
|
14
|
+
{ :old => "copyright 1970", :new => "copyright 2014" },
|
15
|
+
|
16
|
+
{ :old => "Copyright (C) 1970", :new => "Copyright (C) 2014" },
|
17
|
+
{ :old => "copyright (c) 1970", :new => "copyright (c) 2014" },
|
18
|
+
{ :old => "Copyright © 1970", :new => "Copyright © 2014" },
|
19
|
+
{ :old => "copyright © 1970", :new => "copyright © 2014" },
|
20
|
+
|
21
|
+
{ :old => "(c) 1970", :new => "(c) 2014" },
|
22
|
+
{ :old => "(C) 1970", :new => "(C) 2014" },
|
23
|
+
{ :old => "© 1970", :new => "© 2014" },
|
24
|
+
]
|
25
|
+
|
26
|
+
# ./lib/github-copywriter/regex.rb
|
27
|
+
describe Copywriter do
|
28
|
+
regex = Copywriter::Regex
|
29
|
+
|
30
|
+
# Copywriter::Regex.update_copyright ->
|
31
|
+
# should return the updated copyright if the input was out of date
|
32
|
+
context "an out-of-date copyright..." do
|
33
|
+
copyrights.each do |copyright|
|
34
|
+
updated_copyright = regex.update_copyright(2014, copyright[:old])
|
35
|
+
it { expect(updated_copyright).to eq(copyright[:new]) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Copywriter::Regex.update_copyright ->
|
40
|
+
# should return nil if the input was up-to-date
|
41
|
+
context "an up-to-date copyright..." do
|
42
|
+
copyrights.each do |copyright|
|
43
|
+
updated_copyright = regex.update_copyright(2014, copyright[:new])
|
44
|
+
it { expect(updated_copyright).to be(nil) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
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.0
|
4
|
+
version: 0.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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: octokit
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +72,28 @@ dependencies:
|
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.7
|
75
|
+
version: '0.7'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: highline
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
62
90
|
type: :runtime
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
94
|
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
96
|
+
version: '1.6'
|
69
97
|
description: github-copywriter scans through your repositories and updates any copyrights
|
70
98
|
it finds.
|
71
99
|
email:
|
@@ -76,6 +104,10 @@ extensions: []
|
|
76
104
|
extra_rdoc_files: []
|
77
105
|
files:
|
78
106
|
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CONTRIBUTING.md
|
110
|
+
- CONTRIBUTORS.md
|
79
111
|
- Gemfile
|
80
112
|
- LICENSE.txt
|
81
113
|
- README.md
|
@@ -83,6 +115,12 @@ files:
|
|
83
115
|
- bin/github-copywriter
|
84
116
|
- github-copywriter.gemspec
|
85
117
|
- lib/github-copywriter.rb
|
118
|
+
- lib/github-copywriter/octikit_wrapper.rb
|
119
|
+
- lib/github-copywriter/regex.rb
|
120
|
+
- lib/github-copywriter/version.rb
|
121
|
+
- spec/accepted_name_spec.rb
|
122
|
+
- spec/copyright_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
86
124
|
homepage: http://ryanmjacobs.github.io/github-copywriter
|
87
125
|
licenses:
|
88
126
|
- MIT
|
@@ -95,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
133
|
requirements:
|
96
134
|
- - ">="
|
97
135
|
- !ruby/object:Gem::Version
|
98
|
-
version: 1.
|
136
|
+
version: 1.9.2
|
99
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
138
|
requirements:
|
101
139
|
- - ">="
|
@@ -107,4 +145,7 @@ rubygems_version: 2.2.2
|
|
107
145
|
signing_key:
|
108
146
|
specification_version: 4
|
109
147
|
summary: github-copywriter updates your copyrights... so you don't have to!
|
110
|
-
test_files:
|
148
|
+
test_files:
|
149
|
+
- spec/accepted_name_spec.rb
|
150
|
+
- spec/copyright_spec.rb
|
151
|
+
- spec/spec_helper.rb
|