git-review 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/git-review.rb +38 -37
- metadata +4 -4
    
        data/lib/git-review.rb
    CHANGED
    
    | @@ -11,14 +11,14 @@ class GitReview | |
| 11 11 | 
             
              def help
         | 
| 12 12 | 
             
                puts 'Usage: git review <command>'
         | 
| 13 13 | 
             
                puts 'Manage review workflow for projects hosted on GitHub (using pull requests).'
         | 
| 14 | 
            -
                puts | 
| 14 | 
            +
                puts
         | 
| 15 15 | 
             
                puts 'Available commands:'
         | 
| 16 16 | 
             
                puts '   list [--reverse]          List all pending requests.'
         | 
| 17 17 | 
             
                puts '   show <number> [--full]    Show details of a single request.'
         | 
| 18 18 | 
             
                puts '   browse <number>           Open a browser window and review a specified request.'
         | 
| 19 19 | 
             
                puts '   checkout <number>         Checkout a specified request\'s changes to your local repository.'
         | 
| 20 | 
            -
                puts '    | 
| 21 | 
            -
                puts '    | 
| 20 | 
            +
                puts '   merge <number>            Accept a specified request by merging it into master.'
         | 
| 21 | 
            +
                puts '   close <number>            Close a specified request.'
         | 
| 22 22 | 
             
                puts '   create                    Create a new request.'
         | 
| 23 23 | 
             
              end
         | 
| 24 24 |  | 
| @@ -41,7 +41,7 @@ class GitReview | |
| 41 41 | 
             
                  return
         | 
| 42 42 | 
             
                end
         | 
| 43 43 | 
             
                puts "Pending requests for '#{source}'"
         | 
| 44 | 
            -
                puts 'ID       | 
| 44 | 
            +
                puts 'ID      Updated    Comments  Title'
         | 
| 45 45 | 
             
                puts output.compact
         | 
| 46 46 | 
             
              end
         | 
| 47 47 |  | 
| @@ -55,15 +55,14 @@ class GitReview | |
| 55 55 | 
             
                puts "Created  : #{@pending_request['created_at']}"
         | 
| 56 56 | 
             
                puts "Votes    : #{@pending_request['votes']}"
         | 
| 57 57 | 
             
                puts "Comments : #{@pending_request['comments']}"
         | 
| 58 | 
            -
                puts | 
| 58 | 
            +
                puts
         | 
| 59 59 | 
             
                puts "Title    : #{@pending_request['title']}"
         | 
| 60 | 
            -
                puts  | 
| 61 | 
            -
                puts | 
| 60 | 
            +
                puts 'Body     :'
         | 
| 61 | 
            +
                puts
         | 
| 62 62 | 
             
                puts @pending_request['body']
         | 
| 63 | 
            -
                puts | 
| 63 | 
            +
                puts
         | 
| 64 64 | 
             
                puts '------------'
         | 
| 65 | 
            -
                puts | 
| 66 | 
            -
                puts "cmd: git diff #{option}HEAD...#{sha}"
         | 
| 65 | 
            +
                puts
         | 
| 67 66 | 
             
                puts git("diff --color=always #{option}HEAD...#{sha}")
         | 
| 68 67 | 
             
              end
         | 
| 69 68 |  | 
| @@ -74,11 +73,17 @@ class GitReview | |
| 74 73 |  | 
| 75 74 | 
             
              # Checkout a specified request's changes to your local repository.
         | 
| 76 75 | 
             
              def checkout
         | 
| 77 | 
            -
                 | 
| 76 | 
            +
                return unless request_exists?
         | 
| 77 | 
            +
                puts 'Checking out changes to your local repository.'
         | 
| 78 | 
            +
                puts 'To get back to your original state, just run:'
         | 
| 79 | 
            +
                puts
         | 
| 80 | 
            +
                puts '  git checkout master'
         | 
| 81 | 
            +
                puts
         | 
| 82 | 
            +
                git "checkout origin/#{@pending_request['head']['ref']}"
         | 
| 78 83 | 
             
              end
         | 
| 79 84 |  | 
| 80 85 | 
             
              # Accept a specified request by merging it into master.
         | 
| 81 | 
            -
              def  | 
| 86 | 
            +
              def merge
         | 
| 82 87 | 
             
                return unless request_exists?
         | 
| 83 88 | 
             
                option = @args.shift
         | 
| 84 89 | 
             
                unless @pending_request['head']['repository']
         | 
| @@ -86,25 +91,28 @@ class GitReview | |
| 86 91 | 
             
                  user = @pending_request['head']['user']['login']
         | 
| 87 92 | 
             
                  url = @pending_request['patch_url']
         | 
| 88 93 | 
             
                  puts "Sorry, #{user} deleted the source repository, git-review doesn't support this."
         | 
| 89 | 
            -
                  puts  | 
| 94 | 
            +
                  puts 'You can manually patch your repo by running:'
         | 
| 90 95 | 
             
                  puts
         | 
| 91 96 | 
             
                  puts "  curl #{url} | git am"
         | 
| 92 97 | 
             
                  puts
         | 
| 93 | 
            -
                  puts  | 
| 98 | 
            +
                  puts 'Tell the contributor not to do this.'
         | 
| 94 99 | 
             
                  return false
         | 
| 95 100 | 
             
                end
         | 
| 96 101 | 
             
                message = "Accepting request and merging into '#{target}':\n\n"
         | 
| 97 102 | 
             
                message += "#{@pending_request['title']}\n\n"
         | 
| 98 103 | 
             
                message += "#{@pending_request['body']}\n\n"
         | 
| 99 | 
            -
                 | 
| 100 | 
            -
                 | 
| 104 | 
            +
                exec_cmd = "merge --no-ff #{option} -m '#{message}' #{@pending_request['head']['sha']}"
         | 
| 105 | 
            +
                puts
         | 
| 106 | 
            +
                puts "  git #{exec_cmd}"
         | 
| 107 | 
            +
                puts
         | 
| 108 | 
            +
                git(exec_cmd)
         | 
| 101 109 | 
             
              end
         | 
| 102 110 |  | 
| 103 | 
            -
              #  | 
| 104 | 
            -
              def  | 
| 111 | 
            +
              # Close a specified request.
         | 
| 112 | 
            +
              def close
         | 
| 105 113 | 
             
                return unless request_exists?
         | 
| 106 114 | 
             
                Octokit.post("issues/close/#{source_repo}/#{@pending_request['number']}")
         | 
| 107 | 
            -
                puts  | 
| 115 | 
            +
                puts 'Successfully closed request.' unless request_exists?(@pending_request['number'])
         | 
| 108 116 | 
             
              end
         | 
| 109 117 |  | 
| 110 118 | 
             
              # Create a new request.
         | 
| @@ -115,11 +123,11 @@ class GitReview | |
| 115 123 | 
             
                last_request_id = @pending_requests.collect{|req| req['number'] }.sort.last.to_i
         | 
| 116 124 | 
             
                title = "[Review] Request from '#{github_login}' @ '#{source}'"
         | 
| 117 125 | 
             
                # TODO: Insert commit messages (that are not yet in master) into body (since this will be displayed inside the mail that is sent out).
         | 
| 118 | 
            -
                body =  | 
| 126 | 
            +
                body = 'Please review the following changes:'
         | 
| 119 127 | 
             
                # Create the actual pull request.
         | 
| 120 128 | 
             
                Octokit.create_pull_request(target_repo, target_branch, source_branch, title, body)
         | 
| 121 129 | 
             
                # Switch back to target_branch and check for success.
         | 
| 122 | 
            -
                git " | 
| 130 | 
            +
                git "commit #{target_branch}"
         | 
| 123 131 | 
             
                update
         | 
| 124 132 | 
             
                potential_new_request = @pending_requests.find{ |req| req['title'] == title }
         | 
| 125 133 | 
             
                puts 'Successfully created new request.' if potential_new_request['number'] > last_request_id
         | 
| @@ -161,7 +169,7 @@ class GitReview | |
| 161 169 | 
             
                update unless request_id.nil?
         | 
| 162 170 | 
             
                request_id ||= @args.shift.to_i
         | 
| 163 171 | 
             
                if request_id == 0
         | 
| 164 | 
            -
                  puts  | 
| 172 | 
            +
                  puts 'Please specify a valid ID.'
         | 
| 165 173 | 
             
                  return false
         | 
| 166 174 | 
             
                end
         | 
| 167 175 | 
             
                @pending_request = @pending_requests.find{ |req| req['number'] == request_id }
         | 
| @@ -174,9 +182,7 @@ class GitReview | |
| 174 182 | 
             
                @pending_requests = Octokit.pull_requests(source_repo)
         | 
| 175 183 | 
             
                repos = @pending_requests.collect do |req|
         | 
| 176 184 | 
             
                  repo = req['head']['repository']
         | 
| 177 | 
            -
                  #  | 
| 178 | 
            -
                  next if repo.nil? or not has_sha?(req['head']['sha'])
         | 
| 179 | 
            -
                  "#{repo['owner']}/#{repo['name']}"
         | 
| 185 | 
            +
                  "#{repo['owner']}/#{repo['name']}" unless repo.nil?
         | 
| 180 186 | 
             
                end
         | 
| 181 187 | 
             
                host = URI.parse(github_endpoint).host
         | 
| 182 188 | 
             
                repos.uniq.compact.each do |repo|
         | 
| @@ -185,7 +191,7 @@ class GitReview | |
| 185 191 | 
             
              end
         | 
| 186 192 |  | 
| 187 193 | 
             
              # System call to 'git'.
         | 
| 188 | 
            -
              def git(command, chomp=true)
         | 
| 194 | 
            +
              def git(command, chomp = true)
         | 
| 189 195 | 
             
                s = `git #{command}`
         | 
| 190 196 | 
             
                s.chomp! if chomp
         | 
| 191 197 | 
             
                s
         | 
| @@ -228,13 +234,6 @@ class GitReview | |
| 228 234 | 
             
                "#{target_repo}/#{target_branch}"
         | 
| 229 235 | 
             
              end
         | 
| 230 236 |  | 
| 231 | 
            -
              # Returns a boolean stating whether a specified commit exists.
         | 
| 232 | 
            -
              # TODO: Check if this is still necessary, since we don't cache anymore.
         | 
| 233 | 
            -
              def has_sha?(sha)
         | 
| 234 | 
            -
                git("show #{sha} 2>&1")
         | 
| 235 | 
            -
                $?.exitstatus == 0
         | 
| 236 | 
            -
              end
         | 
| 237 | 
            -
             | 
| 238 237 | 
             
              # Returns a boolean stating whether a specified commit has already been merged.
         | 
| 239 238 | 
             
              def merged?(sha)
         | 
| 240 239 | 
             
                not git("rev-list #{sha} ^HEAD 2>&1").split("\n").size > 0
         | 
| @@ -256,20 +255,21 @@ class GitReview | |
| 256 255 |  | 
| 257 256 | 
             
              # Get GitHub user name.
         | 
| 258 257 | 
             
              def github_login
         | 
| 259 | 
            -
                git( | 
| 258 | 
            +
                git('config --get-all github.user')
         | 
| 260 259 | 
             
              end
         | 
| 261 260 |  | 
| 262 261 | 
             
              # Get GitHub token.
         | 
| 263 262 | 
             
              def github_token
         | 
| 264 | 
            -
                git( | 
| 263 | 
            +
                git('config --get-all github.token')
         | 
| 265 264 | 
             
              end
         | 
| 266 265 |  | 
| 267 266 | 
             
              # Determine GitHub endpoint (defaults to 'https://github.com/').
         | 
| 268 267 | 
             
              def github_endpoint
         | 
| 269 | 
            -
                host = git( | 
| 268 | 
            +
                host = git('config --get-all github.host')
         | 
| 270 269 | 
             
                host.empty? ? 'https://github.com/' : host
         | 
| 271 270 | 
             
              end
         | 
| 272 271 |  | 
| 272 | 
            +
              # Returns an array consisting of information on the user and the project.
         | 
| 273 273 | 
             
              def repo_info
         | 
| 274 274 | 
             
                # Read config_hash from local git config.
         | 
| 275 275 | 
             
                config_hash = {}
         | 
| @@ -281,7 +281,7 @@ class GitReview | |
| 281 281 | 
             
                # Extract user and project name from GitHub URL.
         | 
| 282 282 | 
             
                url = config_hash['remote.origin.url']
         | 
| 283 283 | 
             
                user, project = github_user_and_project(url)
         | 
| 284 | 
            -
             | 
| 284 | 
            +
                # If there are no results yet, look for 'insteadof' substitutions in URL and try again.
         | 
| 285 285 | 
             
                unless (user and project)
         | 
| 286 286 | 
             
                  short, base = github_insteadof_matching(config_hash, url)
         | 
| 287 287 | 
             
                  if short and base
         | 
| @@ -292,6 +292,7 @@ class GitReview | |
| 292 292 | 
             
                [user, project]
         | 
| 293 293 | 
             
              end
         | 
| 294 294 |  | 
| 295 | 
            +
              # Looks for 'insteadof' substitutions in URL.
         | 
| 295 296 | 
             
              def github_insteadof_matching(config_hash, url)
         | 
| 296 297 | 
             
                first = config_hash.collect { |key,value|
         | 
| 297 298 | 
             
                  [value, /url\.(.*github\.com.*)\.insteadof/.match(key)]
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: git-review
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 1
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 6
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.6. | 
| 9 | 
            +
              - 3
         | 
| 10 | 
            +
              version: 0.6.3
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Dominik Bamberger, Cristian Messel
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2011- | 
| 18 | 
            +
            date: 2011-11-09 00:00:00 +01:00
         | 
| 19 19 | 
             
            default_executable: 
         | 
| 20 20 | 
             
            dependencies: 
         | 
| 21 21 | 
             
            - !ruby/object:Gem::Dependency 
         |