ghn 2.0.0.pre2 → 2.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 784b9d296d796af6ee80284b9114814515eacc8d
4
- data.tar.gz: c87a10906695670e0bbd3e27f34cecb41b6aad2f
3
+ metadata.gz: d94d9709ddd3bf7603f456f4ed78a2464e7b7f62
4
+ data.tar.gz: f2af501c2ee2cc73e00738209503662e8c6a7354
5
5
  SHA512:
6
- metadata.gz: 997f8ceca8a92eae4e41f7ec5ff53a747f0bdb736f3c2587eb28340dc8b9217f706f93b5203e6e753622c7a97b7872ab28b6b9c9d5f16504cd3c54b3a75290ca
7
- data.tar.gz: ce41feed8fadfa532a9cde7b573fdc9584a3bbf154fa7b33868204a160ddfd17f9410b3a023408f5b73d00782fc3d30d914d6c5825aef8c931a04896f548b450
6
+ metadata.gz: 12b3349afb5ee1899a904e309cf53ba8ebb6f34718fe14cfc035245d73cceaaa52e27a27bc6ac5970dcc9cd2a6970d02ab254443d08de823acc73df3dcfe4741
7
+ data.tar.gz: 0562454df324f03bd73ae7845e807a6e5da577f4dc04898fa2edd93b5482154fc0c9505df32af606875b55d75dd4f01efa18c6b28d40d7b751ebb1acb87a8163
data/lib/ghn/collector.rb CHANGED
@@ -13,7 +13,7 @@ class Ghn
13
13
  end
14
14
  @count = notifications.count
15
15
  notifications.map { |notification|
16
- Notification.new(notification).to_url
16
+ Notification.new(notification).type_class.new(notification).url
17
17
  }.compact
18
18
  end
19
19
 
@@ -6,10 +6,15 @@ class Ghn
6
6
  @notification = notification
7
7
  end
8
8
 
9
- def to_url
10
- if type.nil?
11
- warn "unknown subject type #{notification[:subject][:type]}"
12
- elsif comment?
9
+ def type_class
10
+ klass = "#{subject_type}Notification"
11
+ Ghn.const_get(klass)
12
+ rescue NameError
13
+ Ghn::UnknownNotification
14
+ end
15
+
16
+ def url
17
+ if comment?
13
18
  "https://github.com/#{repo_full_name}/#{type}/#{thread_number}#issuecomment-#{comment_number}"
14
19
  else
15
20
  "https://github.com/#{repo_full_name}/#{type}/#{thread_number}"
@@ -26,17 +31,8 @@ class Ghn
26
31
  notification[:repository][:full_name]
27
32
  end
28
33
 
29
- def type
30
- case notification[:subject][:type]
31
- when 'Issue'
32
- 'issues'
33
- when 'PullRequest'
34
- 'pull'
35
- when 'Commit'
36
- 'commit'
37
- else
38
- nil
39
- end
34
+ def subject_type
35
+ notification[:subject][:type]
40
36
  end
41
37
 
42
38
  def thread_number
@@ -49,4 +45,38 @@ class Ghn
49
45
  end
50
46
  end
51
47
  end
48
+
49
+ class IssueNotification < Notification
50
+ def type
51
+ 'issues'
52
+ end
53
+ end
54
+
55
+ class PullRequestNotification < Notification
56
+ def type
57
+ 'pull'
58
+ end
59
+ end
60
+
61
+ class CommitNotification < Notification
62
+ def type
63
+ 'commit'
64
+ end
65
+ end
66
+
67
+ class ReleaseNotification < Notification
68
+ def url
69
+ "https://github.com/#{repo_full_name}/releases/tag/#{tag}"
70
+ end
71
+
72
+ def tag
73
+ notification[:subject][:title].split(" ")[-1]
74
+ end
75
+ end
76
+
77
+ class UnknownNotification < Notification
78
+ def url
79
+ warn "unknown subject type #{subject_type}"
80
+ end
81
+ end
52
82
  end
data/lib/ghn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Ghn
2
- VERSION = "2.0.0.pre2"
2
+ VERSION = "2.0.0.pre3"
3
3
  end
@@ -1,79 +1,79 @@
1
1
  {
2
- "subscription_url": "https://api.github.com/notifications/threads/40414158/subscription",
3
- "id": "40414158",
4
- "unread": true,
5
- "reason": "subscribed",
6
- "updated_at": "2014-08-22T15:16:26Z",
7
- "last_read_at": null,
8
- "subject": {
9
- "type": "Release",
10
- "latest_comment_url": "???",
11
- "url": "???",
12
- "title": "Title"
13
- },
14
- "repository": {
15
- "releases_url": "https://api.github.com/repos/username/reponame/releases{/id}",
16
- "labels_url": "https://api.github.com/repos/username/reponame/labels{/name}",
17
- "notifications_url": "https://api.github.com/repos/username/reponame/notifications{?since,all,participating}",
18
- "milestones_url": "https://api.github.com/repos/username/reponame/milestones{/number}",
19
- "pulls_url": "https://api.github.com/repos/username/reponame/pulls{/number}",
20
- "issues_url": "https://api.github.com/repos/username/reponame/issues{/number}",
21
- "downloads_url": "https://api.github.com/repos/username/reponame/downloads",
22
- "archive_url": "https://api.github.com/repos/username/reponame/{archive_format}{/ref}",
23
- "merges_url": "https://api.github.com/repos/username/reponame/merges",
24
- "compare_url": "https://api.github.com/repos/username/reponame/compare/{base}...{head}",
25
- "contents_url": "https://api.github.com/repos/username/reponame/contents/{+path}",
26
- "issue_comment_url": "https://api.github.com/repos/username/reponame/issues/comments/{number}",
27
- "events_url": "https://api.github.com/repos/username/reponame/events",
28
- "issue_events_url": "https://api.github.com/repos/username/reponame/issues/events{/number}",
29
- "hooks_url": "https://api.github.com/repos/username/reponame/hooks",
30
- "teams_url": "https://api.github.com/repos/username/reponame/teams",
31
- "collaborators_url": "https://api.github.com/repos/username/reponame/collaborators{/collaborator}",
32
- "keys_url": "https://api.github.com/repos/username/reponame/keys{/key_id}",
33
- "forks_url": "https://api.github.com/repos/username/reponame/forks",
34
- "url": "https://api.github.com/repos/username/reponame",
35
- "id": 18326008,
36
- "name": "reponame",
37
- "full_name": "username/reponame",
38
- "owner": {
39
- "site_admin": false,
40
- "following_url": "https://api.github.com/users/username/following{/other_user}",
41
- "followers_url": "https://api.github.com/users/username/followers",
42
- "html_url": "https://github.com/username",
43
- "url": "https://api.github.com/users/username",
44
- "gravatar_id": "68a1d93ef9b8b36a2658b2b6c77b1e2f",
45
- "avatar_url": "https://avatars.githubusercontent.com/u/535481?v=2",
46
- "id": 535481,
47
- "login": "username",
48
- "gists_url": "https://api.github.com/users/username/gists{/gist_id}",
49
- "starred_url": "https://api.github.com/users/username/starred{/owner}{/repo}",
50
- "subscriptions_url": "https://api.github.com/users/username/subscriptions",
51
- "organizations_url": "https://api.github.com/users/username/orgs",
52
- "repos_url": "https://api.github.com/users/username/repos",
53
- "events_url": "https://api.github.com/users/username/events{/privacy}",
54
- "received_events_url": "https://api.github.com/users/username/received_events",
55
- "type": "Organization"
2
+ "id": "40477317",
3
+ "last_read_at": null,
4
+ "reason": "subscribed",
5
+ "repository": {
6
+ "archive_url": "https://api.github.com/repos/yandod/candycane/{archive_format}{/ref}",
7
+ "assignees_url": "https://api.github.com/repos/yandod/candycane/assignees{/user}",
8
+ "blobs_url": "https://api.github.com/repos/yandod/candycane/git/blobs{/sha}",
9
+ "branches_url": "https://api.github.com/repos/yandod/candycane/branches{/branch}",
10
+ "collaborators_url": "https://api.github.com/repos/yandod/candycane/collaborators{/collaborator}",
11
+ "comments_url": "https://api.github.com/repos/yandod/candycane/comments{/number}",
12
+ "commits_url": "https://api.github.com/repos/yandod/candycane/commits{/sha}",
13
+ "compare_url": "https://api.github.com/repos/yandod/candycane/compare/{base}...{head}",
14
+ "contents_url": "https://api.github.com/repos/yandod/candycane/contents/{+path}",
15
+ "contributors_url": "https://api.github.com/repos/yandod/candycane/contributors",
16
+ "description": "a port of Redmine to CakePHP from Ruby on Rails",
17
+ "downloads_url": "https://api.github.com/repos/yandod/candycane/downloads",
18
+ "events_url": "https://api.github.com/repos/yandod/candycane/events",
19
+ "fork": false,
20
+ "forks_url": "https://api.github.com/repos/yandod/candycane/forks",
21
+ "full_name": "yandod/candycane",
22
+ "git_commits_url": "https://api.github.com/repos/yandod/candycane/git/commits{/sha}",
23
+ "git_refs_url": "https://api.github.com/repos/yandod/candycane/git/refs{/sha}",
24
+ "git_tags_url": "https://api.github.com/repos/yandod/candycane/git/tags{/sha}",
25
+ "hooks_url": "https://api.github.com/repos/yandod/candycane/hooks",
26
+ "html_url": "https://github.com/yandod/candycane",
27
+ "id": 419430,
28
+ "issue_comment_url": "https://api.github.com/repos/yandod/candycane/issues/comments/{number}",
29
+ "issue_events_url": "https://api.github.com/repos/yandod/candycane/issues/events{/number}",
30
+ "issues_url": "https://api.github.com/repos/yandod/candycane/issues{/number}",
31
+ "keys_url": "https://api.github.com/repos/yandod/candycane/keys{/key_id}",
32
+ "labels_url": "https://api.github.com/repos/yandod/candycane/labels{/name}",
33
+ "languages_url": "https://api.github.com/repos/yandod/candycane/languages",
34
+ "merges_url": "https://api.github.com/repos/yandod/candycane/merges",
35
+ "milestones_url": "https://api.github.com/repos/yandod/candycane/milestones{/number}",
36
+ "name": "candycane",
37
+ "notifications_url": "https://api.github.com/repos/yandod/candycane/notifications{?since,all,participating}",
38
+ "owner": {
39
+ "avatar_url": "https://avatars.githubusercontent.com/u/103903?v=2",
40
+ "events_url": "https://api.github.com/users/yandod/events{/privacy}",
41
+ "followers_url": "https://api.github.com/users/yandod/followers",
42
+ "following_url": "https://api.github.com/users/yandod/following{/other_user}",
43
+ "gists_url": "https://api.github.com/users/yandod/gists{/gist_id}",
44
+ "gravatar_id": "9b69fbdeb0713def44a8731091ce5885",
45
+ "html_url": "https://github.com/yandod",
46
+ "id": 103903,
47
+ "login": "yandod",
48
+ "organizations_url": "https://api.github.com/users/yandod/orgs",
49
+ "received_events_url": "https://api.github.com/users/yandod/received_events",
50
+ "repos_url": "https://api.github.com/users/yandod/repos",
51
+ "site_admin": false,
52
+ "starred_url": "https://api.github.com/users/yandod/starred{/owner}{/repo}",
53
+ "subscriptions_url": "https://api.github.com/users/yandod/subscriptions",
54
+ "type": "User",
55
+ "url": "https://api.github.com/users/yandod"
56
+ },
57
+ "private": false,
58
+ "pulls_url": "https://api.github.com/repos/yandod/candycane/pulls{/number}",
59
+ "releases_url": "https://api.github.com/repos/yandod/candycane/releases{/id}",
60
+ "stargazers_url": "https://api.github.com/repos/yandod/candycane/stargazers",
61
+ "statuses_url": "https://api.github.com/repos/yandod/candycane/statuses/{sha}",
62
+ "subscribers_url": "https://api.github.com/repos/yandod/candycane/subscribers",
63
+ "subscription_url": "https://api.github.com/repos/yandod/candycane/subscription",
64
+ "tags_url": "https://api.github.com/repos/yandod/candycane/tags",
65
+ "teams_url": "https://api.github.com/repos/yandod/candycane/teams",
66
+ "trees_url": "https://api.github.com/repos/yandod/candycane/git/trees{/sha}",
67
+ "url": "https://api.github.com/repos/yandod/candycane"
56
68
  },
57
- "private": true,
58
- "html_url": "https://github.com/username/reponame",
59
- "description": "",
60
- "fork": false,
61
- "assignees_url": "https://api.github.com/repos/username/reponame/assignees{/user}",
62
- "branches_url": "https://api.github.com/repos/username/reponame/branches{/branch}",
63
- "tags_url": "https://api.github.com/repos/username/reponame/tags",
64
- "blobs_url": "https://api.github.com/repos/username/reponame/git/blobs{/sha}",
65
- "git_tags_url": "https://api.github.com/repos/username/reponame/git/tags{/sha}",
66
- "git_refs_url": "https://api.github.com/repos/username/reponame/git/refs{/sha}",
67
- "trees_url": "https://api.github.com/repos/username/reponame/git/trees{/sha}",
68
- "statuses_url": "https://api.github.com/repos/username/reponame/statuses/{sha}",
69
- "languages_url": "https://api.github.com/repos/username/reponame/languages",
70
- "stargazers_url": "https://api.github.com/repos/username/reponame/stargazers",
71
- "contributors_url": "https://api.github.com/repos/username/reponame/contributors",
72
- "subscribers_url": "https://api.github.com/repos/username/reponame/subscribers",
73
- "subscription_url": "https://api.github.com/repos/username/reponame/subscription",
74
- "commits_url": "https://api.github.com/repos/username/reponame/commits{/sha}",
75
- "git_commits_url": "https://api.github.com/repos/username/reponame/git/commits{/sha}",
76
- "comments_url": "https://api.github.com/repos/username/reponame/comments{/number}"
77
- },
78
- "url": "https://api.github.com/notifications/threads/40414158"
69
+ "subject": {
70
+ "latest_comment_url": "https://api.github.com/repos/yandod/candycane/releases/510313",
71
+ "title": "CandyCane v0.9.4",
72
+ "type": "Release",
73
+ "url": "https://api.github.com/repos/yandod/candycane/releases/510313"
74
+ },
75
+ "subscription_url": "https://api.github.com/notifications/threads/40477317/subscription",
76
+ "unread": true,
77
+ "updated_at": "2014-08-23T12:45:11Z",
78
+ "url": "https://api.github.com/notifications/threads/40477317"
79
79
  }
@@ -1,59 +1,110 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ghn::Notification do
4
- subject { Ghn::Notification.new(notification) }
4
+ describe '#type_class' do
5
+ subject { Ghn::Notification.new(notification).type_class }
5
6
 
6
- describe '#to_url' do
7
7
  context 'issue' do
8
- subject { Ghn::Notification.new fixture('issue.json') }
8
+ let(:notification) { fixture('issue.json') }
9
9
 
10
- it { expect(subject.to_url).to eq 'https://github.com/username/reponame/issues/305' }
10
+ it { is_expected.to eq Ghn::IssueNotification }
11
11
  end
12
12
 
13
- context 'issue comment' do
14
- subject { Ghn::Notification.new fixture('issue_with_comment.json') }
13
+ context 'pull request' do
14
+ let(:notification) { fixture('pull_request.json') }
15
15
 
16
- it { expect(subject.to_url).to eq 'https://github.com/username/reponame/issues/305#issuecomment-53070200' }
16
+ it { is_expected.to eq Ghn::PullRequestNotification }
17
17
  end
18
18
 
19
- context 'pull request' do
20
- subject { Ghn::Notification.new fixture('pull_request.json') }
19
+ context 'commit' do
20
+ let(:notification) { fixture('commit.json') }
21
21
 
22
- it { expect(subject.to_url).to eq 'https://github.com/username/reponame/pull/22' }
22
+ it { is_expected.to eq Ghn::CommitNotification }
23
23
  end
24
24
 
25
- context 'pull request with comment' do
26
- subject { Ghn::Notification.new fixture('pull_request_with_comment.json') }
25
+ context 'release' do
26
+ let(:notification) { fixture('release.json') }
27
27
 
28
- it { expect(subject.to_url).to eq 'https://github.com/username/reponame/pull/22#issuecomment-16607215' }
28
+ it { is_expected.to eq Ghn::ReleaseNotification }
29
29
  end
30
30
 
31
- context 'commit' do
32
- subject { Ghn::Notification.new fixture('commit.json') }
31
+ context 'unknown' do
32
+ let(:notification) { fixture('unknown.json') }
33
33
 
34
- it { expect(subject.to_url).to eq 'https://github.com/username/reponame/commit/6a4a135335acef4dfe15912d231429c07d4ad143' }
34
+ it { is_expected.to eq Ghn::UnknownNotification }
35
35
  end
36
+ end
36
37
 
37
- context 'commit with comment' do
38
- subject { Ghn::Notification.new fixture('commit_with_comment.json') }
38
+ describe Ghn::IssueNotification do
39
+ describe '#url' do
40
+ it do
41
+ expect(
42
+ Ghn::IssueNotification.new(fixture('issue.json')).url
43
+ ).to eq 'https://github.com/username/reponame/issues/305'
44
+ end
39
45
 
40
- it { expect(subject.to_url).to eq 'https://github.com/username/reponame/commit/6a4a135335acef4dfe15912d231429c07d4ad143#issuecomment-7491006' }
46
+ context 'with comment' do
47
+ it do
48
+ expect(
49
+ Ghn::IssueNotification.new(fixture('issue_with_comment.json')).url
50
+ ).to eq 'https://github.com/username/reponame/issues/305#issuecomment-53070200'
51
+ end
52
+ end
41
53
  end
54
+ end
42
55
 
43
- # TODO: Release type JSON is unknown
44
- context 'release' do
45
- subject { Ghn::Notification.new fixture('release.json') }
56
+ describe Ghn::PullRequestNotification do
57
+ describe '#url' do
58
+ it do
59
+ expect(
60
+ Ghn::PullRequestNotification.new(fixture('pull_request.json')).url
61
+ ).to eq 'https://github.com/username/reponame/pull/22'
62
+ end
46
63
 
47
- it "does not raise error" do
48
- expect(subject.to_url).to be nil
64
+ context 'with comment' do
65
+ it do
66
+ expect(
67
+ Ghn::PullRequestNotification.new(fixture('pull_request_with_comment.json')).url
68
+ ).to eq 'https://github.com/username/reponame/pull/22#issuecomment-16607215'
69
+ end
49
70
  end
50
71
  end
72
+ end
51
73
 
52
- context 'unknown' do
53
- subject { Ghn::Notification.new fixture('unknown.json') }
74
+ describe Ghn::CommitNotification do
75
+ describe '#url' do
76
+ it do
77
+ expect(
78
+ Ghn::CommitNotification.new(fixture('commit.json')).url
79
+ ).to eq 'https://github.com/username/reponame/commit/6a4a135335acef4dfe15912d231429c07d4ad143'
80
+ end
81
+
82
+ context 'with comment' do
83
+ it do
84
+ expect(
85
+ Ghn::CommitNotification.new(fixture('commit_with_comment.json')).url
86
+ ).to eq 'https://github.com/username/reponame/commit/6a4a135335acef4dfe15912d231429c07d4ad143#issuecomment-7491006'
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ describe Ghn::ReleaseNotification do
93
+ describe '#url' do
94
+ it do
95
+ expect(
96
+ Ghn::ReleaseNotification.new(fixture('release.json')).url
97
+ ).to eq 'https://github.com/yandod/candycane/releases/tag/v0.9.4'
98
+ end
99
+ end
100
+ end
54
101
 
55
- it "does not raise error" do
56
- expect(subject.to_url).to be nil
102
+ describe Ghn::UnknownNotification do
103
+ describe '#url' do
104
+ it do
105
+ expect(
106
+ Ghn::UnknownNotification.new(fixture('release.json')).url
107
+ ).to be nil
57
108
  end
58
109
  end
59
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghn
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre2
4
+ version: 2.0.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kensuke Nagae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-23 00:00:00.000000000 Z
11
+ date: 2014-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor