Skip to content

Drop Project-and-Username-finding code #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ GitHub Changelog Generator ![GitHub Logo](../master/images/logo.jpg)
Since you don't have to fill your `CHANGELOG.md` manually now: just run the script, relax and take a cup of :coffee: before your next release! :tada:

### *What’s the point of a change log?*

To make it easier for users and contributors to see precisely what notable changes have been made between each release (or version) of the project.

### *Why should I care?*
Because software tools are for people. If you don’t care, why are you contributing to open source? Surely, there must be a kernel (ha!) of care somewhere in that lovely little brain of yours.

Because software tools are for _people_. "Changelogs make it easier for users and
contributors to see precisely what notable changes have been made between each
release (or version) of the project."

:arrow_right: *[http://keepachangelog.com](http://keepachangelog.com)*

Expand Down Expand Up @@ -71,32 +76,31 @@ See also Troubleshooting.


## Usage
**It's really simple!**

- If your **`git remote`** `origin` refers to your GitHub repo, just go to your project folder and run:
- Run this:

github_changelog_generator

- Or, run this from anywhere:
`github_changelog_generator -u github_username -p 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:
- For Github Enterprise repos, specify *both* `--github-site` and `--github-api` 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.md`, with pretty Markdown formatting.

### Params

Type `github_changelog_generator --help` for details.

For more details about params, read the Wiki page: [**Advanced change log generation examples**](https://github.com/skywinder/github-changelog-generator/wiki/Advanced-change-log-generation-examples)

### Params File

In your project root, you can put a params file named `.github_changelog_generator` to override default params:

Example:

```
unreleased=false
future-release=5.0.0
Expand All @@ -106,6 +110,7 @@ since-tag=1.0.0
### GitHub token

GitHub only allows 50 unauthenticated requests per hour.

Therefore, it's recommended to run this script with authentication by using a **token**.

Here's how:
Expand Down Expand Up @@ -143,7 +148,7 @@ If you have a `HISTORY.md` file in your project, it will automatically be picked
You love `rake`? We do, too! So, we've made it even easier for you:
we've provided a `rake` task library for your changelog generation.

Just put something like this in your `Rakefile`:
Configure the task in your `Rakefile`:

```ruby
require 'github_changelog_generator/task'
Expand All @@ -154,11 +159,14 @@ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
end
```

All command line options can be passed to the `rake` task as `config` parameters. And since you're naming the `rake` task yourself, you can create as many as you want.
All command-line options can be passed to the `rake` task as `config`
parameters. And since you're naming the `rake` task yourself, you can create
as many as you want.

You can look for params names from the [parser source code (#setup_parser)](https://github.com/skywinder/github-changelog-generator/blob/master/lib/github_changelog_generator/parser.rb). For example, to translate the bugs label to Portuguese, instead of setting `config.bugs_label`, you have to set `config.bug_prefix`, and so on.

## Features and advantages of this project

- Generate canonical, neat change log file, followed by [basic change log guidelines](http://keepachangelog.com) :gem:
- Optionally generate **Unreleased** changes (closed issues that have not released yet) :dizzy:
- **GitHub Enterprise support** via command line options! :factory:
Expand All @@ -179,12 +187,14 @@ You can look for params names from the [parser source code (#setup_parser)](http


### Alternatives

Here is a [wikipage list of alternatives](https://github.com/skywinder/Github-Changelog-Generator/wiki/Alternatives) that I found. But none satisfied my requirements.

*If you know other projects, feel free to edit this Wiki page!*


### Projects using this library

Here's a [wikipage list of projects](https://github.com/skywinder/Github-Changelog-Generator/wiki/Projects-using-Github-Changelog-Generator).

If you've used this project in a live app, please let me know! Nothing makes me happier than seeing someone else take my work and go wild with it.
Expand Down
1 change: 0 additions & 1 deletion lib/github_changelog_generator/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Options < SimpleDelegator
filter_issues_by_milestone
frontmatter
future_release
git_remote
github_endpoint
github_site
header
Expand Down
108 changes: 0 additions & 108 deletions lib/github_changelog_generator/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def self.parse_options
abort [e, parser].join("\n")
end

fetch_user_and_project(options)

abort(parser.banner) unless options[:user] && options[:project]

print_options(options)
Expand Down Expand Up @@ -220,114 +218,8 @@ def self.default_options
issue_prefix: "**Closed issues:**",
bug_prefix: "**Fixed bugs:**",
enhancement_prefix: "**Implemented enhancements:**",
git_remote: "origin",
http_cache: true
)
end

# If `:user` or `:project` not set in options, try setting them
# Valid unnamed parameters:
# 1) in 1 param: repo_name/project
# 2) in 2 params: repo name project
def self.fetch_user_and_project(options)
if options[:user].nil? || options[:project].nil?
user, project = user_and_project_from_git(options, ARGV[0], ARGV[1])
options[:user] ||= user
options[:project] ||= project
end
end

# Sets `:user` and `:project` in `options` from CLI arguments or `git remote`
# @param [String] arg0 first argument in cli
# @param [String] arg1 second argument in cli
# @return [Array<String>] user and project, or nil if unsuccessful
def self.user_and_project_from_git(options, arg0 = nil, arg1 = nil)
user, project = user_project_from_option(arg0, arg1, options[:github_site])
unless user && project
if ENV["RUBYLIB"] =~ /ruby-debug-ide/
user = "skywinder"
project = "changelog_test"
else
remote = `git config --get remote.#{options[:git_remote]}.url`
user, project = user_project_from_remote(remote)
end
end

[user, project]
end

# Returns GitHub username and project from CLI arguments
#
# @param arg0 [String] This parameter takes two forms: Either a full
# 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)
user = nil
project = nil
github_site ||= "github.com"
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
match = /(?:.+#{Regexp.escape(github_site)}\/)?(.+)\/(.+)/.match(arg0)

begin
param = match[2].nil?
rescue StandardError
puts "Can't detect user and name from first parameter: '#{arg0}' -> exit'"
return
end
if param
return
else
user = match[1]
project = match[2]
end
end
[user, project]
end

# 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
#
# @return [Array] user and project
def self.user_project_from_remote(git_remote_output)
user = nil
project = nil
GIT_REMOTE_PATTERNS.each do |git_remote_pattern|
git_remote_pattern =~ git_remote_output

if Regexp.last_match
user = Regexp.last_match(:user)
project = Regexp.last_match(:project)
break
end
end

[user, project]
end
end
end
4 changes: 1 addition & 3 deletions lib/github_changelog_generator/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ def define(args, &task_block)
# mimick parse_options
options = Parser.default_options

Parser.fetch_user_and_project(options)

OPTIONS.each do |o|
v = instance_variable_get("@#{o}")
options[o.to_sym] = v unless v.nil?
end

abort "user and project are required." unless options[:user] && options[:project]
generator = Generator.new options

log = generator.compound_changelog
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it "raises an error" do
expect do
described_class.new(
git_remote: "origin",
project: "rails",
strength: "super-strength",
wisdom: "deep"
)
Expand All @@ -22,13 +22,13 @@
end

describe "#[]=(key, value)" do
let(:options) { described_class.new(git_remote: "origin") }
let(:options) { described_class.new(project: "rails") }

context "with known options" do
it "sets the option value" do
expect do
options[:git_remote] = "in the cloud"
end.to change { options[:git_remote] }.to "in the cloud"
options[:project] = "trails"
end.to change { options[:project] }.to "trails"
end
end

Expand Down
79 changes: 0 additions & 79 deletions spec/unit/parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,83 +1,4 @@
# frozen_string_literal: true

describe GitHubChangelogGenerator::Parser do
describe ".user_project_from_remote" do
context "when remote is type 1" do
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("origin https://github.com/skywinder/ActionSheetPicker-3.0 (fetch)") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when remote is type 2" do
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("https://github.com/skywinder/ActionSheetPicker-3.0") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when remote is type 3" do
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("https://github.com/skywinder/ActionSheetPicker-3.0") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when remote is type 4" do
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("origin git@github.com:skywinder/ActionSheetPicker-3.0.git (fetch)") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when remote is invalid" do
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("some invalid text") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array([nil, nil]) }
end
end
describe ".user_project_from_option" do
context "when option is invalid" do
it("should return nil") { expect(GitHubChangelogGenerator::Parser.user_project_from_option("blah", nil, nil)).to be_nil }
end

context "when option is valid" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", nil, nil) }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when option nil" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option(nil, nil, nil) }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array([nil, nil]) }
end
context "when site is nil" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", nil, nil) }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when site is valid" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", nil, "https://codeclimate.com") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when second arg is not nil" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", "blah", nil) }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array([nil, nil]) }
end
context "when all args is not nil" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", "blah", "https://codeclimate.com") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array([nil, nil]) }
end
end
describe ".fetch_user_and_project" do
before do
stub_const("ARGV", ["https://github.com/skywinder/github-changelog-generator"])
end

context do
let(:valid_user) { "initialized_user" }
let(:options) { { user: valid_user } }
let(:options_before_change) { options.dup }
it "should leave user unchanged" do
expect { GitHubChangelogGenerator::Parser.fetch_user_and_project(options) }.to change { options }
.from(options_before_change)
.to(options_before_change.merge(project: "github-changelog-generator"))
end
end
end
end
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy