Class: MyTimeline::Github::PullRequestEventBuilder

Inherits:
GithubBuilder
  • Object
show all
Defined in:
app/scrapers/my_timeline/github/pull_request_event_builder.rb

Instance Attribute Summary

Attributes inherited from GithubBuilder

#github_event, #user

Instance Method Summary collapse

Methods inherited from GithubBuilder

#initialize

Constructor Details

This class inherits a constructor from MyTimeline::Github::GithubBuilder

Instance Method Details

#build_eventObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/scrapers/my_timeline/github/pull_request_event_builder.rb', line 5

def build_event
  return false if already_exists_in_db?

  event = MyTimeline::Event.create(
    happened_on:   github_event.created_at,
    original_id:   github_event.id,
    external_link: github_event.payload.pull_request.rels[:html].href,
    icon_name:     "github.png",
    importance:    5,
    public:        1,
    description:   "#{github_event.payload.action.capitalize} Pull Request #{link_pr} on #{link_user_repo(github_event.repo.name)}: #{github_event.payload.pull_request.title}"
  )

  pull_request_event = MyTimeline::Github::PullRequestEvent.new(
    happened_on:   github_event.created_at,
    title:         github_event.payload.pull_request.title,
    body:          github_event.payload.pull_request.body,
    url:           github_event.payload.pull_request.rels[:html].href,
    commits:       github_event.payload.pull_request.commits,
    additions:     github_event.payload.pull_request.additions,
    deletions:     github_event.payload.pull_request.deletions,
    changed_files: github_event.payload.pull_request.changed_files,
    repo:          github_event.repo.name
  )

  event.linkable = pull_request_event
  event.user = user if MyTimeline.user_class
  event.save

  pull_request_event.event = event
  pull_request_event.save
end