Merge branch 'master' into develop
This commit is contained in:
commit
fdd41a22f6
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -5,3 +5,5 @@ pkg/
|
||||||
coverage/
|
coverage/
|
||||||
.bundle
|
.bundle
|
||||||
spec/*.lock
|
spec/*.lock
|
||||||
|
doc
|
||||||
|
.yardoc
|
||||||
|
|
|
@ -77,6 +77,11 @@ Because software tools are for people. If you don’t care, why are you contribu
|
||||||
- `github_changelog_generator -u github_username -p github_project`
|
- `github_changelog_generator -u github_username -p github_project`
|
||||||
- `github_changelog_generator github_username/github_project`
|
- `github_changelog_generator github_username/github_project`
|
||||||
|
|
||||||
|
- If you are running it against a repository on a Github Enterprise install, you must specify *both* `--github-site` and `--github-api` command line options:
|
||||||
|
|
||||||
|
github_changelog_generator --github-site="https://github.yoursite.com" \
|
||||||
|
--github-api="https://github.yoursite.com/api/v3/"
|
||||||
|
|
||||||
This generates a changelog to the `CHANGELOG.md` file, with pretty markdown formatting.
|
This generates a changelog to the `CHANGELOG.md` file, with pretty markdown formatting.
|
||||||
|
|
||||||
### Params
|
### Params
|
||||||
|
@ -133,6 +138,8 @@ we've provided a `rake` task library for your changelog generation.
|
||||||
Just put something like this in your `Rakefile`:
|
Just put something like this in your `Rakefile`:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
require 'github_changelog_generator/task'
|
||||||
|
|
||||||
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
||||||
config.since_tag = '0.1.14'
|
config.since_tag = '0.1.14'
|
||||||
config.future_release = '0.2.0'
|
config.future_release = '0.2.0'
|
||||||
|
|
78
lib/github_changelog_generator/parser.rb
Normal file → Executable file
78
lib/github_changelog_generator/parser.rb
Normal file → Executable file
|
@ -23,7 +23,12 @@ module GitHubChangelogGenerator
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param [Hash] options to display
|
# If options set to verbose, print the parsed options.
|
||||||
|
#
|
||||||
|
# The GitHub `:token` key is censored in the output.
|
||||||
|
#
|
||||||
|
# @param options [Hash] The options to display
|
||||||
|
# @option options [Boolean] :verbose If false this method does nothing
|
||||||
def self.print_options(options)
|
def self.print_options(options)
|
||||||
if options[:verbose]
|
if options[:verbose]
|
||||||
Helper.log.info "Performing task with options:"
|
Helper.log.info "Performing task with options:"
|
||||||
|
@ -170,7 +175,7 @@ module GitHubChangelogGenerator
|
||||||
parser
|
parser
|
||||||
end
|
end
|
||||||
|
|
||||||
# just get default options
|
# @return [Hash] Default options
|
||||||
def self.default_options
|
def self.default_options
|
||||||
{
|
{
|
||||||
tag1: nil,
|
tag1: nil,
|
||||||
|
@ -202,13 +207,14 @@ module GitHubChangelogGenerator
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If `:user` or `:project` not set in options, try setting them
|
||||||
def self.user_and_project_from_git(options)
|
def self.user_and_project_from_git(options)
|
||||||
if options[:user].nil? || options[:project].nil?
|
if options[:user].nil? || options[:project].nil?
|
||||||
detect_user_and_project(options, ARGV[0], ARGV[1])
|
detect_user_and_project(options, ARGV[0], ARGV[1])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Detects user and project from git
|
# Sets `:user` and `:project` in `options` from CLI arguments or `git remote`
|
||||||
def self.detect_user_and_project(options, arg0 = nil, arg1 = nil)
|
def self.detect_user_and_project(options, arg0 = nil, arg1 = nil)
|
||||||
options[:user], options[:project] = user_project_from_option(arg0, arg1, options[:github_site])
|
options[:user], options[:project] = user_project_from_option(arg0, arg1, options[:github_site])
|
||||||
return if options[:user] && options[:project]
|
return if options[:user] && options[:project]
|
||||||
|
@ -222,16 +228,23 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Try to find user and project name from git remote output
|
# Returns GitHub username and project from CLI arguments
|
||||||
#
|
#
|
||||||
# @param [String] output of git remote command
|
# @param arg0 [String] This parameter takes two forms: Either a full
|
||||||
# @return [Array] user and project
|
# GitHub URL, or a 'username/projectname', or
|
||||||
|
# simply a GitHub username
|
||||||
|
# @param arg1 [String] If arg0 is given as a username,
|
||||||
|
# then arg1 can given as a projectname
|
||||||
|
# @param github_site [String] Domain name of GitHub site
|
||||||
|
#
|
||||||
|
# @return [Array, nil] user and project, or nil if unsuccessful
|
||||||
def self.user_project_from_option(arg0, arg1, github_site)
|
def self.user_project_from_option(arg0, arg1, github_site)
|
||||||
user = nil
|
user = nil
|
||||||
project = nil
|
project = nil
|
||||||
github_site ||= "github.com"
|
github_site ||= "github.com"
|
||||||
if arg0 && !arg1
|
if arg0 && !arg1
|
||||||
# this match should parse strings such "https://github.com/skywinder/Github-Changelog-Generator" or "skywinder/Github-Changelog-Generator" to user and name
|
# this match should parse strings such "https://github.com/skywinder/Github-Changelog-Generator" or
|
||||||
|
# "skywinder/Github-Changelog-Generator" to user and name
|
||||||
puts arg0
|
puts arg0
|
||||||
match = /(?:.+#{Regexp.escape(github_site)}\/)?(.+)\/(.+)/.match(arg0)
|
match = /(?:.+#{Regexp.escape(github_site)}\/)?(.+)\/(.+)/.match(arg0)
|
||||||
|
|
||||||
|
@ -251,35 +264,40 @@ module GitHubChangelogGenerator
|
||||||
[user, project]
|
[user, project]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Try to find user and project name from git remote output
|
# These patterns match these formats:
|
||||||
|
#
|
||||||
|
# ```
|
||||||
|
# origin git@github.com:skywinder/Github-Changelog-Generator.git (fetch)
|
||||||
|
# git@github.com:skywinder/Github-Changelog-Generator.git
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
# and
|
||||||
|
#
|
||||||
|
# ```
|
||||||
|
# origin https://github.com/skywinder/ChangelogMerger (fetch)
|
||||||
|
# https://github.com/skywinder/ChangelogMerger
|
||||||
|
# ```
|
||||||
|
GIT_REMOTE_PATTERNS = [
|
||||||
|
/.*(?:[:\/])(?<user>(?:-|\w|\.)*)\/(?<project>(?:-|\w|\.)*)(?:\.git).*/,
|
||||||
|
/.*\/(?<user>(?:-|\w|\.)*)\/(?<project>(?:-|\w|\.)*).*/
|
||||||
|
]
|
||||||
|
|
||||||
|
# Returns GitHub username and project from git remote output
|
||||||
|
#
|
||||||
|
# @param git_remote_output [String] Output of git remote command
|
||||||
#
|
#
|
||||||
# @param [String] output of git remote command
|
|
||||||
# @return [Array] user and project
|
# @return [Array] user and project
|
||||||
def self.user_project_from_remote(remote)
|
def self.user_project_from_remote(git_remote_output)
|
||||||
# try to find repo in format:
|
|
||||||
# origin git@github.com:skywinder/Github-Changelog-Generator.git (fetch)
|
|
||||||
# git@github.com:skywinder/Github-Changelog-Generator.git
|
|
||||||
regex1 = /.*(?:[:\/])((?:-|\w|\.)*)\/((?:-|\w|\.)*)(?:\.git).*/
|
|
||||||
|
|
||||||
# try to find repo in format:
|
|
||||||
# origin https://github.com/skywinder/ChangelogMerger (fetch)
|
|
||||||
# https://github.com/skywinder/ChangelogMerger
|
|
||||||
regex2 = /.*\/((?:-|\w|\.)*)\/((?:-|\w|\.)*).*/
|
|
||||||
|
|
||||||
remote_structures = [regex1, regex2]
|
|
||||||
|
|
||||||
user = nil
|
user = nil
|
||||||
project = nil
|
project = nil
|
||||||
remote_structures.each do |regex|
|
GIT_REMOTE_PATTERNS.each do |git_remote_pattern|
|
||||||
matches = Regexp.new(regex).match(remote)
|
git_remote_pattern =~ git_remote_output
|
||||||
|
|
||||||
if matches && matches[1] && matches[2]
|
if Regexp.last_match
|
||||||
puts "Detected user:#{matches[1]}, project:#{matches[2]}"
|
user = Regexp.last_match(:user)
|
||||||
user = matches[1]
|
project = Regexp.last_match(:project)
|
||||||
project = matches[2]
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
break unless matches.nil?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
[user, project]
|
[user, project]
|
||||||
|
|
|
@ -14,7 +14,7 @@ module GitHubChangelogGenerator
|
||||||
unreleased_only unreleased unreleased_label
|
unreleased_only unreleased unreleased_label
|
||||||
compare_link include_labels exclude_labels
|
compare_link include_labels exclude_labels
|
||||||
bug_labels enhancement_labels
|
bug_labels enhancement_labels
|
||||||
between_tags exclude_tags since_tag max_issues
|
between_tags exclude_tags exclude_tags_regex since_tag max_issues
|
||||||
github_site github_endpoint simple_list
|
github_site github_endpoint simple_list
|
||||||
future_release release_branch verbose release_url
|
future_release release_branch verbose release_url
|
||||||
base )
|
base )
|
||||||
|
|
Loading…
Reference in New Issue
Block a user