github_changelog_entry 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: baa32aa33e7e1860ea19a7c6bf7108e257a6d97d465e31c6fb907cff90e6e805
4
+ data.tar.gz: 16483518f5e399c26cd75c557df15f505988f02d530f1bb2bd8da2226ab11187
5
+ SHA512:
6
+ metadata.gz: 27116d5e083f671840887579a6cbce97be0a4ecaca5dec3243387c4e8299f24acdc378aa925acefd63dc63fb7c601559ee99fe48067023665d187f0b6792b8a0
7
+ data.tar.gz: f9900ce2ca8978d145d438f548efbad89a2881c6f6cd43bc23bcc2fdcee36b7d4eae5476e12a76843159bd739e7780afae6af5b7cad74f8f7cbaa593355b648b
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .byebug_history
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.6
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in github_changelog_entry.gemspec
4
+ gemspec
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ github_changelog_entry (0.1.0)
5
+ octokit (~> 4.0)
6
+ paint
7
+ thor
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.5.2)
13
+ public_suffix (>= 2.0.2, < 4.0)
14
+ byebug (11.0.0)
15
+ faraday (0.15.4)
16
+ multipart-post (>= 1.2, < 3)
17
+ minitest (5.11.3)
18
+ multipart-post (2.0.0)
19
+ octokit (4.13.0)
20
+ sawyer (~> 0.8.0, >= 0.5.3)
21
+ paint (2.1.0)
22
+ public_suffix (3.0.3)
23
+ rake (10.5.0)
24
+ sawyer (0.8.1)
25
+ addressable (>= 2.3.5, < 2.6)
26
+ faraday (~> 0.8, < 1.0)
27
+ thor (0.20.3)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 2.0)
34
+ byebug
35
+ github_changelog_entry!
36
+ minitest (~> 5.0)
37
+ rake (~> 10.0)
38
+
39
+ BUNDLED WITH
40
+ 2.0.1
@@ -0,0 +1,52 @@
1
+ # Github Changelog Entry
2
+
3
+ Simple changelog assistant for a team working with github. Fetches issues from github and outputs them in a format that can be copy pasted into your changelog and edited to fit your needs.
4
+
5
+ The idea here is NOT to have a fully automatic changelog.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "github_changelog_entry"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install github_changelog_entry
22
+
23
+ ## Usage
24
+
25
+ ### Generating a new changelog entry
26
+
27
+ `gce generate -t <github_token> -r <repo_name>`
28
+
29
+ This will use all of the issues created since the last release.
30
+
31
+ ### List of options
32
+
33
+ ```
34
+ -l, [--default-to-latest-tag], [--no-default-to-latest-tag] # If false, will not try to limit the query to the issues created after a given tag
35
+ # Default: true
36
+ -o, [--origin-tag=ORIGIN_TAG] # Choose a given tag as an origin
37
+ -m, [--milestone-number=MILESTONE_NUMBER] # Select issues linked to this milestone (the number needs to be in the milestone title separated by spaces)
38
+ -s, [--issue-state=ISSUE_STATE] # Override the state parameter
39
+ # Default: closed
40
+ # Possible values: open, closed, all
41
+
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alxckn/github_changelog_entry.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "github_changelog_entry"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/gce ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'github_changelog_entry/cli'
3
+ GithubChangelogEntry::CLI.start
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "github_changelog_entry/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "github_changelog_entry"
8
+ spec.version = GithubChangelogEntry::VERSION
9
+ spec.authors = ["Alexandre Chakroun"]
10
+ spec.email = ["alexandre.chakroun@gmail.com"]
11
+
12
+ spec.summary = %q{Create a new changelog entry using github API}
13
+
14
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
15
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+ else
19
+ raise "RubyGems 2.0 or newer is required to protect against " \
20
+ "public gem pushes."
21
+ end
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "minitest", "~> 5.0"
35
+ spec.add_development_dependency "byebug"
36
+ spec.add_dependency "octokit", "~> 4.0"
37
+ spec.add_dependency "thor"
38
+ spec.add_dependency "paint"
39
+ end
@@ -0,0 +1,5 @@
1
+ require "github_changelog_entry/version"
2
+
3
+ module GithubChangelogEntry
4
+ class Error < StandardError; end
5
+ end
@@ -0,0 +1,40 @@
1
+ require "thor"
2
+ require "paint"
3
+ require "github_changelog_entry/github"
4
+ require "github_changelog_entry/generator"
5
+ require "byebug"
6
+
7
+ module GithubChangelogEntry
8
+ class CLI < Thor
9
+ class_option :repo, desc: "Repository", aliases: "-r", required: true
10
+ class_option :token, desc: "Github token", aliases: "-t", required: true
11
+
12
+ desc "generate", "Generates a new changelog raw entry"
13
+ option :default_to_latest_tag,
14
+ aliases: "-l",
15
+ required: false,
16
+ default: true,
17
+ type: :boolean,
18
+ desc: %q{If false, will not try to limit the query to the issues created after a given tag}
19
+ option :origin_tag, aliases: "-o", required: false, desc: %q{Choose a given tag as an origin}
20
+ option :milestone_number, aliases: "-m", required: false, desc: %q{Select issues linked to this milestone (the number needs to be in the milestone title separated by spaces)}
21
+ option :issue_state, aliases: "-s", required: false, default: "closed", enum: ["open", "closed", "all"], desc: %q{Override the state parameter}
22
+ def generate
23
+ puts Paint["Generating a new changelog entry", :blue, :bold]
24
+
25
+ github_handler = GithubChangelogEntry::Github.new(options[:token], options[:repo])
26
+
27
+ issues_options = options.select do |key, value|
28
+ [
29
+ "origin_tag",
30
+ "milestone_number",
31
+ "default_to_latest_tag",
32
+ "issue_state"
33
+ ].include?(key)
34
+ end
35
+ GithubChangelogEntry::Generator.new.generate(
36
+ github_handler.closed_issues(issues_options)
37
+ )
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ require "github_changelog_entry/github"
2
+
3
+ module GithubChangelogEntry
4
+ class Generator
5
+ def generate(issues)
6
+ print_version
7
+
8
+ print_section("Enhancements")
9
+ print_section("Bugs")
10
+ print_section("Chores")
11
+ print_section("Hotfix")
12
+
13
+ issues.each do |issue|
14
+ puts " - [\\##{issue[:number]}](#{issue[:html_url]}): #{issue[:title]}"
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def print_version
21
+ sep
22
+ new_line
23
+ puts "## <version_number>"
24
+ new_line
25
+ end
26
+
27
+ def print_section(section_name)
28
+ puts "### #{section_name}"
29
+ new_line
30
+ end
31
+
32
+ def new_line
33
+ puts ""
34
+ end
35
+
36
+ def sep
37
+ puts "--"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,71 @@
1
+ require "octokit"
2
+ require "paint"
3
+
4
+ module GithubChangelogEntry
5
+ class Github
6
+ def initialize(github_token, repo)
7
+ @github_token = github_token
8
+ @repo = repo
9
+ end
10
+
11
+ def closed_issues(options = {})
12
+ filters = { state: "closed" }
13
+
14
+ tag_commit = if options["origin_tag"]
15
+ commit(options["origin_tag"])
16
+ elsif options["default_to_latest_tag"]
17
+ commit(nil)
18
+ end
19
+ filters = filters.merge(since: tag_commit[:commit][:committer][:date]) if tag_commit
20
+
21
+ if options["milestone_number"]
22
+ m = milestone(options["milestone_number"])
23
+ unless m.nil?
24
+ filters.merge!(milestone: m[:number])
25
+ puts Paint["Using milestone #{m[:title]}", :blue]
26
+ end
27
+ end
28
+
29
+ if options["issue_state"]
30
+ filters.merge!(state: options["issue_state"])
31
+ end
32
+
33
+ client.list_issues(@repo, filters).reject { |issue| issue.key?(:pull_request) }
34
+ end
35
+
36
+ private
37
+
38
+ def milestone(number)
39
+ client.list_milestones(@repo).find { |m| m[:title].include?(" #{number} ") }
40
+ end
41
+
42
+ def commit(tag_name)
43
+ tag = tag_name ? tags[clean_tag_name(tag_name)] : tags[tags.keys.sort.last]
44
+
45
+ puts Paint["Using tag version #{clean_tag_ref(tag[:ref])}", :blue]
46
+
47
+ client.commit(@repo, tag[:object][:sha])
48
+ end
49
+
50
+ def tags
51
+ @tags ||= Hash[
52
+ client.refs(@repo, :tag)
53
+ .map { |ref| [clean_tag_ref(ref[:ref]), ref] }
54
+ .reject { |ref| ref[0].nil? }
55
+ ]
56
+ end
57
+
58
+ def clean_tag_ref(ref)
59
+ tag = ref.match(/(\d+\.)?(\d+\.)?(\*|\d+)$/)
60
+ tag[0] if tag
61
+ end
62
+
63
+ def clean_tag_name(tag_name)
64
+ tag_name.gsub("v", "")
65
+ end
66
+
67
+ def client
68
+ @client ||= Octokit::Client.new(access_token: @github_token)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module GithubChangelogEntry
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_changelog_entry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre Chakroun
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: octokit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: paint
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - alexandre.chakroun@gmail.com
114
+ executables:
115
+ - gce
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - exe/gce
128
+ - github_changelog_entry.gemspec
129
+ - lib/github_changelog_entry.rb
130
+ - lib/github_changelog_entry/cli.rb
131
+ - lib/github_changelog_entry/generator.rb
132
+ - lib/github_changelog_entry/github.rb
133
+ - lib/github_changelog_entry/version.rb
134
+ homepage:
135
+ licenses: []
136
+ metadata:
137
+ allowed_push_host: https://rubygems.org
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.7.8
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Create a new changelog entry using github API
158
+ test_files: []