my_timeline-github 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a69047376412697ed0c61a421156b0b651f7aa2
4
+ data.tar.gz: 3f7dc6837b6568e0cf98306aada5cd985d880e5b
5
+ SHA512:
6
+ metadata.gz: 22d65b0d13409d271dd6afd27b52ccbaef97d544368255e38c1e10aca44e93aa2649c3121ec78606472f407e620cdf12e0dfe816163ab28b6fe0c4fdd0650f12
7
+ data.tar.gz: c90d5d3ad51ed4e435e7e1044e49702820956ca4a39a5241075b4adbf1e91bd6758cb5733ff9a65d93941163845cf247a418b60bd13c56ebf3dd0f29e00e58d8
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ .ruby-version
3
+ .ruby-gemset
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Justin Aiken
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,78 @@
1
+ [![Code Climate](https://codeclimate.com/github/JustinAiken/my_timeline-github.png)](https://codeclimate.com/github/JustinAiken/my_timeline-github)
2
+
3
+ # My Timeline - Github Plugin
4
+ #### Github Integration with My Timeline
5
+
6
+ ### Requirements:
7
+
8
+ - [My Timeline](https://github.com/JustinAiken/my_timeline)
9
+ - [Octokit](https://github.com/octokit/octokit.rb) gem
10
+
11
+ ### Usage:
12
+
13
+ 1. Add this gem to your Gemfile:
14
+ `gem 'my_timeline-github'` and `bundle install`
15
+ 2. [Register your application](https://github.com/settings/applications/new) with Github to get `client_id` and `client_secret` keys.
16
+ 3. Edit `config/initializers/my_timeline.rb` to include your Github OAUTH keys:
17
+
18
+ ```ruby
19
+ MyTimeline.setup do |config|
20
+ ...
21
+ end
22
+
23
+ ...
24
+
25
+ MyTimeline::Github.setup do |config|
26
+ config.client_id = "YOURKEY"
27
+ config.client_secret = "YOURKEY"
28
+ end
29
+
30
+ ```
31
+
32
+ ### Current State
33
+
34
+ Github provides a wide variety of user activities. This plugin will eventually include them all, but they'll be coming one at a time...
35
+
36
+ - [ ] [CommitCommentEvent](http://developer.github.com/v3/activity/events/types/#commitcommentevent)
37
+ - [ ] [CreateEvent](http://developer.github.com/v3/activity/events/types/#createevent)
38
+ - [ ] [DeleteEvent](http://developer.github.com/v3/activity/events/types/#deleteevent)
39
+ - [ ] [DownloadEvent](http://developer.github.com/v3/activity/events/types/#downloadevent)
40
+ - [ ] [FollowEvent](http://developer.github.com/v3/activity/events/types/#followevent)
41
+ - [x] [ForkEvent](http://developer.github.com/v3/activity/events/types/#forkevent)
42
+ - [ ] [ForkApplyEvent](http://developer.github.com/v3/activity/events/types/#forkapplyevent)
43
+ - [ ] [GistEvent](http://developer.github.com/v3/activity/events/types/#gistevent)
44
+ - [ ] [GollumEvent](http://developer.github.com/v3/activity/events/types/#gollumevent)
45
+ - [ ] [IssueCommentEvent](http://developer.github.com/v3/activity/events/types/#issuecommentevent)
46
+ - [ ] [IssuesEvent](http://developer.github.com/v3/activity/events/types/#issuesevent)
47
+ - [ ] [MemberEvent](http://developer.github.com/v3/activity/events/types/#memberevent)
48
+ - [ ] [PublicEvent](http://developer.github.com/v3/activity/events/types/#publicevent)
49
+ - [ ] [PullRequestEvent](http://developer.github.com/v3/activity/events/types/#pullrequestevent)
50
+ - [ ] [PullRequestReviewCommentEvent](http://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent)
51
+ - [ ] [PushEvent](http://developer.github.com/v3/activity/events/types/#pushevent)
52
+ - [ ] [ReleaseEvent](http://developer.github.com/v3/activity/events/types/#releaseevent)
53
+ - [ ] [StatusEvent](http://developer.github.com/v3/activity/events/types/#statusevent)
54
+ - [ ] [TeamAddEvent](http://developer.github.com/v3/activity/events/types/#teamaddevent)
55
+ - [ ] [WatchEvent](http://developer.github.com/v3/activity/events/types/#watchevent)
56
+
57
+ ## Credits
58
+
59
+ Original author: [Justin Aiken](https://github.com/JustinAiken)
60
+
61
+ ## Links
62
+
63
+ * [Source](https://github.com/JustinAiken/my_timeline-github)
64
+ * [Bug Tracker](https://github.com/JustinAiken/my_timeline-github/issues)
65
+ * [Rubygem](https://rubygems.org/gems/my_timeline-github)
66
+
67
+ ## Note on Patches/Pull Requests
68
+
69
+ * Fork the project.
70
+ * Make your feature addition or bug fix.
71
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
72
+ * Commit, do not mess with rakefile, version, or history.
73
+ * If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull
74
+ * Send me a pull request. Bonus points for topic branches.
75
+
76
+ ## Copyright
77
+
78
+ Copyright (c) 2013 Justin Aiken Inc. MIT license (see LICENSE for details).
@@ -0,0 +1,14 @@
1
+ module MyTimeline
2
+ class GithubController < ApplicationController
3
+ def new
4
+ @user.settings(:github).user_name = params[:user_name]
5
+ @user.save!
6
+ redirect_to control_panel_path, notice: "Github added!"
7
+ end
8
+
9
+ def scrape
10
+ scrapey = MyTimeline::Github::GithubScraper.new(@user).scrape
11
+ redirect_to :back, notice: "Added #{scrapey} gits."
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module MyTimeline
2
+ module Github
3
+ class ForkEvent < ActiveRecord::Base
4
+ self.table_name = :my_timeline_github_fork_events
5
+ belongs_to :event #,dependant: :destroy
6
+
7
+ attr_protected
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,33 @@
1
+ module MyTimeline
2
+ module Github
3
+ class ForkEventBuilder < GithubBuilder
4
+
5
+ def build_event
6
+ return false if already_exists_in_db?
7
+
8
+ event = MyTimeline::Event.create(
9
+ happened_on: github_event.created_at,
10
+ original_id: github_event.id,
11
+ external_link: "https://www.github.com/#{user.settings(:github).user_name}/#{github_event.repo.name}",
12
+ icon_name: "github.png",
13
+ importance: 5,
14
+ public: 1,
15
+ description: "Forked #{link_user_repo(github_event.repo.name)}"
16
+ )
17
+
18
+ fork_event = MyTimeline::Github::ForkEvent.new(
19
+ happened_on: github_event.created_at,
20
+ original_id: github_event.id,
21
+ repo: github_event.repo.name
22
+ )
23
+
24
+ event.linkable = fork_event
25
+ event.user = user if MyTimeline.user_class
26
+ event.save
27
+
28
+ fork_event.event = event
29
+ fork_event.save
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,28 @@
1
+ module MyTimeline
2
+ module Github
3
+ class GithubBuilder
4
+
5
+ attr_reader :user, :github_event
6
+
7
+ def initialize(user, github_event)
8
+ @user = user
9
+ @github_event = github_event
10
+ end
11
+
12
+ def build_event
13
+ #Children should define this!
14
+ end
15
+
16
+ private
17
+
18
+ def already_exists_in_db?
19
+ event = MyTimeline::Event.find_by_original_id(github_event.id)
20
+ event && event.icon_name =~ /github/
21
+ end
22
+
23
+ def link_user_repo(user_repo)
24
+ "<a href=https://www.github.com/#{user_repo}>#{user_repo}</a>"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,71 @@
1
+ module MyTimeline
2
+ module Github
3
+ class GithubScraper
4
+
5
+ # ALL VALID GITHUB API EVENTS:
6
+ # CommitCommentEvent CreateEvent DeleteEvent DownloadEvent FollowEvent ForkEvent
7
+ # ForkApplyEvent GistEvent GollumEvent IssueCommentEvent IssuesEvent MemberEvent
8
+ # PublicEvent PullRequestEvent PullRequestReviewCommentEvent PushEvent ReleaseEvent
9
+ # StatusEvent TeamAddEvent WatchEvent
10
+
11
+ # IMPLEMENTED EVENTS ONLY:
12
+ VALID_EVENTS = %w{ForkEvent}.freeze
13
+
14
+ attr_accessor :user
15
+
16
+ def initialize(user)
17
+ @user = user
18
+ end
19
+
20
+ def scrape
21
+ @count = 0
22
+
23
+ events.each do |event|
24
+ if should_build? event
25
+ Rails.logger.fatal "buidling #{event.type}"
26
+ @count = @count + 1 if "MyTimeline::Github::#{event.type}Builder".constantize.new(user, event).build_event
27
+ end
28
+ end
29
+
30
+ @count
31
+ end
32
+
33
+ private
34
+
35
+ def events
36
+ [].tap do |big_array|
37
+ while items_on_current_page? do
38
+ big_array << @current_page
39
+ end
40
+ end.flatten
41
+ end
42
+
43
+ def items_on_current_page?
44
+ @current_page = github.user_public_events(username, page: page_number)
45
+ @current_page.length > 0
46
+ end
47
+
48
+ def page_number
49
+ @page_number ||= 0
50
+ @page_number = @page_number + 1
51
+ end
52
+
53
+ def username
54
+ user.settings(:github).user_name
55
+ end
56
+
57
+ def github
58
+ @github ||= Octokit::Client.new(
59
+ client_id: MyTimeline::Github.client_id,
60
+ client_secret: MyTimeline::Github.client_secret,
61
+ auto_traversal: true
62
+ )
63
+ end
64
+
65
+ def should_build?(event)
66
+ VALID_EVENTS.include?(event.type) &&
67
+ user #TODO - @user has this option set??
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,11 @@
1
+ <h3> Github Settings </h3>
2
+ <% if @user.settings(:github).user_name %>
3
+ <%= button_to "Scrape activities from #{@user.settings(:github).user_name}!", github_scrape_path, method: :get, class: "btn btn-primary" %>
4
+ <% else %>
5
+ <%= form_tag new_github_path, method: :post do %>
6
+ <%= label_tag :user_name %>
7
+ <%= text_field_tag :user_name %>
8
+ <br>
9
+ <%= submit_tag "Save username", class: "btn btn-primary" %>
10
+ <% end %>
11
+ <% end %>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ MyTimeline::Engine.routes.draw do
2
+ match 'github/scrape' => 'github#scrape', as: "github_scrape"
3
+ post 'github/new' => 'github#new', as: "new_github"
4
+ resources :github
5
+ end
@@ -0,0 +1,13 @@
1
+ class CreateGithubForkEvents < ActiveRecord::Migration
2
+ def change
3
+ create_table :my_timeline_github_fork_events do |t|
4
+ t.datetime :happened_on
5
+
6
+ t.string :original_id
7
+ t.string :repo
8
+
9
+ t.references :event
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module MyTimeline
2
+ module Github
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace MyTimeline::Github
5
+
6
+ config.autoload_paths << File.expand_path("../../../app/classes/**", __FILE__)
7
+ config.autoload_paths << File.expand_path("../../../app/scrapers/**", __FILE__)
8
+
9
+ config.generators do |g|
10
+ g.test_framework :rspec, fixture: false
11
+ g.fixture_replacement :factory_girl, dir: 'spec/factories'
12
+ g.assets false
13
+ g.helper false
14
+ end
15
+
16
+ config.after_initialize do |app|
17
+ MyTimeline.config_object.key :github, defaults: {user_token: nil}
18
+ MyTimeline.register_plugin :github
19
+ end
20
+
21
+ rake_tasks do
22
+ load File::expand_path "railties/github_tasks.rake", File.dirname(__FILE__)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ namespace "my_timeline-twitter" do
2
+ namespace :install do
3
+ desc "Copy migrations from my_timeline-twitter to application"
4
+ task :migrations do
5
+ timestamp = Time.now.strftime("%Y%m%d%H%M%S")
6
+
7
+ source = File.expand_path "../../../../db/migrate//db/migrate/20131222224040_create_github_fork_events.rb", File.dirname(__FILE__)
8
+ dest = File.expand_path "db/migrate/#{timestamp}_create_github_fork_events.my_timeline.rb"
9
+ puts "cp #{source} #{dest}"
10
+ `cp #{source} #{dest}`
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module MyTimeline
2
+ module Github
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require 'octokit'
2
+
3
+ require "my_timeline"
4
+ require "my_timeline/github/engine"
5
+
6
+ module MyTimeline
7
+ module Github
8
+
9
+ mattr_accessor :client_id, :client_secret
10
+
11
+ def self.setup
12
+ yield self
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "my_timeline/github/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "my_timeline-github"
7
+ s.version = MyTimeline::Github::VERSION
8
+ s.authors = ["Justin Aiken"]
9
+ s.email = ["60tonangel@gmail.com"]
10
+ s.homepage = "https://www.github.com/JustinAiken/my_timeline-github"
11
+ s.summary = "Github plugin for MyTimeline"
12
+ s.description = "Github plugin for MyTimeline"
13
+ s.license = 'MIT'
14
+ s.files = `git ls-files`.split("\n")
15
+
16
+ s.add_runtime_dependency "my_timeline"
17
+ s.add_runtime_dependency "octokit"
18
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: my_timeline-github
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Aiken
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: my_timeline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: octokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Github plugin for MyTimeline
42
+ email:
43
+ - 60tonangel@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.markdown
52
+ - app/assets/images/my_timeline/icons/github.png
53
+ - app/controllers/my_timeline/github_controller.rb
54
+ - app/models/my_timeline/github/fork_event.rb
55
+ - app/scrapers/my_timeline/github/fork_event_builder.rb
56
+ - app/scrapers/my_timeline/github/github_builder.rb
57
+ - app/scrapers/my_timeline/github/github_scraper.rb
58
+ - app/views/my_timeline/github/_control_panel.html.erb
59
+ - config/routes.rb
60
+ - db/migrate/20131222224040_create_github_fork_events.rb
61
+ - lib/my_timeline-github.rb
62
+ - lib/my_timeline/github/engine.rb
63
+ - lib/my_timeline/github/railties/github_tasks.rake
64
+ - lib/my_timeline/github/version.rb
65
+ - my_timeline-github.gemspec
66
+ homepage: https://www.github.com/JustinAiken/my_timeline-github
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.0.6
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Github plugin for MyTimeline
90
+ test_files: []
91
+ has_rdoc: