octocam 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61efce8fc4172a636811a41aa6decdeab00062c9
4
- data.tar.gz: cbfcc063fb9a005dac79e370df55fb5c68f1a9e2
3
+ metadata.gz: fc7bca552f1d0e63087cea4a7079135f8eb8273d
4
+ data.tar.gz: f52493aa08f0abf773e73f78e4f4f958277247ab
5
5
  SHA512:
6
- metadata.gz: 4491e3474ededd50ee5e076f612e6ac326f9dd62d758a0ea60c9e00c4d4f51bf3de93d6c96eada9608c0987323c1f0f6415223998b0b641371f90ec38e02ff3a
7
- data.tar.gz: 5808abae53dab9c70b9d79af4f06c759efbbaa9565af6de83cf55365d0e0834834a8eb35867d93d299514995672e187034397ec095080ade12c9315d3b364eea
6
+ metadata.gz: f94afb8856c8f57aaf40c26b3271a20ab0e738a71f9298c3b6ad3aa1cd4a9180adba873662f5a430e443ba935c83792a480bdf1c888447c49a09570cb2457ca5
7
+ data.tar.gz: 024a22120ef9a8f83a8096fdfd1e0c81a378e10b7c9e782bf2a3c5c65e0ca17aedbeafd4b3081bce9b1f0ebefd5d64a25619feb9c98952626804e52de0b03efc
data/README.md CHANGED
@@ -1,28 +1,35 @@
1
1
  # Octocam
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/octocam`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Octocam generate simple CHANGELOG with Markdown from GitHub pull requests.
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
7
+ $ gem install octocam
10
8
 
11
- ```ruby
12
- gem 'octocam'
13
- ```
9
+ ### GitHub Token
14
10
 
15
- And then execute:
11
+ If you want to generate CHANGELOG from private repo, set OCTOCAM_GITHUB_TOKEN to your environment variable.
16
12
 
17
- $ bundle
13
+ **You can easily [generate it here](https://github.com/settings/applications)**.
18
14
 
19
- Or install it yourself as:
15
+ Then, add to your `~/.bash_profile` or `~/.zshrc` or any other place to load ENV variables string.
20
16
 
21
- $ gem install octocam
17
+ ```
18
+ export OCTOCAM_GITHUB_TOKEN="your-40-digit-github-token"
19
+ ```
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ```
24
+ octocam -o zephiransas -r octocam -f 2015-01-01 -t 2015-01-31
25
+ ```
26
+
27
+ ```
28
+ -o (required) owner of the GitHub repository
29
+ -r (required) name of the GitHub repository
30
+ -f (required) start of merged at
31
+ -t (required) end of merged at
32
+ ```
26
33
 
27
34
  ## Development
28
35
 
@@ -32,7 +39,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
39
 
33
40
  ## Contributing
34
41
 
35
- 1. Fork it ( https://github.com/[my-github-username]/octocam/fork )
42
+ 1. Fork it ( https://github.com/zephiransas/octocam/fork )
36
43
  2. Create your feature branch (`git checkout -b my-new-feature`)
37
44
  3. Commit your changes (`git commit -am 'Add some feature'`)
38
45
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,40 +1,20 @@
1
1
  require 'octokit'
2
2
  require 'optparse'
3
3
  require 'time'
4
+ require 'octocam/parser'
4
5
 
5
6
  class Octocam::Client
6
7
 
7
8
  def generate
8
- args = Argument.new
9
+ options = Octocam::Parser.parse_options
9
10
 
10
11
  Octokit.auto_paginate = true
11
12
  client = Octokit::Client.new(access_token: ENV['OCTOCAM_GITHUB_TOKEN'])
12
13
 
13
- pull_requests = client.pull_requests("#{args.owner}/#{args.repository}", state: 'closed').reject{|pr| pr[:merged_at] == nil }
14
- pull_requests.select{|pr| pr[:merged_at].localtime >= args.from && pr[:merged_at].localtime <= args.to }.sort{|a, b| -(a[:merged_at] <=> b[:merged_at]) }.each do |pull_request|
14
+ pull_requests = client.pull_requests("#{options[:owner]}/#{options[:repository]}", state: 'closed').reject{|pr| pr[:merged_at] == nil }
15
+ pull_requests.select{|pr| pr[:merged_at].localtime >= options[:from] && pr[:merged_at].localtime <= options[:to] }.sort{|a, b| -(a[:merged_at] <=> b[:merged_at]) }.each do |pull_request|
15
16
  puts "- #{pull_request[:title]} [[##{pull_request[:number]}](#{pull_request[:html_url]})]"
16
17
  end
17
18
  end
18
19
 
19
- class Argument
20
- def initialize
21
- params = ARGV.getopts('o:r:f:t:')
22
- @owner = params['o']
23
- @repository = params['r']
24
- @from = params['f']
25
- @to = params['t']
26
- end
27
-
28
- def owner; @owner; end
29
- def repository; @repository; end
30
-
31
- def from
32
- Time.parse(@from)
33
- end
34
-
35
- def to
36
- Time.parse(@to)
37
- end
38
- end
39
-
40
20
  end
@@ -0,0 +1,79 @@
1
+ require 'optparse'
2
+
3
+ module Octocam
4
+ class Parser
5
+ def self.parse_options
6
+ options = {
7
+ owner: nil,
8
+ repository: nil,
9
+ from: nil,
10
+ to: nil
11
+ }
12
+
13
+ parser = OptionParser.new do |opts|
14
+ opts.banner = 'Usage: octocam -o [owner] -r [repository] -f [merged_from] -t [merged_to]'
15
+
16
+ opts.accept(Time) do |s|
17
+ begin
18
+ Time.parse(s) if s
19
+ rescue
20
+ raise "#{s} is not date format. ex) 2015-08-22"
21
+ end
22
+ end
23
+
24
+ opts.on('-o [NAME]', 'Username of the owner of target GitHub repo') do |v|
25
+ options[:owner] = v
26
+ end
27
+ opts.on('-r [NAME]', 'target repository name') do |v|
28
+ options[:repository] = v
29
+ end
30
+ opts.on('-f YYYY-MM-DD', Time, 'From date of merged date') do |v|
31
+ options[:from] = v
32
+ end
33
+ opts.on('-t YYYY-MM-DD', Time, 'To date of merged date') do |v|
34
+ options[:to] = v
35
+ end
36
+ opts.parse!(ARGV)
37
+ end
38
+
39
+ if !options[:from] || !options[:to]
40
+ puts parser.banner
41
+ exit
42
+ end
43
+
44
+ if !options[:owner] || !options[:repository]
45
+ options[:owner], options[:repository] = detect_owner_and_repository
46
+ end
47
+
48
+ if !options[:owner] || !options[:repository]
49
+ puts parser.banner
50
+ exit
51
+ end
52
+
53
+ options
54
+ end
55
+
56
+ private
57
+
58
+ def self.detect_owner_and_repository
59
+ remote = `git config --get remote.origin.url`
60
+
61
+ # git@github.com:zephiransas/octocam.git
62
+ match = /.*(?:[:\/])((?:-|\w|\.)*)\/((?:-|\w|\.)*)(?:\.git).*/.match(remote)
63
+ if match
64
+ puts "Detected owner:#{match[1]}, repository:#{match[2]}"
65
+ return [match[1], match[2]]
66
+ end
67
+
68
+ # https://github.com/zephiransas/octocam
69
+ match = /.*\/((?:-|\w|\.)*)\/((?:-|\w|\.)*).*/.match(remote)
70
+ if match
71
+ puts "Detected owner:#{match[1]}, repository:#{match[2]}"
72
+ return [match[1], match[2]]
73
+ end
74
+
75
+ []
76
+ end
77
+
78
+ end
79
+ end
@@ -1,3 +1,3 @@
1
1
  module Octocam
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octocam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takafumi Yoshida
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-01 00:00:00.000000000 Z
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,6 +85,7 @@ files:
85
85
  - exe/octocam
86
86
  - lib/octocam.rb
87
87
  - lib/octocam/client.rb
88
+ - lib/octocam/parser.rb
88
89
  - lib/octocam/version.rb
89
90
  - octocam.gemspec
90
91
  homepage: https://github.com/zephiransas/octocam