saddler-reporter-github 0.1.5 → 0.1.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1dc735b2cef637c5d5a467a40b8bf593451220f9
4
- data.tar.gz: ef5f818d8cce267bfd9daad9835774c4301324b0
3
+ metadata.gz: 879b2b1b02b0f258dc52c8d8707b0ea05f12f69e
4
+ data.tar.gz: 4061ab75257db71d06d0d6ca4b866d7bb04a03cc
5
5
  SHA512:
6
- metadata.gz: 0fae38fc76fb4b589153a7cc78852b2a145f559adbf6aaf5103362ec48f137a505eff4b0362d167cff55694265a92d26ff5ed3a8ef2a234e280c9c7e23d02082
7
- data.tar.gz: 13c3bdb196b3aa9d8c2afc3230478ed027fa56aac1f3276c455bea638602390db19d240c45d7a1630f6a50bdd438461bc371eddfeb31b4848c282037bdabb0bc
6
+ metadata.gz: e63cd96035d3cb1796e15a1afb769bc870c3762a74dcc8377b5ac1d41cda24465912835b46b074083e5d881aa7d212cc4aae343f2b7db52e51b17ff04e641a68
7
+ data.tar.gz: 014f24df85b94364edf83afdc9b8c45ffc90306496f950cb76cfec5194b3b7c6a26f765aa8cb27a0855ae87e86ca5f6fea8dff91b7f3f49f5ddf7afc354e5dec
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+ var execSync = require('child_process').execSync;
3
+ var URI = require('urijs');
4
+
5
+ var gemspec = JSON.parse(execSync('bundle exec parse-gemspec-cli saddler-reporter-github.gemspec'));
6
+ var homepageUrl = gemspec.homepage;
7
+ var url = new URI(homepageUrl);
8
+ var host = url.protocol() + '://' + url.authority();
9
+ var owner = url.pathname().split('/')[1];
10
+ var repository = url.pathname().split('/')[2];
11
+
12
+ module.exports = {
13
+ version: gemspec.version,
14
+ host: host,
15
+ owner: owner,
16
+ repository: repository
17
+ };
data/.rubocop.yml CHANGED
@@ -12,6 +12,3 @@ Metrics/LineLength:
12
12
  Style/FileName:
13
13
  Exclude:
14
14
  - exe/*
15
-
16
- Style/RegexpLiteral:
17
- MaxSlashes: 0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ <a name="0.1.6"></a>
2
+ ## [0.1.6](https://github.com/packsaddle/ruby-saddler-reporter-github/compare/v0.1.5...v0.1.6) (2015-10-02)
3
+
4
+ * Improve document.
5
+
6
+
1
7
  <a name="0.1.5"></a>
2
8
  ## [0.1.5](https://github.com/packsaddle/ruby-saddler-reporter-github/compare/v0.1.4...v0.1.5) (2015-09-21)
3
9
 
data/Gemfile CHANGED
@@ -2,5 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in saddler-reporter-github.gemspec
4
4
  gemspec
5
+
5
6
  gem 'byebug' if RUBY_VERSION >= '2.0.0'
7
+ gem 'parse_gemspec-cli'
6
8
  gem 'pry'
9
+ gem 'rubocop'
10
+ gem 'yard'
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Saddler::Reporter::Github
2
2
 
3
- [![Gem Version](http://img.shields.io/gem/v/saddler-reporter-github.svg?style=flat)](http://badge.fury.io/rb/saddler-reporter-github)
4
- [![Build Status](http://img.shields.io/travis/packsaddle/ruby-saddler-reporter-github/master.svg?style=flat)](https://travis-ci.org/packsaddle/ruby-saddler-reporter-github)
3
+ [![Gem version][gem-image]][gem-url] [![Travis-CI Status][travis-image]][travis-url] [![yard docs][docs-image]][docs-url]
4
+
5
+ > [Saddler](https://github.com/packsaddle/ruby-saddler) reporter for GitHub.
5
6
 
6
7
 
7
8
  ## Reporters
@@ -9,9 +10,17 @@
9
10
  This provides saddler reporters for GitHub.
10
11
 
11
12
  * PullRequestComment
13
+ * `--require saddler/reporter/github`
14
+ * `--reporter Saddler::Reporter::Github::PullRequestComment`
12
15
  * PullRequestReviewComment
13
- * CommitComment(under construction)
14
- * CommitReviewComment(under construction)
16
+ * `--require saddler/reporter/github`
17
+ * `--reporter Saddler::Reporter::Github::PullRequestReviewComment`
18
+ * CommitComment (_under construction_)
19
+ * `--require saddler/reporter/github`
20
+ * `--reporter Saddler::Reporter::Github::CommitComment`
21
+ * CommitReviewComment (_under construction_)
22
+ * `--require saddler/reporter/github`
23
+ * `--reporter Saddler::Reporter::Github::CommitReviewComment`
15
24
 
16
25
 
17
26
  ## Usage
@@ -22,7 +31,7 @@ $ saddler report \
22
31
  --reporter Saddler::Reporter::Github::PullRequestReviewComment
23
32
  ```
24
33
 
25
- like this.
34
+ like this. See [Saddler](https://github.com/packsaddle/ruby-saddler).
26
35
 
27
36
 
28
37
  ## Requirement
@@ -45,6 +54,16 @@ $ travis encrypt -r <owner_name>/<repos_name> "GITHUB_ACCESS_TOKEN=<github_token
45
54
  [Environment variables - CircleCI](https://circleci.com/docs/environment-variables)
46
55
 
47
56
 
57
+ ## API
58
+
59
+ *[details][docs-url]*.
60
+
61
+
62
+ ## Changelog
63
+
64
+ [CHANGELOG.md](./CHANGELOG.md).
65
+
66
+
48
67
  ## Installation
49
68
 
50
69
  Add this line to your application's Gemfile:
@@ -76,3 +95,17 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
76
95
  3. Commit your changes (`git commit -am 'Add some feature'`)
77
96
  4. Push to the branch (`git push origin my-new-feature`)
78
97
  5. Create a new Pull Request
98
+
99
+
100
+ ## License
101
+
102
+ © [sanemat](http://sane.jp)
103
+
104
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
105
+
106
+ [travis-url]: https://travis-ci.org/packsaddle/ruby-saddler-reporter-github
107
+ [travis-image]: https://img.shields.io/travis/packsaddle/ruby-saddler-reporter-github/master.svg?style=flat-square&label=build%20%28linux%29
108
+ [gem-url]: https://rubygems.org/gems/saddler-reporter-github
109
+ [gem-image]: http://img.shields.io/gem/v/saddler-reporter-github.svg?style=flat-square
110
+ [docs-url]: http://www.rubydoc.info/gems/saddler-reporter-github
111
+ [docs-image]: https://img.shields.io/badge/yard-docs-blue.svg?style=flat-square
data/Rakefile CHANGED
@@ -7,3 +7,12 @@ Rake::TestTask.new(:test) do |t|
7
7
  end
8
8
 
9
9
  task default: :test
10
+
11
+ require 'yard'
12
+ require 'yard/rake/yardoc_task'
13
+ DOC_FILES = ['lib/**/*.rb']
14
+ DOC_OPTIONS = ['--debug', '--verbose']
15
+ YARD::Rake::YardocTask.new(:doc) do |t|
16
+ t.files = DOC_FILES
17
+ t.options = DOC_OPTIONS if Rake.application.options.trace
18
+ end
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
@@ -1,7 +1,15 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
1
+ #!/usr/bin/env ruby
4
2
 
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
3
+ require 'open3'
4
+ unless ENV['CI']
5
+ out, err, status = Open3.capture3(*%w(bundle install))
6
+ $stdout.puts out
7
+ $stderr.puts err
8
+ exit status.exitstatus if !status.exitstatus.nil? && status.exitstatus != 0
9
+ end
10
+ unless ENV['CI']
11
+ out, err, status = Open3.capture3(*%w(npm install))
12
+ $stdout.puts out
13
+ $stderr.puts err
14
+ exit status.exitstatus if !status.exitstatus.nil? && status.exitstatus != 0
15
+ end
@@ -14,6 +14,7 @@ require 'saddler/reporter/github/pull_request_review_comment'
14
14
  module Saddler
15
15
  module Reporter
16
16
  class ArgumentError < StandardError; end
17
+ # Saddler reporter for GitHub.
17
18
  module Github
18
19
  class InvalidParameterError < ::Saddler::Reporter::ArgumentError; end
19
20
  end
@@ -1,22 +1,35 @@
1
1
  module Saddler
2
2
  module Reporter
3
3
  module Github
4
+ # GitHub client wrapper
4
5
  class Client
6
+ # @param repo [::Saddler::Reporter::Support::Git::Repository] git repository
5
7
  def initialize(repo)
6
8
  @repo = repo
7
9
  end
8
10
 
11
+ # @param sha [String] target commit sha
12
+ #
13
+ # @return [Array<Comment>] parse commit comments into Comment
9
14
  def commit_comments(sha)
10
15
  client.commit_comments(slug, sha).map do |comment|
11
16
  Comment.new(sha, comment.body, comment.path, comment.position)
12
17
  end
13
18
  end
14
19
 
20
+ # @param comment [Comment] posting commit comment
21
+ #
22
+ # @return [Sawyer::Resource] Commit comment
23
+ #
24
+ # @see ::Octokit::Client::CommitComments.create_commit_comment
15
25
  def create_commit_comment(comment)
16
26
  client.create_commit_comment(slug, comment.sha, comment.body,
17
27
  comment.path, nil, comment.position)
18
28
  end
19
29
 
30
+ # @param sha [String] target commit sha
31
+ #
32
+ # @return [::GitDiffParser::Patches<::GitDiffParser::Patch>] patches
20
33
  def commit_patches(sha)
21
34
  patches = ::GitDiffParser::Patches[]
22
35
  client.commit(slug, sha).files.each do |file|
@@ -25,22 +38,31 @@ module Saddler
25
38
  patches
26
39
  end
27
40
 
41
+ # @return [Array<Comment>] parse issue comments into Comment
28
42
  def issue_comments
29
43
  client.issue_comments(slug, pull_id).map do |comment|
30
- Comment.new(sha = nil, comment.body, comment.path, comment.position)
44
+ sha = nil
45
+ Comment.new(sha, comment.body, comment.path, comment.position)
31
46
  end
32
47
  end
33
48
 
49
+ # @param comment [Comment] posting issue comment
50
+ #
51
+ # @return [Sawyer::Resource] Comment
52
+ #
53
+ # @see ::Octokit::Client::Issues.add_comment
34
54
  def create_issue_comment(comment)
35
55
  client.add_comment(slug, pull_id, comment.body)
36
56
  end
37
57
 
58
+ # @return [Array<Comment>] parse pull request comments into Comment
38
59
  def pull_request_review_comments
39
60
  client.pull_request_comments(slug, pull_id).map do |comment|
40
61
  Comment.new(comment.commit_id, comment.body, comment.path, comment.position)
41
62
  end
42
63
  end
43
64
 
65
+ # @return [::GitDiffParser::Patches<::GitDiffParser::Patch>] patches
44
66
  def pull_request_patches
45
67
  patches = ::GitDiffParser::Patches[]
46
68
  client.pull_request_files(slug, pull_id).each do |file|
@@ -49,11 +71,17 @@ module Saddler
49
71
  patches
50
72
  end
51
73
 
74
+ # @param comment [Comment] posting pull request comment
75
+ #
76
+ # @return [Sawyer::Resource] Hash representing the new comment
77
+ #
78
+ # @see ::Octokit::Client::PullRequests.create_pull_request_comment
52
79
  def create_pull_request_review_comment(comment)
53
80
  client.create_pull_request_comment(slug, pull_id, comment.body,
54
81
  comment.sha, comment.path, comment.position)
55
82
  end
56
83
 
84
+ # @return [Integer, nil] pull request id
57
85
  def pull_id
58
86
  @pull_id ||= begin
59
87
  pull_id = env_pull_id
@@ -66,22 +94,29 @@ module Saddler
66
94
  end
67
95
  end
68
96
 
97
+ # @return [Array<Sawyer::Resource>] Array of pulls
98
+ #
99
+ # @see ::Octokit::Client::PullRequests.pull_requests
69
100
  def pull_requests
70
101
  @pull_requests ||= client.pull_requests(slug)
71
102
  end
72
103
 
104
+ # @return [String, nil] repository's slug
73
105
  def slug
74
106
  @slug ||= @repo.slug
75
107
  end
76
108
 
109
+ # @return [Octokit::Client]
77
110
  def client
78
111
  @client ||= Octokit::Client.new(access_token: access_token)
79
112
  end
80
113
 
114
+ # @return [String, nil] github access token
81
115
  def access_token
82
116
  ENV['GITHUB_ACCESS_TOKEN']
83
117
  end
84
118
 
119
+ # @return [Integer, nil] pull request id from environment variables
85
120
  def env_pull_id
86
121
  if ENV['PULL_REQUEST_ID']
87
122
  ENV['PULL_REQUEST_ID'].to_i
@@ -5,7 +5,13 @@ module Saddler
5
5
  include ::Saddler::Reporter::Support
6
6
  include Helper
7
7
 
8
- # https://developer.github.com/v3/repos/comments/#create-a-commit-comment
8
+ # @param messages [String] checkstyle string
9
+ # @param options [Hash]
10
+ # @option options [String] sha target commit sha
11
+ #
12
+ # @return [void]
13
+ #
14
+ # @see https://developer.github.com/v3/repos/comments/#create-a-commit-comment
9
15
  def report(messages, options)
10
16
  repo_path = '.'
11
17
  repo = ::Saddler::Reporter::Support::Git::Repository.new(repo_path)
@@ -20,7 +26,10 @@ module Saddler
20
26
  # build comment
21
27
  body = concat_body(data)
22
28
  return if body.empty?
23
- comment = Comment.new(sha, body, path = nil, position = nil)
29
+
30
+ path = nil
31
+ position = nil
32
+ comment = Comment.new(sha, body, path, position)
24
33
 
25
34
  # compare commit_comments.include?(comment)
26
35
  return if commit_comments.include?(comment)
@@ -7,7 +7,13 @@ module Saddler
7
7
  include ::Saddler::Reporter::Support
8
8
  include Helper
9
9
 
10
- # https://developer.github.com/v3/repos/comments/#create-a-commit-comment
10
+ # @param messages [String] checkstyle string
11
+ # @param options [Hash]
12
+ # @option options [String] sha target commit sha
13
+ #
14
+ # @return [void]
15
+ #
16
+ # @see https://developer.github.com/v3/repos/comments/#create-a-commit-comment
11
17
  def report(messages, options)
12
18
  repo_path = '.'
13
19
  repo = ::Saddler::Reporter::Support::Git::Repository.new(repo_path)
@@ -1,7 +1,13 @@
1
1
  module Saddler
2
2
  module Reporter
3
3
  module Github
4
+ # Helper for saddler-reporter-github
4
5
  module Helper
6
+ # Concatenate parsed errors
7
+ #
8
+ # @param data [Object] parsed checkstyle data
9
+ #
10
+ # @return [String] concatenated errors. separated with new line.
5
11
  def concat_body(data)
6
12
  buffer = []
7
13
  files = data['checkstyle']['file'] ||= []
@@ -18,6 +24,12 @@ module Saddler
18
24
  buffer.join("\n")
19
25
  end
20
26
 
27
+ # Build comment objects by parsed errors and patches
28
+ #
29
+ # @param data [Object] parsed checkstyle data
30
+ # @param patches [Patches<Patch>] `git diff`'s patch section
31
+ #
32
+ # @return [Array<Comment>] comment objects
21
33
  def build_comments_with_patches(data, patches)
22
34
  comments = []
23
35
  files = data['checkstyle']['file'] ||= []
@@ -5,7 +5,12 @@ module Saddler
5
5
  include ::Saddler::Reporter::Support
6
6
  include Helper
7
7
 
8
- # https://developer.github.com/v3/issues/comments/#create-a-comment
8
+ # @param messages [String] checkstyle string
9
+ # @param _options [Hash]
10
+ #
11
+ # @return [void]
12
+ #
13
+ # @see https://developer.github.com/v3/issues/comments/#create-a-comment
9
14
  def report(messages, _options)
10
15
  repo_path = '.'
11
16
  repo = ::Saddler::Reporter::Support::Git::Repository.new(repo_path)
@@ -19,7 +24,11 @@ module Saddler
19
24
  # build comment
20
25
  body = concat_body(data)
21
26
  return if body.empty?
22
- comment = Comment.new(sha1 = nil, body, path = nil, position = nil)
27
+
28
+ sha = nil
29
+ path = nil
30
+ position = nil
31
+ comment = Comment.new(sha, body, path, position)
23
32
 
24
33
  # compare pull_request_comments.include?(comment)
25
34
  return if pull_request_comments.include?(comment)
@@ -5,7 +5,12 @@ module Saddler
5
5
  include ::Saddler::Reporter::Support
6
6
  include Helper
7
7
 
8
- # https://developer.github.com/v3/pulls/comments/#create-a-comment
8
+ # @param messages [String] checkstyle string
9
+ # @param _options [Hash]
10
+ #
11
+ # @return [void]
12
+ #
13
+ # @see https://developer.github.com/v3/pulls/comments/#create-a-comment
9
14
  def report(messages, _options)
10
15
  repo_path = '.'
11
16
  repo = ::Saddler::Reporter::Support::Git::Repository.new(repo_path)
@@ -1,7 +1,7 @@
1
1
  module Saddler
2
2
  module Reporter
3
3
  module Github
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saddler-reporter-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - sanemat
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-21 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -115,6 +115,7 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".conventional-changelog.context.js"
118
119
  - ".gitignore"
119
120
  - ".rubocop.yml"
120
121
  - CHANGELOG.md
@@ -124,7 +125,6 @@ files:
124
125
  - README.md
125
126
  - Rakefile
126
127
  - bin/console
127
- - bin/conventional-changelog
128
128
  - bin/setup
129
129
  - lib/saddler/reporter/github.rb
130
130
  - lib/saddler/reporter/github/client.rb
@@ -161,3 +161,4 @@ signing_key:
161
161
  specification_version: 4
162
162
  summary: Saddler reporter for GitHub.
163
163
  test_files: []
164
+ has_rdoc:
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- var fs = require('fs');
4
- var execSync = require('child_process').execSync;
5
- var conventionalChangelog = require('conventional-changelog');
6
- var tempfile = require('tempfile');
7
- var addStream = require('add-stream');
8
-
9
- var version = "" + execSync('ruby -e \'require "./lib/saddler/reporter/github/version"; print Saddler::Reporter::Github::VERSION\'');
10
-
11
- var options = { preset: 'angular' };
12
- var templateContext = {
13
- version: version,
14
- host: 'https://github.com',
15
- owner: 'packsaddle',
16
- repository: 'ruby-saddler-reporter-github'
17
- };
18
- var infile = 'CHANGELOG.md';
19
- var outfile = 'CHANGELOG.md';
20
- var changelogStream = conventionalChangelog(options, templateContext)
21
- .on('error', function(err) {
22
- console.error(err.toString());
23
- process.exit(1);
24
- });
25
-
26
- var tmp = tempfile();
27
- var readStream = fs.createReadStream(infile);
28
-
29
- changelogStream
30
- .pipe(addStream(readStream))
31
- .pipe(fs.createWriteStream(tmp))
32
- .on('finish', function() {
33
- fs.createReadStream(tmp)
34
- .pipe(fs.createWriteStream(outfile));
35
- });