Skip to content
Browse files

Fetch user and project from origin remote config

Also update the CLI so that the CHANGELOG gets overwritten instead of
just printed out.
  • Loading branch information...
1 parent 6c1e749 commit f4b6a9807d00950a0eb005d3986b115f823f9ecb @pcreux committed Dec 12, 2011
View
2 bin/pimpmychangelog
@@ -2,4 +2,4 @@
require File.expand_path('../../lib/pimpmychangelog.rb', __FILE__)
-PimpMyChangelog::CLI.run!(ARGV)
+PimpMyChangelog::CLI.run!
View
2 lib/pimpmychangelog.rb
@@ -1,3 +1,3 @@
-%w(pimper parser cli version).each do |file|
+%w(pimper parser git_remote cli version).each do |file|
require File.expand_path("../pimpmychangelog/#{file}.rb", __FILE__)
end
View
45 lib/pimpmychangelog/cli.rb
@@ -1,24 +1,43 @@
module PimpMyChangelog
class CLI
- def self.run!(args)
- unless args.size == 3
- puts "Usage: pimpmychangelog github_user github_project CHANGELOG.md"
- exit 1
- end
+ def self.run!
+ new.run
+ end
- new(*args).run
+ def initialize
+ @git_remote = GitRemote.new
end
- attr_reader :user, :project, :changelog_path
+ def run
+ changelog = read_changelog
+ puts changelog
+ puts ""
+ puts "In case something goes wrong we printed out your current #{changelog_path} above"
- def initialize(user, project, changelog_path)
- @user = user
- @project = project
- @changelog_path = changelog_path
+ write_changelog(Pimper.new(user, project, changelog).better_changelog)
+ puts "Your changelog is now pimped!"
end
- def run
- puts Pimper.new(user, project, File.read(changelog_path)).better_changelog
+ private
+
+ def user
+ @git_remote.user
+ end
+
+ def project
+ @git_remote.project
+ end
+
+ def changelog_path
+ "CHANGELOG.md"
+ end
+
+ def read_changelog
+ File.read(changelog_path)
+ end
+
+ def write_changelog(content)
+ File.open(changelog_path, 'w') { |f| f.write content }
end
end
end
View
22 lib/pimpmychangelog/git_remote.rb
@@ -0,0 +1,22 @@
+class GitRemote
+ def initialize
+ match = fetch_url.match(/(\w+)\/(\w+)/)
+ @user = match[1]
+ @project = match[2]
+ unless @user && @project
+ raise "Can't extract github user and project from origin remote"
+ end
+ end
+
+ attr_reader :user, :project
+
+ private
+
+ def fetch_url
+ @fetch_url ||= run_command.split(' ').last
+ end
+
+ def run_command
+ `git remote show origin | grep "Fetch URL"`
+ end
+end
View
5 spec/cli_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe CLI ,"#run"do
+
+end
View
8 spec/git_remote_spec.rb
@@ -0,0 +1,8 @@
+require 'spec_helper'
+
+describe GitRemote do
+ context "when working on pcreux/pimpmychangelog" do
+ its(:user) { should == 'pcreux' }
+ its(:project) { should == 'pimpmychangelog' }
+ end
+end
View
4 spec/pimper_spec.rb
@@ -67,7 +67,7 @@
You know what? [@pcreux][] closed issue [#123][].
And this is my link, don't touch it: [Adequate][http://adequatehq.com]
-<!--- The following link definitions are generated by PimpMyChangelog --->
+<!--- The following link definition list is generated by PimpMyChangelog --->
[#123]: https://github.com/gregbell/activeadmin/issues/123
[@pcreux]: https://github.com/pcreux
EOS
@@ -84,7 +84,7 @@
You know what? [@pcreux][] closed issue [#123][].
And this is my link, don't touch it: [Adequate][http://adequatehq.com]
-<!--- The following link definitions are generated by PimpMyChangelog --->
+<!--- The following link definition list is generated by PimpMyChangelog --->
[#123]: https://github.com/gregbell/activeadmin/issues/123
[#300]: https://github.com/gregbell/activeadmin/issues/300
[@pcreux]: https://github.com/pcreux

0 comments on commit f4b6a98

Please sign in to comment.
Something went wrong with that request. Please try again.