{"id":18728757,"url":"https://github.com/rubyonworld/git-diff-parser","last_synced_at":"2025-11-12T05:30:18.889Z","repository":{"id":174007916,"uuid":"542162200","full_name":"RubyOnWorld/git-diff-parser","owner":"RubyOnWorld","description":"Parse git diff into patches and lines.","archived":false,"fork":false,"pushed_at":"2022-09-28T00:58:02.000Z","size":82,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-28T14:26:19.085Z","etag":null,"topics":["diff","git","into","parse"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RubyOnWorld.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-27T15:38:22.000Z","updated_at":"2022-09-28T03:14:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"0fb927b2-b36a-4a75-a602-a08fb742c303","html_url":"https://github.com/RubyOnWorld/git-diff-parser","commit_stats":null,"previous_names":["rubyonworld/git-diff-parser"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fgit-diff-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fgit-diff-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fgit-diff-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fgit-diff-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RubyOnWorld","download_url":"https://codeload.github.com/RubyOnWorld/git-diff-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239599039,"owners_count":19665911,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diff","git","into","parse"],"created_at":"2024-11-07T14:24:16.041Z","updated_at":"2025-11-12T05:30:18.145Z","avatar_url":"https://github.com/RubyOnWorld.png","language":"Ruby","readme":"# GitDiffParser\n\n[![Gem version][gem-image]][gem-url] [![Travis-CI Status][travis-image]][travis-url] [![yard docs][docs-image]][docs-url]\n\n\u003e Parse `git diff` into patches and lines.\n\n\n## Examples\n\n### Parse entire `git diff`\n\n```ruby\ndiff = \u003c\u003c'EOL'\ndiff --git a/lib/saddler/reporter/github.rb b/lib/saddler/reporter/github.rb\nindex fc33cdd..0638356 100644\n--- a/lib/saddler/reporter/github.rb\n+++ b/lib/saddler/reporter/github.rb\n@@ -2,6 +2,7 @@\n require 'octokit'\n require 'git'\n require 'saddler/reporter/github/version'\n+require 'saddler/reporter/github/support'\n require 'saddler/reporter/github/helper'\n require 'saddler/reporter/github/client'\n require 'saddler/reporter/github/comment'\nEOL\n\npatches = GitDiffParser.parse(diff)\n#=\u003e [#\u003cGitDiffParser::Patch:0x007fb313189430\n# @body=\"@@ -2,6 +2,7 @@\\n require 'octokit'\\n require 'git'\\n require 'saddler/reporter/github/version'\\n+r (snip)\",\n# @file=\"lib/saddler/reporter/github.rb\"\u003e]\n\npatches[0].file\n#=\u003e \"lib/saddler/reporter/github.rb\"\n\npatches[0].changed_lines\n#=\u003e [#\u003cGitDiffParser::Line:0x007fb3130a53e8\n# @number=5,\n# @content=\"+require 'saddler/reporter/github/support'\\n\",\n# @patch_position=4\u003e]\n```\n\n\n### Parse single patch\n\n* patch section in `git diff`.\n* GitHub's [pull request file's patch](https://developer.github.com/v3/pulls/#list-pull-requests-files).\n* GitHub's [commit file's patch](https://developer.github.com/v3/repos/commits/#get-a-single-commit).\n\n\n```ruby\ndiff = \u003c\u003c-'EOS'\n@@ -2,6 +2,7 @@ module Saddler\n   module Reporter\n     module Github\n       class CommitComment\n+        include Support\n         include Helper\n\n         # https://developer.github.com/v3/repos/comments/#create-a-commit-comment\n@@ -11,7 +12,7 @@ def report(messages, options)\n           data = parse(messages)\n\n           # build comment\n-          body = build_body(data)\n+          body = concat_body(data)\n           return if body.empty?\n           comment = Comment.new(sha1, body, nil, nil)\n\n@@ -25,20 +26,6 @@ def report(messages, options)\n           # create commit_comment\n           client.create_commit_comment(comment)\n         end\n-\n-        def build_body(data)\n-          buffer = []\n-          files = data['checkstyle']['file'] ||= []\n-          files.each do |file|\n-            errors = file['error'] ||= []\n-            errors.each do |error|\n-              severity = error['@severity'] \u0026\u0026 error['@severity'].upcase\n-              message = error['@message']\n-              buffer \u003c\u003c [severity, message].compact.join(': ')\n-            end\n-          end\n-          buffer.join(\"\\n\")\n-        end\n       end\n     end\n   end\nEOS\n\npatch = GitDiffParser::Patch.new(diff)\n#=\u003e #\u003cGitDiffParser::Patch:0x007fb068ca7a18\n# @body=\"@@ -2,6 +2,7 @@ module Saddler (snip)\"\u003e\n\npatch.changed_lines\n#=\u003e [#\u003cGitDiffParser::Line:0x007fb068c17af8 @number=5,\n# @content=\"+        include Support\\n\", @patch_position=4\u003e,\n# \u003cGitDiffParser::Line:0x007fb068c17580 @number=15,\n# @content=\"+          body = concat_body(data)\\n\", @patch_position=13\u003e]\n```\n\n\n## API\n\nAnd more *[details][docs-url]*.\n\n\n## Changelog\n\n[changelog.md](./changelog.md).\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'git_diff_parser'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install git_diff_parser\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo 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).\n\n\n## Contributing\n\n1. Fork it ( https://github.com/packsaddle/ruby-git_diff_parser/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n\n## License\n\n### git_diff_parser\nCopyright (c) 2015 sanemat. [Licensed under the MIT license](./LICENSE)\n\n\n### original [thoughtbot/hound](https://github.com/thoughtbot/hound)\n\nCopyright (c) 2014 thoughtbot, inc. [Licensed under the MIT license](./thoughtbot-hound/LICENSE)\n\n* lib/git_diff_parser/line.rb \u003c- app/models/line.rb\n* lib/git_diff_parser/patch.rb \u003c- app/models/patch.rb\n* spec/git_diff_parser/patch_spec.rb \u003c- spec/models/patch_spec.rb\n\n\n[travis-url]: https://travis-ci.org/packsaddle/ruby-git_diff_parser\n[travis-image]: https://img.shields.io/travis/packsaddle/ruby-git_diff_parser/master.svg?style=flat-square\u0026label=build%20%28linux%29\n[gem-url]: https://rubygems.org/gems/git_diff_parser\n[gem-image]: http://img.shields.io/gem/v/git_diff_parser.svg?style=flat-square\n[docs-url]: http://www.rubydoc.info/gems/git_diff_parser\n[docs-image]: https://img.shields.io/badge/yard-docs-blue.svg?style=flat-square\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fgit-diff-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyonworld%2Fgit-diff-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fgit-diff-parser/lists"}