Class: Senju::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/senju/repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Repository

Returns a new instance of Repository.



31
32
33
34
35
# File 'lib/senju/repository.rb', line 31

def initialize(name, options)
  @name = options["repo"] || name
  @options = options
  @type = options["type"]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/senju/repository.rb', line 15

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/senju/repository.rb', line 15

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'lib/senju/repository.rb', line 15

def type
  @type
end

Class Method Details

.allObject



17
18
19
20
21
# File 'lib/senju/repository.rb', line 17

def self.all
  Senju::Repos.new.data.map do |repository, config|
    new(repository, config)
  end
end

.find(name) ⇒ Object



27
28
29
# File 'lib/senju/repository.rb', line 27

def self.find(name)
  new(name, Senju::Repos.new[name])
end

.firstObject



23
24
25
# File 'lib/senju/repository.rb', line 23

def self.first
  all.first
end

Instance Method Details

#changes(no) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/senju/repository.rb', line 68

def changes(no)
  case type
  when "github" then list = client.pull_request_files(name, no)
  when "gitlab" then list = client.merge_request_changes(name, no).changes
  end

  list.map do |raw|
    Senju::Change.new(raw, type)
  end
end

#clientObject



37
38
39
40
41
42
43
44
# File 'lib/senju/repository.rb', line 37

def client
  credential = Senju::Credential.find(type)
  case type
  when "github" then Senju::Github.new(credential)
  when "gitlab" then Senju::Gitlab.new(credential)
  when "trello" then Senju::Trello.new(credential)
  end
end

#comments(no) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/senju/repository.rb', line 57

def comments(no)
  case type
  when "github" then list = client.issue_comments(name, no)
  when "gitlab" then list = client.issue_notes(name, no)
  end

  list.map do |raw|
    Senju::Comment.new(raw, type)
  end
end

#issue(no) ⇒ Object



46
47
48
# File 'lib/senju/repository.rb', line 46

def issue(no)
  Senju::Issue.new(client.issue(name, no), type)
end

#issuesObject



79
80
81
82
83
# File 'lib/senju/repository.rb', line 79

def issues
  client.issues(name).map do |raw|
    Senju::Issue.new(raw, type)
  end
end

#pull_request(no) ⇒ Object



50
51
52
53
54
55
# File 'lib/senju/repository.rb', line 50

def pull_request(no)
  case type
  when "github" then list = Senju::Issue.new(client.pull_request(name, no), type)
  when "gitlab" then list = Senju::Issue.new(client.merge_request(name, no), type)
  end
end

#pull_requestsObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/senju/repository.rb', line 85

def pull_requests
  case type
  when "github" then list = client.pull_requests(name)
  when "gitlab" then list = client.merge_requests(name)
  end

  list.map do |raw|
    Senju::Issue.new(raw, type)
  end
end