https://github.com/rubyonworld/git-diff-parser
Parse git diff into patches and lines.
https://github.com/rubyonworld/git-diff-parser
diff git into parse
Last synced: 5 months ago
JSON representation
Parse git diff into patches and lines.
- Host: GitHub
- URL: https://github.com/rubyonworld/git-diff-parser
- Owner: RubyOnWorld
- License: mit
- Created: 2022-09-27T15:38:22.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-09-28T00:58:02.000Z (over 3 years ago)
- Last Synced: 2024-12-28T14:26:19.085Z (over 1 year ago)
- Topics: diff, git, into, parse
- Language: Ruby
- Homepage:
- Size: 80.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# GitDiffParser
[![Gem version][gem-image]][gem-url] [![Travis-CI Status][travis-image]][travis-url] [![yard docs][docs-image]][docs-url]
> Parse `git diff` into patches and lines.
## Examples
### Parse entire `git diff`
```ruby
diff = <<'EOL'
diff --git a/lib/saddler/reporter/github.rb b/lib/saddler/reporter/github.rb
index fc33cdd..0638356 100644
--- a/lib/saddler/reporter/github.rb
+++ b/lib/saddler/reporter/github.rb
@@ -2,6 +2,7 @@
require 'octokit'
require 'git'
require 'saddler/reporter/github/version'
+require 'saddler/reporter/github/support'
require 'saddler/reporter/github/helper'
require 'saddler/reporter/github/client'
require 'saddler/reporter/github/comment'
EOL
patches = GitDiffParser.parse(diff)
#=> [#]
patches[0].file
#=> "lib/saddler/reporter/github.rb"
patches[0].changed_lines
#=> [#]
```
### Parse single patch
* patch section in `git diff`.
* GitHub's [pull request file's patch](https://developer.github.com/v3/pulls/#list-pull-requests-files).
* GitHub's [commit file's patch](https://developer.github.com/v3/repos/commits/#get-a-single-commit).
```ruby
diff = <<-'EOS'
@@ -2,6 +2,7 @@ module Saddler
module Reporter
module Github
class CommitComment
+ include Support
include Helper
# https://developer.github.com/v3/repos/comments/#create-a-commit-comment
@@ -11,7 +12,7 @@ def report(messages, options)
data = parse(messages)
# build comment
- body = build_body(data)
+ body = concat_body(data)
return if body.empty?
comment = Comment.new(sha1, body, nil, nil)
@@ -25,20 +26,6 @@ def report(messages, options)
# create commit_comment
client.create_commit_comment(comment)
end
-
- def build_body(data)
- buffer = []
- files = data['checkstyle']['file'] ||= []
- files.each do |file|
- errors = file['error'] ||= []
- errors.each do |error|
- severity = error['@severity'] && error['@severity'].upcase
- message = error['@message']
- buffer << [severity, message].compact.join(': ')
- end
- end
- buffer.join("\n")
- end
end
end
end
EOS
patch = GitDiffParser::Patch.new(diff)
#=> #
patch.changed_lines
#=> [#,
# ]
```
## API
And more *[details][docs-url]*.
## Changelog
[changelog.md](./changelog.md).
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'git_diff_parser'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install git_diff_parser
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
1. Fork it ( https://github.com/packsaddle/ruby-git_diff_parser/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## License
### git_diff_parser
Copyright (c) 2015 sanemat. [Licensed under the MIT license](./LICENSE)
### original [thoughtbot/hound](https://github.com/thoughtbot/hound)
Copyright (c) 2014 thoughtbot, inc. [Licensed under the MIT license](./thoughtbot-hound/LICENSE)
* lib/git_diff_parser/line.rb <- app/models/line.rb
* lib/git_diff_parser/patch.rb <- app/models/patch.rb
* spec/git_diff_parser/patch_spec.rb <- spec/models/patch_spec.rb
[travis-url]: https://travis-ci.org/packsaddle/ruby-git_diff_parser
[travis-image]: https://img.shields.io/travis/packsaddle/ruby-git_diff_parser/master.svg?style=flat-square&label=build%20%28linux%29
[gem-url]: https://rubygems.org/gems/git_diff_parser
[gem-image]: http://img.shields.io/gem/v/git_diff_parser.svg?style=flat-square
[docs-url]: http://www.rubydoc.info/gems/git_diff_parser
[docs-image]: https://img.shields.io/badge/yard-docs-blue.svg?style=flat-square