Skip to content
This repository was archived by the owner on Mar 3, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.rb]
indent_style = space
indent_size = 2
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: ruby
rvm:
- 2.2
script: rake test:one_by_one
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ghi

[![Build Status](https://travis-ci.org/shubhamshuklaer/ghi.svg?branch=travis-ci)](https://travis-ci.org/shubhamshuklaer/ghi)
Copy link
Collaborator Author

@shubhamshuklaer shubhamshuklaer May 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link needs to be changed after merge.


GitHub Issues on the command line. Use your `$EDITOR`, not your browser.

`ghi` was originally created by [Stephen Celis](https://github.com/stephencelis), and is now maintained by [Alex Chesters](https://github.com/alexchesters).
Expand Down Expand Up @@ -69,3 +71,47 @@ FAQs can be found in the [wiki](https://github.com/stephencelis/ghi/wiki/FAQ)
## Screenshot

![Example](images/example.png)

## Testing Guidlines

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Guidlines => Guidelines

* You are encouraged to add tests if you are adding new feature or solving some
problem which do not have a test.
* A test file should be named as `something_test.rb` and should be kept in the
`test` folder. A test class should be named `Test_something` and a test
function `test_something`. Helper functions must not start with `test`.
* Before running tests `GITHUB_USER` and `GITHUB_PASSWORD` environment
variables must be exported. It is best to use a fake account as a bug can mess
up your original account. You can either export these 2 environment variables
through `~/.bashrc`(As ghi only uses these while generating its token, so after

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing before (As

you generate the token for your original account(for regular use), fake account

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing before (for

details can be exported) or you can pass it on command line, eg. `rake
test:one_by_one GITHUB_USER='abc' GITHUB_PASSWORD='xyz'`.
* Run `rake test:one_by_one` to run all the tests
* Check [Single Test](https://github.com/grosser/single_test) for better
control over which test to run. Eg. `rake test:assign:un_assign` will run a
test function matching `/un_assign/` in file `assign_test.rb`. One more eg.
`rake test:edit test:assign` will run tests `edit_test.rb` and
`assign_test.rb`. Or you can also use `ruby -I"lib:test" test/file_name.rb -n
method_name`
* By default, the repo and token created while testing will be deleted. But if
you want to see the state of repo and tokens after the test has run, then add
`NO_DELETE_REPO=1` and `NO_DELETE_TOKEN=1` to the command. For eg. `rake
test:assign NO_DELETE_REPO=1 NO_DELETE_TOKEN=1`.
* If you don't wanna run the tests locally use travis-ci. See section below.

## Enable Travis CI in fork

* Open a Travis CI account and activate travis-ci for the fork
* Create a fake github account for testing. The username, password and token
will be available to the tests and if by mistake the test prints it, it will be
available in public log. So its best to create a fake account and use a

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo its => it's

password you are not using for anything else. Apart from security reasons,
bugs in tests or software can also mess up your original account, so to be
on safe side use a fake account.
* At Travis-CI, on the settings page for the fork, add environment variables
`GITHUB_USER` and `GITHUB_PASSWORD`. Ensure that the "Display value in build
log" is set to false. It is possible to add these in ".travis.yml", but don't
as all forks as well as original repo will be using different accounts(We cannot

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing before (We

provide the details of a common account for testing because of security reasons) for
testing, so it will cause problems during merge.
* Note that the build status badge in the README points to the travis-ci page
for this repo, not the fork.
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'single_test/tasks'

desc 'Build the standalone script'
task :build do
manifest = %w(
Expand Down
25 changes: 19 additions & 6 deletions ghi
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ module GHI
@token = GHI.config 'ghi.token'
end

def authorize! user = username, pass = password, local = true
def authorize! user = username, pass = password, local = true, just_print_token = false
return false unless user && pass
code ||= nil # 2fa
args = code ? [] : [54, "✔\r"]
Expand All @@ -1106,11 +1106,15 @@ module GHI
}
@token = res.body['token']

unless username
system "git config#{' --global' unless local} github.user #{user}"
end
if just_print_token
puts token
else
unless username
system "git config#{' --global' unless local} github.user #{user}"
end

store_token! user, token, local
store_token! user, token, local
end
rescue Client::Error => e
if e.response['X-GitHub-OTP'] =~ /required/
puts "Bad code." if code
Expand Down Expand Up @@ -1882,6 +1886,9 @@ EOF
opts.on '--local', 'set for local repo only' do
assigns[:local] = true
end
opts.on '--just_print_token', "Just print the token don't add it to ~/.gitconfig(Useful while testing)" do
assigns[:just_print_token] = true
end
opts.on '--auth [<username>]' do |username|
self.action = 'auth'
assigns[:username] = username || Authorization.username
Expand All @@ -1899,7 +1906,7 @@ EOF
if action == 'auth'
assigns[:password] = Authorization.password || get_password
Authorization.authorize!(
assigns[:username], assigns[:password], assigns[:local]
assigns[:username], assigns[:password], assigns[:local], assigns[:just_print_token]
)
end
end
Expand Down Expand Up @@ -1997,6 +2004,9 @@ EOF
case action
when 'edit'
begin
unless args.empty?
assigns[:title], assigns[:body] = args.join(' '), assigns[:title]
end
if editor || assigns.empty?
i = throb { api.get "/repos/#{repo}/issues/#{issue}" }.body
e = Editor.new "GHI_ISSUE_#{issue}.md"
Expand Down Expand Up @@ -2743,6 +2753,9 @@ EOF
if web
Web.new(repo).open 'issues/milestones/new'
else
unless args.empty?
assigns[:title], assigns[:description] = args.join(' '), assigns[:title]
end
if assigns[:title].nil?
e = Editor.new 'GHI_MILESTONE.md'
message = e.gets format_milestone_editor
Expand Down
2 changes: 2 additions & 0 deletions ghi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ EOF

s.add_development_dependency 'rake'
s.add_development_dependency 'ronn'
s.add_development_dependency 'typhoeus'
s.add_development_dependency 'single_test'
end
14 changes: 9 additions & 5 deletions lib/ghi/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def token
@token = GHI.config 'ghi.token'
end

def authorize! user = username, pass = password, local = true
def authorize! user = username, pass = password, local = true, just_print_token = false
return false unless user && pass
code ||= nil # 2fa
args = code ? [] : [54, "✔\r"]
Expand All @@ -36,11 +36,15 @@ def authorize! user = username, pass = password, local = true
}
@token = res.body['token']

unless username
system "git config#{' --global' unless local} github.user #{user}"
end
if just_print_token
puts token
else
unless username
system "git config#{' --global' unless local} github.user #{user}"
end

store_token! user, token, local
store_token! user, token, local
end
rescue Client::Error => e
if e.response['X-GitHub-OTP'] =~ /required/
puts "Bad code." if code
Expand Down
5 changes: 4 additions & 1 deletion lib/ghi/commands/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def options
opts.on '--local', 'set for local repo only' do
assigns[:local] = true
end
opts.on '--just_print_token', "Just print the token don't add it to ~/.gitconfig(Useful while testing)" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing before (Useful

assigns[:just_print_token] = true
end
opts.on '--auth [<username>]' do |username|
self.action = 'auth'
assigns[:username] = username || Authorization.username
Expand All @@ -27,7 +30,7 @@ def execute
if action == 'auth'
assigns[:password] = Authorization.password || get_password
Authorization.authorize!(
assigns[:username], assigns[:password], assigns[:local]
assigns[:username], assigns[:password], assigns[:local], assigns[:just_print_token]
)
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/ghi/commands/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def execute
case action
when 'edit'
begin
unless args.empty?
assigns[:title], assigns[:body] = args.join(' '), assigns[:title]
end
if editor || assigns.empty?
i = throb { api.get "/repos/#{repo}/issues/#{issue}" }.body
e = Editor.new "GHI_ISSUE_#{issue}.md"
Expand Down
3 changes: 3 additions & 0 deletions lib/ghi/commands/milestone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def execute
if web
Web.new(repo).open 'issues/milestones/new'
else
unless args.empty?
assigns[:title], assigns[:description] = args.join(' '), assigns[:title]
end
if assigns[:title].nil?
e = Editor.new 'GHI_MILESTONE.md'
message = e.gets format_milestone_editor
Expand Down
42 changes: 42 additions & 0 deletions test/assign_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "test/unit"
require "helper"
require "pp"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pp no longer used in this file.


class Test_assign < Test::Unit::TestCase
def setup
gen_token
@repo_name=create_repo
end

def un_assign issue_no=1
`#{ghi_exec} assign -d #{issue_no} -- #{@repo_name}`

response_issue = get_body("repos/#{@repo_name}/issues/#{issue_no}","Issue does not exist")

assert_equal(nil,response_issue["assignee"],"User not unassigned")
end

def test_un_assign
open_issue @repo_name

un_assign
end

def test_assign
open_issue @repo_name

un_assign

`#{ghi_exec} assign -u "#{ENV['GITHUB_USER']}" 1 -- #{@repo_name}`

response_issue=get_body("repos/#{@repo_name}/issues/1","Issue does not exist")

assert_not_equal(nil,response_issue["assignee"],"No user assigned")
assert_equal(ENV['GITHUB_USER'],response_issue["assignee"]["login"],"Not assigned to proper user")
end

def teardown
delete_repo(@repo_name)
delete_token
end
end
30 changes: 30 additions & 0 deletions test/close_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "test/unit"
require "helper"
require "pp"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pp no longer used in this file.


class Test_close < Test::Unit::TestCase
def setup
gen_token
@repo_name=create_repo
end

def test_close_issue
open_issue @repo_name
comment=get_comment

`#{ghi_exec} close -m "#{comment}" 1 -- #{@repo_name}`

response_issue=get_body("repos/#{@repo_name}/issues/1","Issue does not exist")

assert_equal("closed",response_issue["state"],"Issue not closed")

response_body=get_body("repos/#{@repo_name}/issues/1/comments","Issue does not exist")

assert_equal(comment,response_body[-1]["body"],"Close comment text not proper")
end

def teardown
delete_repo(@repo_name)
delete_token
end
end
45 changes: 45 additions & 0 deletions test/comment_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require "test/unit"
require "helper"
require "pp"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pp not used.


class Test_comment < Test::Unit::TestCase
def setup
gen_token
@repo_name=create_repo
end

def test_comment
open_issue @repo_name
create_comment @repo_name
end

def test_comment_amend
open_issue @repo_name
create_comment @repo_name

comment=get_comment 1

`#{ghi_exec} comment --amend "#{comment}" 1 -- #{@repo_name}`

response_body=get_body("repos/#{@repo_name}/issues/1/comments","Issue does not exist")

assert_equal(1,response_body.length,"Comment does not exist")
assert_equal(comment,response_body[-1]["body"],"Comment text not proper")
end

def test_comment_delete
open_issue @repo_name
create_comment @repo_name

`#{ghi_exec} comment -D 1 -- #{@repo_name}`

response_body=get_body("repos/#{@repo_name}/issues/1/comments","Issue does not exist")

assert_equal(0,response_body.length,"Comment not deleted")
end

def teardown
delete_repo(@repo_name)
delete_token
end
end
30 changes: 30 additions & 0 deletions test/delete_all_repos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "helper"
require "json"
require "pp"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pp not used.


# This is helpful if your account(fake) gets littered with repos.
# You need to run ruby -I. delete_all_repos.rb. If you are executing from a
# different directory then you need to change the parameter of -I
# appropriately.

puts "Warning this will delete ALL repositories from the account pointed by GITHUB_USER environment variable"
puts "The account name(login) is #{ENV["GITHUB_USER"]}"
puts "Do you want to continue [N/y]"
option = gets
if option.chop == "y"
puts "Deleting"
while true
response=request("users/#{ENV["GITHUB_USER"]}/repos",:get,{},true)
repos=JSON.load(response.body)
if repos.length == 0
puts "Exiting"
break
end
repos.each do |repo|
puts "Deleting #{repo["full_name"]}"
delete_repo(repo["full_name"])
end
end
else
puts 'Not deleting'
end
Loading