forkreadme 0.0.2 → 0.0.3
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.
- data/.gitignore +6 -0
- data/README.md +51 -18
- data/Rakefile +58 -0
- data/bin/forkreadme +1 -1
- data/forkreadme.gemspec +3 -0
- data/lib/forkreadme/errors.rb +1 -1
- data/lib/forkreadme/generator.rb +33 -27
- data/lib/forkreadme/version.rb +1 -1
- data/test/fixtures/README_with_images.md +5 -0
- data/test/fixtures/README_without_images.md +5 -0
- data/test/test_generator.rb +44 -0
- data/test/test_helper.rb +20 -0
- metadata +44 -3
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,34 +1,67 @@
|
|
1
|
-
|
1
|
+
# ForkReadme
|
2
2
|
|
3
|
-
|
4
|
-
why they exist. Mostly they're hanging around waiting for a pull request to be
|
5
|
-
merged into or rejected from the upstream repo. And since my changes are tucked
|
6
|
-
away in feature branches, it's not immediately obvious to visitors (or me) why I
|
7
|
-
created the fork, what I changed, and whether those changes have been merged
|
8
|
-
upstream.
|
3
|
+
This is a command-line utility for generating useful READMEs for GitHub forks.
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
I have quite a few forks which contain no useful indication of why they exist.
|
6
|
+
Mostly they're hanging around waiting for a pull request to be merged into or
|
7
|
+
rejected from the upstream repo. And since my changes are tucked away in feature
|
8
|
+
branches, it's not immediately obvious to visitors (including myself, six months
|
9
|
+
later) why I created the fork, what I changed, and whether or not those changes
|
10
|
+
have been merged upstream.
|
13
11
|
|
12
|
+
My solution is to create an orphan branch containing a README explaining what's
|
13
|
+
going on, and make that the default branch on GitHub. This little tool does the
|
14
|
+
first part automatically.
|
14
15
|
|
15
|
-
## Usage
|
16
16
|
|
17
|
-
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Get it via [RubyGems] [gem]:
|
20
|
+
|
21
|
+
```
|
18
22
|
$ gem install forkreadme
|
19
|
-
$ forkreadme generate
|
20
23
|
```
|
21
24
|
|
22
|
-
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
1. Create an empty branch with no history:
|
29
|
+
|
30
|
+
```
|
31
|
+
$ git checkout --orphan forkreadme
|
32
|
+
$ git rm -rf .
|
33
|
+
```
|
34
|
+
|
35
|
+
The `git rm` part is a bit scary, but it's just clearing the working area.
|
36
|
+
Check out `git help checkout` and search for `--orphan` for more info.
|
37
|
+
|
38
|
+
2. Generate the README:
|
39
|
+
|
40
|
+
```
|
41
|
+
$ forkreadme > README.md
|
42
|
+
```
|
43
|
+
|
44
|
+
Here's [an example] [example] of the output.
|
45
|
+
|
46
|
+
3. Push it to GitHub:
|
47
|
+
|
48
|
+
```
|
49
|
+
$ git add README.md
|
50
|
+
$ git commit -m "Add README.md"
|
51
|
+
$ git push origin forkreadme
|
52
|
+
```
|
53
|
+
|
54
|
+
4. [Change the default branch] [set-branch] on GitHub.
|
23
55
|
|
24
56
|
|
25
57
|
## License
|
26
58
|
|
27
|
-
|
59
|
+
ForkReadme is available under the [MIT license] [license].
|
28
60
|
|
29
61
|
|
30
62
|
|
31
63
|
|
32
|
-
[
|
33
|
-
[
|
34
|
-
[
|
64
|
+
[gem]: https://rubygems.org/gems/forkreadme
|
65
|
+
[example]: https://github.com/adammck/grit#readme
|
66
|
+
[set-branch]: https://github.com/blog/421-pick-your-default-branch
|
67
|
+
[license]: https://raw.github.com/adammck/forkreadme/master/LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require "fileutils"
|
5
|
+
require "rake/testtask"
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.pattern = "test/test_*.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
# Check fixtures before running tests.
|
12
|
+
task :test => "fixtures:check"
|
13
|
+
|
14
|
+
|
15
|
+
namespace :fixtures do
|
16
|
+
def fixture name
|
17
|
+
File.join File.dirname(__FILE__), "test", "fixtures", name
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Check for test fixtures"
|
21
|
+
task :check do
|
22
|
+
unless File.exists? fixture "empty"
|
23
|
+
puts "Fixtures have not been fetched yet."
|
24
|
+
puts "Run $(rake fixtures:fetch) first."
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Fetch test fixtures"
|
30
|
+
task :fetch do
|
31
|
+
empty = fixture "empty"
|
32
|
+
unless File.exists? empty
|
33
|
+
%x[mkdir #{empty}]
|
34
|
+
end
|
35
|
+
|
36
|
+
git_repo = fixture "git_repo"
|
37
|
+
unless File.exists? git_repo
|
38
|
+
%x[git init #{git_repo}]
|
39
|
+
end
|
40
|
+
|
41
|
+
github_repo = fixture "github_repo"
|
42
|
+
unless File.exists? github_repo
|
43
|
+
%x[git clone git://github.com/forkreadme-test-user-1/test.git #{github_repo} &>/dev/null]
|
44
|
+
end
|
45
|
+
|
46
|
+
github_fork = fixture "github_fork"
|
47
|
+
unless File.exists? github_fork
|
48
|
+
%x[git clone git://github.com/forkreadme-test-user-2/test.git #{github_fork} &>/dev/null]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Delete test fixtures"
|
53
|
+
task :flush do
|
54
|
+
%w[empty git_repo github_repo github_fork].each do |name|
|
55
|
+
FileUtils.rm_rf fixture name
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/bin/forkreadme
CHANGED
@@ -22,7 +22,7 @@ path = ARGV.shift || "."
|
|
22
22
|
|
23
23
|
begin
|
24
24
|
dir = File.expand_path path, Dir.pwd
|
25
|
-
puts ForkReadme::Generator.new(dir
|
25
|
+
puts ForkReadme::Generator.new(dir).readme(opts[:pullstatus])
|
26
26
|
|
27
27
|
rescue ForkReadme::Error => err
|
28
28
|
$stderr.puts err
|
data/forkreadme.gemspec
CHANGED
@@ -16,6 +16,9 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.add_dependency "trollop", "~> 1.16.2"
|
17
17
|
gem.add_dependency "octokit", "~> 1.0.2"
|
18
18
|
|
19
|
+
gem.add_development_dependency "simplecov", "~> 0.6.4"
|
20
|
+
gem.add_development_dependency "vcr", "~> 2.1.1"
|
21
|
+
|
19
22
|
gem.files = `git ls-files`.split($\)
|
20
23
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
24
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
data/lib/forkreadme/errors.rb
CHANGED
data/lib/forkreadme/generator.rb
CHANGED
@@ -8,17 +8,16 @@ module ForkReadme
|
|
8
8
|
class Generator
|
9
9
|
include URI::REGEXP::PATTERN
|
10
10
|
|
11
|
-
def initialize path
|
11
|
+
def initialize path
|
12
12
|
@path = path
|
13
|
-
@with_images = with_images
|
14
13
|
|
15
14
|
repo_name = github_repo_name @path
|
16
15
|
@repo = octokit.repo repo_name
|
17
16
|
@parent = parent_of @repo
|
18
17
|
end
|
19
18
|
|
20
|
-
def readme
|
21
|
-
intro + "\n\n" + (links.join "\n")
|
19
|
+
def readme with_images=false
|
20
|
+
intro + "\n\n" + (links(with_images).join "\n")
|
22
21
|
end
|
23
22
|
|
24
23
|
# Public: Returns the introduction paragraph.
|
@@ -27,21 +26,30 @@ module ForkReadme
|
|
27
26
|
"This is a fork of #{link}, with pull requests:"
|
28
27
|
end
|
29
28
|
|
30
|
-
# Public:
|
31
|
-
|
29
|
+
# Public: Generate a paragraph summarizing the pull requests.
|
30
|
+
#
|
31
|
+
# with_images - Include pullstat.us images?
|
32
|
+
#
|
33
|
+
# Returns the paragraph as Markdown.
|
34
|
+
def links with_images
|
32
35
|
pull_requests(@parent).select do |pull|
|
33
|
-
pull.head.repo
|
36
|
+
@repo.id == (pull.head.repo && pull.head.repo.id)
|
34
37
|
|
35
38
|
end.map do |pull|
|
36
|
-
"* " + line_for(pull,
|
39
|
+
"* " + line_for(pull, with_images)
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
43
|
private
|
41
44
|
|
42
|
-
# Private:
|
43
|
-
|
44
|
-
|
45
|
+
# Private: Generate a one-line summary of a pull request.
|
46
|
+
#
|
47
|
+
# pull_request - The Octokit pull request to be summarized.
|
48
|
+
# with_image - Include a pullstat.us image?
|
49
|
+
#
|
50
|
+
# Returns the line as Markdown.
|
51
|
+
def line_for pull_request, with_image
|
52
|
+
img = if with_image
|
45
53
|
image "Status of ##{pull_request.number}", status_image(pull_request)
|
46
54
|
end
|
47
55
|
|
@@ -50,14 +58,14 @@ module ForkReadme
|
|
50
58
|
end
|
51
59
|
|
52
60
|
# Private: Returns the parent repo (as an Octokit repo) of an Octokit repo,
|
53
|
-
# or raises
|
61
|
+
# or raises NotGitHubFork if the repo does not have a parent.
|
54
62
|
def parent_of child_repo
|
55
63
|
if child_repo.parent
|
56
64
|
parent_repo_name = full_name child_repo.parent
|
57
65
|
octokit.repo parent_repo_name
|
58
66
|
else
|
59
67
|
child_name = full_name child_repo
|
60
|
-
raise
|
68
|
+
raise NotGitHubFork.new "Not a GitHub fork: #{child_name}"
|
61
69
|
end
|
62
70
|
end
|
63
71
|
|
@@ -71,14 +79,6 @@ module ForkReadme
|
|
71
79
|
"!" + link_to(alt_text, href)
|
72
80
|
end
|
73
81
|
|
74
|
-
# Private: Returns an Array containing the logins of all collaborators for
|
75
|
-
# an Octokit repo.
|
76
|
-
def collaborator_logins repo
|
77
|
-
octokit.collabs(full_name repo).map do |user|
|
78
|
-
user.login
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
82
|
# Private: Returns the URL of the status image (via pullstat.us) for an
|
83
83
|
# Octokit pull request.
|
84
84
|
def status_image pull_request
|
@@ -98,7 +98,13 @@ module ForkReadme
|
|
98
98
|
# Private: Returns the full GitHub repo name (e.g. adammck/forkreadme) of a
|
99
99
|
# Git working directory, or raises NotGitHubRepo.
|
100
100
|
def github_repo_name path
|
101
|
-
|
101
|
+
origin = remote_origin_url path
|
102
|
+
|
103
|
+
if origin == ""
|
104
|
+
raise NotGitHubRepo.new "No remote origin URL: #{path}"
|
105
|
+
end
|
106
|
+
|
107
|
+
clone_url = parse_url origin
|
102
108
|
|
103
109
|
if clone_url.host.downcase != "github.com"
|
104
110
|
raise NotGitHubRepo.new "Not a GitHub repo: #{path}"
|
@@ -117,9 +123,9 @@ module ForkReadme
|
|
117
123
|
@ok ||= Octokit.new(:auto_traversal=>true)
|
118
124
|
end
|
119
125
|
|
120
|
-
# Private: Returns the remote
|
121
|
-
# raises NotGitRepo.
|
122
|
-
def
|
126
|
+
# Private: Returns the remote origin URL of a Git working directory (which
|
127
|
+
# may be an empty string, if the repo has no origin) or raises NotGitRepo.
|
128
|
+
def remote_origin_url path
|
123
129
|
unless is_working_dir path
|
124
130
|
raise NotGitRepo.new "Not a Git repo: #{path}"
|
125
131
|
end
|
@@ -150,12 +156,12 @@ module ForkReadme
|
|
150
156
|
|
151
157
|
# Private: Returns a filename with the extension removed.
|
152
158
|
def chop_extension filename
|
153
|
-
filename.sub
|
159
|
+
filename.sub %r{\.\w+$}, ""
|
154
160
|
end
|
155
161
|
|
156
162
|
# Private: Returns a filename with the leading slash removed.
|
157
163
|
def chop_leading_slash filename
|
158
|
-
filename.sub
|
164
|
+
filename.sub %r{^/}, ""
|
159
165
|
end
|
160
166
|
end
|
161
167
|
end
|
data/lib/forkreadme/version.rb
CHANGED
@@ -0,0 +1,5 @@
|
|
1
|
+
This is a fork of [test] (https://github.com/forkreadme-test-user-1/test), with pull requests:
|
2
|
+
|
3
|
+
* [Add empty GAMMA file.] (https://github.com/forkreadme-test-user-1/test/pull/3) ![Status of #3] (https://pullstat.us/forkreadme-test-user-1/test/pull/3)
|
4
|
+
* [Add empty BETA file.] (https://github.com/forkreadme-test-user-1/test/pull/2) ![Status of #2] (https://pullstat.us/forkreadme-test-user-1/test/pull/2)
|
5
|
+
* [Add empty ALPHA file.] (https://github.com/forkreadme-test-user-1/test/pull/1) ![Status of #1] (https://pullstat.us/forkreadme-test-user-1/test/pull/1)
|
@@ -0,0 +1,5 @@
|
|
1
|
+
This is a fork of [test] (https://github.com/forkreadme-test-user-1/test), with pull requests:
|
2
|
+
|
3
|
+
* [Add empty GAMMA file.] (https://github.com/forkreadme-test-user-1/test/pull/3)
|
4
|
+
* [Add empty BETA file.] (https://github.com/forkreadme-test-user-1/test/pull/2)
|
5
|
+
* [Add empty ALPHA file.] (https://github.com/forkreadme-test-user-1/test/pull/1)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper.rb")
|
5
|
+
|
6
|
+
describe Generator do
|
7
|
+
describe "Errors" do
|
8
|
+
it "rejects paths which are not git repos" do
|
9
|
+
assert_raises(NotGitRepo) do
|
10
|
+
Generator.new fixture("empty")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "rejects repos which are not hosted on github" do
|
15
|
+
assert_raises(NotGitHubRepo) do
|
16
|
+
Generator.new fixture("git_repo")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "rejects github repos which are not forks" do
|
21
|
+
VCR.use_cassette("github_repo") do
|
22
|
+
assert_raises(NotGitHubFork) do
|
23
|
+
Generator.new fixture("github_repo")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "README" do
|
30
|
+
it "generates a readme without images" do
|
31
|
+
VCR.use_cassette("github_fork") do
|
32
|
+
g = Generator.new fixture("github_fork")
|
33
|
+
assert_equal File.read(fixture("README_without_images.md")), g.readme
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "generates a readme with images" do
|
38
|
+
VCR.use_cassette("github_fork") do
|
39
|
+
g = Generator.new fixture("github_fork")
|
40
|
+
assert_equal File.read(fixture("README_with_images.md")), g.readme(true)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require "simplecov"
|
5
|
+
SimpleCov.start
|
6
|
+
|
7
|
+
require "vcr"
|
8
|
+
require "minitest/autorun"
|
9
|
+
|
10
|
+
require "forkreadme"
|
11
|
+
include ForkReadme
|
12
|
+
|
13
|
+
VCR.configure do |c|
|
14
|
+
c.cassette_library_dir = "test/fixtures/cassettes"
|
15
|
+
c.hook_into :faraday
|
16
|
+
end
|
17
|
+
|
18
|
+
def fixture name
|
19
|
+
File.join File.dirname(__FILE__), "fixtures", name
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forkreadme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: trollop
|
@@ -43,6 +43,38 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 1.0.2
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: simplecov
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.6.4
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.4
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: vcr
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.1.1
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.1.1
|
46
78
|
description:
|
47
79
|
email:
|
48
80
|
- adam.mckaig@gmail.com
|
@@ -55,12 +87,17 @@ files:
|
|
55
87
|
- Gemfile
|
56
88
|
- LICENSE
|
57
89
|
- README.md
|
90
|
+
- Rakefile
|
58
91
|
- bin/forkreadme
|
59
92
|
- forkreadme.gemspec
|
60
93
|
- lib/forkreadme.rb
|
61
94
|
- lib/forkreadme/errors.rb
|
62
95
|
- lib/forkreadme/generator.rb
|
63
96
|
- lib/forkreadme/version.rb
|
97
|
+
- test/fixtures/README_with_images.md
|
98
|
+
- test/fixtures/README_without_images.md
|
99
|
+
- test/test_generator.rb
|
100
|
+
- test/test_helper.rb
|
64
101
|
homepage: https://github.com/adammck/forkreadme
|
65
102
|
licenses:
|
66
103
|
- MIT
|
@@ -86,4 +123,8 @@ rubygems_version: 1.8.23
|
|
86
123
|
signing_key:
|
87
124
|
specification_version: 3
|
88
125
|
summary: Generate useful READMEs for GitHub forks
|
89
|
-
test_files:
|
126
|
+
test_files:
|
127
|
+
- test/fixtures/README_with_images.md
|
128
|
+
- test/fixtures/README_without_images.md
|
129
|
+
- test/test_generator.rb
|
130
|
+
- test/test_helper.rb
|